Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CinemaTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String movieTitle = scanner.nextLine();
- int freeSeats = Integer.parseInt(scanner.nextLine());
- String ticketType = scanner.nextLine();
- int students = 0;
- int sudentsAll = 0;
- int standard = 0;
- int standardAll = 0;
- int kids = 0;
- int kidsAll = 0;
- int sumTicketsPerMovie = 0;
- int sumAllTickets = 0;
- boolean isFinished = false;
- while (!movieTitle.equals("Finish")) {
- movieTitle = movieTitle;
- freeSeats = freeSeats;
- while (!ticketType.equals("End")) {
- if (ticketType.equals("Finish")) {
- isFinished = true;
- break;
- }
- if (ticketType.equals("student")) {
- students++;
- sudentsAll++;
- } else if (ticketType.equals("standard")) {
- standard++;
- standardAll++;
- } else {
- kids++;
- kidsAll++;
- }
- sumAllTickets++;
- sumTicketsPerMovie++;
- ticketType = scanner.nextLine();
- }
- double percentUsedSeats = sumTicketsPerMovie * 1.0 / freeSeats * 100;
- System.out.printf("%s - %.2f%% full.%n", movieTitle, percentUsedSeats);
- if (isFinished) {
- break;
- }
- sumTicketsPerMovie = 0;
- students = 0;
- standard = 0;
- kids = 0;
- movieTitle = scanner.nextLine();
- freeSeats = Integer.parseInt(scanner.nextLine());
- ticketType = scanner.nextLine();
- }
- System.out.printf("Total tickets: %d%n", sumAllTickets);
- double percentStudents = sudentsAll * 1.0 / sumAllTickets * 100;
- System.out.printf("%.2f%% student tickets.%n", percentStudents);
- double percentStandard = standardAll * 1.0 / sumAllTickets * 100;
- System.out.printf("%.2f%% standard tickets.%n", percentStandard);
- double percentKids = kidsAll * 1.0 / sumAllTickets * 100;
- System.out.printf("%.2f%% kids tickets.", percentKids);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement