Advertisement
veronikaaa86

07. Cinema Tickets

Aug 7th, 2021
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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.  
  24. counterTickets++;
  25. countAllTickets++;
  26.  
  27. switch (typeTicket) {
  28. case "student":
  29. studentCount++;
  30. break;
  31. case "standard":
  32. standardCount++;
  33. break;
  34. case "kid":
  35. kidsCount++;
  36. break;
  37. }
  38.  
  39. if (counterTickets == freeSeats){
  40. break;
  41. }
  42.  
  43. command = scanner.nextLine();
  44. }
  45.  
  46. System.out.printf("%s - %.2f%% full.%n", movieName, counterTickets * 1.0 / freeSeats * 100);
  47.  
  48. input = scanner.nextLine();
  49. }
  50.  
  51. System.out.printf("Total tickets: %d%n", countAllTickets);
  52. System.out.printf("%.2f%% student tickets.%n", studentCount * 1.0 / countAllTickets * 100);
  53. System.out.printf("%.2f%% standard tickets.%n", standardCount * 1.0 / countAllTickets * 100);
  54. System.out.printf("%.2f%% kids tickets.%n", kidsCount * 1.0 / countAllTickets * 100);
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement