Advertisement
Lyubohd

07. Cinema Tickets

Apr 26th, 2020
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         String input = scan.nextLine();
  7.         int studentCounter = 0;
  8.         int standardCounter = 0;
  9.         int kidCounter = 0;
  10.  
  11.         while (!input.equals("Finish")) {
  12.             int seatsCnt = Integer.parseInt(scan.nextLine());
  13.             int peopleCounter = 0;
  14.             for (int i = 0; i < seatsCnt; i++) {
  15.                 String ticketType = scan.nextLine();
  16.                 if (ticketType.equals("End")) {
  17.                     break;
  18.                 }
  19.  
  20.                 peopleCounter++;
  21.                 switch (ticketType) {
  22.                     case "student":
  23.                         studentCounter++;
  24.                         break;
  25.                     case "standard":
  26.                         standardCounter++;
  27.                         break;
  28.                     case "kid":
  29.                         kidCounter++;
  30.                         break;
  31.                 }
  32.             }
  33.             double percent = peopleCounter * 1.0 / seatsCnt * 100;
  34.             System.out.printf("%s - %.2f%% full.%n", input, percent);
  35.  
  36.             input = scan.nextLine();
  37.         }
  38.  
  39.         int peopleCounter = studentCounter + standardCounter + kidCounter;
  40.         System.out.printf("Total tickets: %d%n", peopleCounter);
  41.         System.out.printf("%.2f%% student tickets.%n", studentCounter * 1.0 / peopleCounter * 100);
  42.         System.out.printf("%.2f%% standard tickets.%n", standardCounter * 1.0 / peopleCounter * 100);
  43.         System.out.printf("%.2f%% kids tickets.%n", kidCounter * 1.0 / peopleCounter * 100);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement