Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nestedLoops;
- import java.util.Scanner;
- public class P07CinemaTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- int countAllTickets = 0;
- int studentCount = 0;
- int standardCount = 0;
- int kidsCount = 0;
- while (!input.equals("Finish")) {
- String movieName = input;
- int freeSeats = Integer.parseInt(scanner.nextLine());
- int counterTickets = 0;
- String command = scanner.nextLine();
- while (!command.equals("End")) {
- String typeTicket = command;
- counterTickets++;
- countAllTickets++;
- switch (typeTicket) {
- case "student":
- studentCount++;
- break;
- case "standard":
- standardCount++;
- break;
- case "kid":
- kidsCount++;
- break;
- }
- if (freeSeats == counterTickets) {
- break;
- }
- command = scanner.nextLine();
- }
- System.out.printf("%s - %.2f%% full.%n", movieName, counterTickets * 1.0 / freeSeats * 100);
- input = scanner.nextLine();
- }
- System.out.println("Total tickets: " + countAllTickets);
- System.out.printf("%.2f%% student tickets.%n", studentCount * 1.0 / countAllTickets * 100);
- System.out.printf("%.2f%% standard tickets.%n", standardCount * 1.0 / countAllTickets * 100);
- System.out.printf("%.2f%% kids tickets.%n", kidsCount * 1.0 / countAllTickets * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement