Ejemplo n.º 1
0
  private void findAndRateBeer(User user) {
    System.out.print("beer to find: ");
    String n = scanner.nextLine();
    Beer foundBeer = server.find(Beer.class).where().like("name", n).findUnique();

    if (foundBeer == null) {
      System.out.println(n + " not found");
      return;
    }
    int quantity = 0;
    int ratingsCombined = 0;
    int average = 0;
    List<Rating> ratings = server.find(Rating.class).where().findList();
    for (Rating rating : ratings) {
      if (rating.getBeer().getName().equals(n)) {
        ratingsCombined += rating.getRating();
        quantity++;
      }
    }
    if (quantity > 0) {
      average = ratingsCombined / quantity;
    }

    System.out.println("found: " + foundBeer);
    System.out.println("  number of ratings: " + quantity + " average " + average);
    System.out.print("give rating (leave empty if not): ");
    int ratingValue = scanner.nextInt();

    Rating rating = new Rating(user, foundBeer, ratingValue);
    server.save(rating);
  }
Ejemplo n.º 2
0
 private void listRatings(User logged) {
   List<Rating> ratings = server.find(Rating.class).findList();
   for (Rating rating : ratings) {
     if (rating.getUser().getUsername().equals(logged.getUsername())) {
       System.out.println(
           rating.getBeer().getName()
               + " ("
               + rating.getBeer().getBrewery().getName()
               + ") "
               + rating.getRating()
               + " points");
     }
   }
 }