Advertisement
IvaAnd

CinemaTickets

Mar 20th, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CinemaTickets {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String movieTitle = scanner.nextLine();
  9.         int freeSeats = Integer.parseInt(scanner.nextLine());
  10.         String ticketType = scanner.nextLine();
  11.         int students = 0;
  12.         int sudentsAll = 0;
  13.         int standard = 0;
  14.         int standardAll = 0;
  15.         int kids = 0;
  16.         int kidsAll = 0;
  17.         int sumTicketsPerMovie = 0;
  18.         int sumAllTickets = 0;
  19.         boolean isFinished = false;
  20.  
  21.         while (!movieTitle.equals("Finish")) {
  22.             movieTitle = movieTitle;
  23.             freeSeats = freeSeats;
  24.  
  25.             while (!ticketType.equals("End")) {
  26.  
  27.                 if (ticketType.equals("Finish")) {
  28.                     isFinished = true;
  29.                     break;
  30.                 }
  31.  
  32.                 if (ticketType.equals("student")) {
  33.                     students++;
  34.                     sudentsAll++;
  35.  
  36.                 } else if (ticketType.equals("standard")) {
  37.                     standard++;
  38.                     standardAll++;
  39.                 } else {
  40.                     kids++;
  41.                     kidsAll++;
  42.                 }
  43.                 sumAllTickets++;
  44.                 sumTicketsPerMovie++;
  45.                 ticketType = scanner.nextLine();
  46.             }
  47.  
  48.             double percentUsedSeats = sumTicketsPerMovie * 1.0 / freeSeats * 100;
  49.             System.out.printf("%s - %.2f%% full.%n", movieTitle, percentUsedSeats);
  50.             if (isFinished) {
  51.                 break;
  52.             }
  53.             sumTicketsPerMovie = 0;
  54.             students = 0;
  55.             standard = 0;
  56.             kids = 0;
  57.             movieTitle = scanner.nextLine();
  58.             freeSeats = Integer.parseInt(scanner.nextLine());
  59.             ticketType = scanner.nextLine();
  60.  
  61.         }
  62.  
  63.         System.out.printf("Total tickets: %d%n", sumAllTickets);
  64.  
  65.         double percentStudents = sudentsAll * 1.0 / sumAllTickets * 100;
  66.         System.out.printf("%.2f%% student tickets.%n", percentStudents);
  67.  
  68.         double percentStandard = standardAll * 1.0 / sumAllTickets * 100;
  69.         System.out.printf("%.2f%% standard tickets.%n", percentStandard);
  70.  
  71.         double percentKids = kidsAll * 1.0 / sumAllTickets * 100;
  72.         System.out.printf("%.2f%% kids tickets.", percentKids);
  73.  
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement