SHARE
TWEET

Untitled

Sim0o0na Jul 20th, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top