Dido09

05.MovieRating

Nov 1st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MovieRatings {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int movieCount = Integer.parseInt(scanner.nextLine());
  8. double maxRating = 1;
  9. String maxRatingMovie = "";
  10.  
  11. double minRating = 10;
  12. String minRatingMovie = "";
  13. double totalSumRating = 0;
  14.  
  15. for (int i = 1; i <= movieCount ; i++){
  16. String movieName = scanner.nextLine();
  17. double rating = Double.parseDouble(scanner.nextLine());
  18. totalSumRating += rating;
  19.  
  20. if (rating > maxRating){
  21. maxRating = rating;
  22. maxRatingMovie = movieName;
  23.  
  24. }
  25.  
  26. if (rating < minRating){
  27. minRating = rating;
  28. minRatingMovie = movieName;
  29.  
  30. }
  31.  
  32. }
  33. double averageRating = totalSumRating / movieCount;
  34.  
  35. System.out.printf("%s is with highest rating: %.1f%n", maxRatingMovie, maxRating);
  36. System.out.printf("%s is with lowest rating: %.1f%n",minRatingMovie, minRating);
  37. System.out.printf("Average rating: %.1f", averageRating);
  38.  
  39. }
  40. }
Add Comment
Please, Sign In to add comment