Advertisement
myrdok123

06. Cinema Tickets

Jun 4th, 2023
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. package L06_NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06_CinemaTickets {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.  
  11.  
  12.         String movieName = scanner.nextLine();
  13.  
  14.         int totalTickets = 0;
  15.         int totalKidTickets = 0;
  16.         int totalStudentTickets = 0;
  17.         int totalStandardTickets = 0;
  18.  
  19.         while (!movieName.equals("Finish")){
  20.  
  21.             int countFreeSeats = Integer.parseInt(scanner.nextLine());
  22.             String ticketType = scanner.nextLine();
  23.  
  24.             int countTicketsPerMovie = 0;
  25.  
  26.  
  27.             while (!ticketType.equals("End")){
  28.                 countTicketsPerMovie ++;
  29.  
  30.                 switch (ticketType){
  31.  
  32.                     case "kid":
  33.                         totalKidTickets++;
  34.                         break;
  35.  
  36.                     case "student":
  37.                         totalStudentTickets++;
  38.                         break;
  39.  
  40.                     case "standard":
  41.                         totalStandardTickets ++;
  42.                         break;
  43.  
  44.                 }
  45.  
  46.                 if(countTicketsPerMovie == countFreeSeats ){
  47.                     break;
  48.                 }
  49.  
  50.  
  51.                 ticketType = scanner.nextLine();
  52.             }
  53.  
  54.             totalTickets += countTicketsPerMovie;
  55.  
  56.             double percentFilled = (countTicketsPerMovie * 1.0 / countFreeSeats) * 100;
  57.             System.out.printf("%s - %.2f%% full.%n", movieName, percentFilled);
  58.  
  59.  
  60.             movieName = scanner.nextLine();
  61.         }
  62.  
  63.  
  64.         double percentKidTickets = totalKidTickets * 1.0 / totalTickets * 100;
  65.         double percentStandardTickets = totalStandardTickets * 1.0 / totalTickets * 100;
  66.         double percentStudentTickets = totalStudentTickets * 1.0 / totalTickets * 100;
  67.  
  68.         System.out.printf("Total tickets: %d%n", totalTickets);
  69.         System.out.printf("%.2f%% student tickets.%n", percentStudentTickets);
  70.         System.out.printf("%.2f%% standard tickets.%n", percentStandardTickets);
  71.         System.out.printf("%.2f%% kids tickets.%n", percentKidTickets);
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement