Advertisement
veronikaaa86

06. Cinema Tickets

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