desislava_topuzakova

07. Cinema Tickets

May 15th, 2021
680
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class OldBooks_01 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String movie = scanner.nextLine();
  7.         int totalTickets = 0;
  8.         int countStudentTickets = 0;
  9.         int countStandardTickets = 0;
  10.         int countKidsTickets = 0;
  11.  
  12.         while (!movie.equals("Finish")) {
  13.             //филм
  14.             int freeSeats = Integer.parseInt(scanner.nextLine());
  15.             int takenSeats = 0;
  16.             while (true) {
  17.                 String ticketType = scanner.nextLine(); //тип на билета
  18.                 if (ticketType.equals("End")) {
  19.                     break;
  20.                 }
  21.                 totalTickets++;
  22.                 takenSeats++;
  23.                 //проверка за билета
  24.                 if (ticketType.equals("student")) {
  25.                     countStudentTickets++;
  26.                 } else if (ticketType.equals("standard")) {
  27.                     countStandardTickets++;
  28.                 } else if (ticketType.equals("kid")){
  29.                     countKidsTickets++;
  30.                 }
  31.                 //проверка дали има още свободни места
  32.                 if (takenSeats >= freeSeats) {
  33.                     break;
  34.                 }
  35.                 //"student", "standard", "kid"
  36.  
  37.  
  38.             }
  39.  
  40.             double percentTaken = takenSeats * 1.0 / freeSeats * 100;
  41.             System.out.printf("%s - %.2f%% full.%n", movie, percentTaken);
  42.             movie = scanner.nextLine();
  43.         }
  44.  
  45.             System.out.printf("Total tickets: %d%n", totalTickets);
  46.             double percentStudent = countStudentTickets * 1.0 / totalTickets * 100;
  47.             System.out.printf("%.2f%% student tickets.%n", percentStudent);
  48.             double percentStandard = countStandardTickets * 1.0 / totalTickets * 100;
  49.             System.out.printf("%.2f%% standard tickets.%n", percentStandard);
  50.             double percentKids = countKidsTickets * 1.0 / totalTickets * 100;
  51.             System.out.printf("%.2f%% kids tickets.%n", percentKids);
  52.  
  53.  
  54.  
  55.     }
  56. }
RAW Paste Data