Advertisement
Spocoman

Cinema Tickets

Sep 3rd, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int seats, kidTickets = 0, studentTickets = 0, standardTickets = 0;
  7.         String movie, category;
  8.  
  9.         while (!(movie = scanner.nextLine()).equals("Finish")) {
  10.             seats = Integer.parseInt(scanner.nextLine());
  11.             int counter = 0;
  12.  
  13.             for (int i = 0; i < seats; i++) {
  14.                 category = scanner.nextLine();
  15.                 if (category.equals("student")) {
  16.                     studentTickets++;
  17.                 } else if (category.equals("standard")) {
  18.                     standardTickets++;
  19.                 } else if (category.equals("kid")) {
  20.                     kidTickets++;
  21.                 } else {
  22.                     break;
  23.                 }
  24.                 counter++;
  25.             }
  26.  
  27.             System.out.printf("%s - %.2f%% full.\n", movie, 1.0 * counter / seats * 100);
  28.         }
  29.  
  30.         int sumTickets = standardTickets + studentTickets + kidTickets;
  31.  
  32.         System.out.printf("Total tickets: %d\n", sumTickets);
  33.         System.out.printf("%.2f%% student tickets.\n", 1.0 * studentTickets / sumTickets * 100);
  34.         System.out.printf("%.2f%% standard tickets.\n", 1.0 * standardTickets / sumTickets * 100);
  35.         System.out.printf("%.2f%% kids tickets.\n", 1.0 * kidTickets / sumTickets * 100);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement