Advertisement
veronikaaa86

07. Cinema Tickets

Apr 10th, 2021
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package nestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07CinemaTickets {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String input = scanner.nextLine();
  10.  
  11.         int counterTotalTickets = 0;
  12.         int studentCounter = 0;
  13.         int standardCounter = 0;
  14.         int kidsCounter = 0;
  15.         while (!input.equals("Finish")){
  16.             String movieName = input;
  17.             int freeSeats = Integer.parseInt(scanner.nextLine());
  18.  
  19.             int counterTicket = 0;
  20.             String command = scanner.nextLine();
  21.             while (!command.equals("End")) {
  22.                 String typeTicket = command;
  23.                 counterTicket++;
  24.  
  25.                 switch (typeTicket) {
  26.                     case "student":
  27.                         studentCounter++;
  28.                         break;
  29.                     case "standard":
  30.                         standardCounter++;
  31.                         break;
  32.                     case "kid":
  33.                         kidsCounter++;
  34.                         break;
  35.                 }
  36.  
  37.                 if (counterTicket == freeSeats) {
  38.                     break;
  39.                 }
  40.  
  41.                 command = scanner.nextLine();
  42.             }
  43.  
  44.             counterTotalTickets += counterTicket;
  45.  
  46.             System.out.printf("%s - %.2f%% full.%n", movieName, counterTicket * 1.0 / freeSeats * 100);
  47.  
  48.             input = scanner.nextLine();
  49.         }
  50.  
  51.         System.out.println("Total tickets: " + counterTotalTickets);
  52.         System.out.printf("%.2f%% student tickets.%n", studentCounter * 1.0 / counterTotalTickets * 100);
  53.         System.out.printf("%.2f%% standard tickets.%n", standardCounter * 1.0 / counterTotalTickets * 100);
  54.         System.out.printf("%.2f%% kids tickets.%n", kidsCounter * 1.0 / counterTotalTickets * 100);
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement