silviasj

Cinema Tickets

Apr 13th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 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.         double tickets = 0;
  7.         int ticketsNumber = 0;
  8.         double standardTickets = 0;
  9.         double studentTickets = 0;
  10.         double kidTickets = 0;
  11.         for (; ; ) {
  12.             String filmName = scanner.nextLine();
  13.             if (filmName.equalsIgnoreCase("Finish")) {
  14.                 System.out.printf("Total tickets: %d\n", ticketsNumber);
  15.                 System.out.printf("%.2f%% student tickets.\n", (studentTickets / ticketsNumber) * 100);
  16.                 System.out.printf("%.2f%% standard tickets.\n", (standardTickets / ticketsNumber) * 100);
  17.                 System.out.printf("%.2f%% kids tickets.\n", (kidTickets / ticketsNumber) * 100);
  18.                 break;
  19.             }
  20.             int freePlaces = Integer.parseInt(scanner.nextLine());
  21.             for (; ; ) {
  22.                 String type = scanner.nextLine();
  23.                 if (type.equalsIgnoreCase("Standard")) {
  24.                     standardTickets++;
  25.                 } else if (type.equalsIgnoreCase("Student")) {
  26.                     studentTickets++;
  27.                 } else if (type.equalsIgnoreCase("Kid")) {
  28.                     kidTickets++;
  29.                 }
  30.  
  31.  
  32.                 if (type.equalsIgnoreCase("End")) {
  33.                     System.out.printf("%s - %.2f%% full.\n", filmName, ((tickets) / freePlaces) * 100);
  34.                     tickets = 0;
  35.                     break;
  36.                 }
  37.                 ticketsNumber++;
  38.                 tickets += 1;
  39.                 if (tickets >= freePlaces) {
  40.  
  41.                     System.out.printf("%s - %.2f%% full.\n", filmName, (tickets / freePlaces) * 100);
  42.                     tickets = 0;
  43.                     break;
  44.                 }
  45.             }
  46.         }
  47.  
  48.  
  49.     }
  50. }
Add Comment
Please, Sign In to add comment