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