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