Advertisement
veronikaaa86

07. Cinema Tickets

Jun 12th, 2021
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. package nestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07CinemaTickets {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String input = scanner.nextLine();
  10.  
  11. int countAllTickets = 0;
  12. int studentCount = 0;
  13. int standardCount = 0;
  14. int kidsCount = 0;
  15. while (!input.equals("Finish")) {
  16. String movieName = input;
  17. int freeSeats = Integer.parseInt(scanner.nextLine());
  18.  
  19. int counterTickets = 0;
  20. String command = scanner.nextLine();
  21. while (!command.equals("End")) {
  22. String typeTicket = command;
  23. counterTickets++;
  24. countAllTickets++;
  25.  
  26. switch (typeTicket) {
  27. case "student":
  28. studentCount++;
  29. break;
  30. case "standard":
  31. standardCount++;
  32. break;
  33. case "kid":
  34. kidsCount++;
  35. break;
  36. }
  37. if (freeSeats == counterTickets) {
  38. break;
  39. }
  40. command = scanner.nextLine();
  41. }
  42. System.out.printf("%s - %.2f%% full.%n", movieName, counterTickets * 1.0 / freeSeats * 100);
  43.  
  44. input = scanner.nextLine();
  45. }
  46.  
  47. System.out.println("Total tickets: " + countAllTickets);
  48. System.out.printf("%.2f%% student tickets.%n", studentCount * 1.0 / countAllTickets * 100);
  49. System.out.printf("%.2f%% standard tickets.%n", standardCount * 1.0 / countAllTickets * 100);
  50. System.out.printf("%.2f%% kids tickets.%n", kidsCount * 1.0 / countAllTickets * 100);
  51. }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement