Guest User

CinemaTickets

a guest
Oct 20th, 2019
1,036
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class CinemaTickets {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         String movieName = "";
  8.         int emptySeats = 0;
  9.         String ticket = "";
  10.         int studentTicket = 0;
  11.         int standartTicket = 0;
  12.         int kidTicket = 0;
  13.         int ticketCounter = 0;
  14.         double studentPercent = 0.0;
  15.         double standartPercent = 0.0;
  16.         double kidPercent = 0.0;
  17.         double totalPercent = 0.0;
  18.  
  19.  
  20.         while (!"Finish".equals(movieName)) {
  21.             //System.out.print("Movie name: ");
  22.             movieName = scan.nextLine();
  23.             if ("Finish".equals(movieName)) {
  24.                 break;
  25.             }
  26.  
  27.  
  28.             //System.out.print("Empty seats:  ");
  29.             emptySeats = Integer.parseInt(scan.nextLine());
  30.  
  31.             for (int i = 1; i <= emptySeats; i++) {
  32.  
  33.                 //while (!"End".equals(ticket)) {
  34.                 //System.out.print("Ticket type: ");
  35.                 ticket = scan.nextLine();
  36.                 ticketCounter++;
  37.                 if (ticket.equals("End")) {
  38.                     break;
  39.                 }
  40.  
  41.  
  42.                 switch (ticket) {
  43.                     case "student":
  44.                         studentTicket++;
  45.                         break;
  46.                     case "standard":
  47.                         standartTicket++;
  48.                         break;
  49.                     case "kid":
  50.                         kidTicket++;
  51.                         break;
  52.  
  53.                 }
  54.  
  55.  
  56.             }
  57.             studentPercent = studentTicket * 1.0 / emptySeats * 100;
  58.             standartPercent = standartTicket * 1.0 / emptySeats * 100;
  59.             kidPercent = kidTicket * 1.0 / emptySeats * 100;
  60.             totalPercent = standartPercent + studentPercent + kidPercent;
  61.  
  62.             System.out.printf("%s - %.2f%% full.%n", movieName, totalPercent);
  63.         }
  64.         if ("Finish".equals(movieName)) {
  65.  
  66.             System.out.printf("Total tickets: %d", ticketCounter).println();
  67.             System.out.printf("%.2f%% students tickets.", studentPercent).println();
  68.             System.out.printf("%.2f%% standard tickets.", standartPercent).println();
  69.             System.out.printf("%.2f%% kid tickets.", kidPercent).println();
  70.         }
  71.     }
  72. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×