Advertisement
GabrielHr00

06. Cinema Tickets

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