Advertisement
Guest User

Cinema Tickets JAVA

a guest
Jun 6th, 2020
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CinemaTickets {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String nameMovie = scanner.nextLine();
  8.  
  9.         int counterTotalTickets = 0;
  10.         int counterStudents = 0;
  11.         int counterStandard = 0;
  12.         int counterKids = 0;
  13.  
  14.         boolean isFinished = false;
  15.  
  16.  
  17.         while(!nameMovie.equals("Finish")){
  18.  
  19.             int freeSeats = Integer.parseInt(scanner.nextLine());
  20.             String typeTickets = scanner.nextLine();
  21.             int counterTicketsPerMovie = 0;
  22.  
  23.             while(!typeTickets.equals("End")){
  24.  
  25.                 if (typeTickets.equals("Finish")){
  26.                     isFinished = true;
  27.                     break;
  28.                 }
  29.                 counterTotalTickets++;
  30.                 counterTicketsPerMovie++;
  31.  
  32.                 if (counterTicketsPerMovie >= freeSeats){
  33.                     double percentFull = ((counterTicketsPerMovie * 1.0) / freeSeats) * 100;
  34.                     System.out.printf("%s - %.2f%% full.%n",nameMovie, percentFull);
  35.                     break;
  36.                 }
  37.  
  38.                 if (typeTickets.equals("student")){
  39.                     counterStudents++;
  40.                 } else if (typeTickets.equals("standard")){
  41.                     counterStandard++;
  42.                 } else if (typeTickets.equals("kid")){
  43.                     counterKids++;
  44.                 }
  45.  
  46.                 typeTickets = scanner.nextLine();
  47.             }
  48.  
  49.             if (isFinished){
  50.                 break;
  51.             }
  52.             nameMovie = scanner.nextLine();
  53.         }
  54.         System.out.printf("Total tickets: %d%n", counterTotalTickets);
  55.  
  56.         double percentStudents = (counterStudents * 1.0 / counterTotalTickets) * 100;
  57.         double percentStandard = (counterStandard * 1.0 / counterTotalTickets) * 100;
  58.         double percentKids = (counterKids * 1.0 / counterTotalTickets) * 100;
  59.  
  60.         System.out.printf("%.2f%% student tickets.%n%.2f%% standard tickets.%n%.2f%% kids tickets.",percentStudents, percentStandard, percentKids);
  61.  
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement