Advertisement
Sim0o0na

Untitled

Jul 20th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MovieRating {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int moviesCount = Integer.parseInt(scanner.nextLine());
  10.  
  11. double highestRating = 0;
  12. String highestRatingMovieName = "";
  13.  
  14. double lowestRating = 11;
  15. String lowestRatingMovieName = "";
  16.  
  17. double sumRatings = 0;
  18. for (int movie = 0; movie < moviesCount; movie++) {
  19. String movieName = scanner.nextLine();
  20. double movieRating = Double.parseDouble(scanner.nextLine());
  21. sumRatings += movieRating;
  22.  
  23. if (movieRating > highestRating) {
  24. highestRating = movieRating;
  25. highestRatingMovieName = movieName;
  26. }
  27.  
  28. if (movieRating < lowestRating) {
  29. lowestRating = movieRating;
  30. lowestRatingMovieName = movieName;
  31. }
  32. }
  33.  
  34. System.out.printf("%s is with highest rating: %.1f%n", highestRatingMovieName, highestRating);
  35. System.out.printf("%s is with lowest rating: %.1f%n", lowestRatingMovieName, lowestRating);
  36. System.out.printf("Average rating: %.1f", sumRatings / moviesCount);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement