Advertisement
Spocoman

06. Cinema Tickets

Aug 30th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CinemaTickets {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int standardTickets = 0, studentTickets = 0, kidTickets = 0;
  7.  
  8.         String movie;
  9.         while (!(movie = scanner.nextLine()).equals("Finish")) {
  10.             int seats = Integer.parseInt(scanner.nextLine()),
  11.                     counter = 0;
  12.  
  13.             String category;
  14.             while (counter != seats && !(category = scanner.nextLine()).equals("End")) {
  15.                 if (category.equals("standard")) {
  16.                     standardTickets++;
  17.                 } else if (category.equals("student")) {
  18.                     studentTickets++;
  19.                 } else {
  20.                     kidTickets++;
  21.                 }
  22.                 counter++;
  23.             }
  24.             System.out.printf("%s - %.2f%% full.\n", movie, 1.0 * counter / seats * 100);
  25.         }
  26.  
  27.         int totalTickets = studentTickets + standardTickets + kidTickets;
  28.  
  29.         System.out.printf("Total tickets: %d\n", totalTickets);
  30.         System.out.printf("%.2f%% student tickets.\n", 1.0 * studentTickets / totalTickets * 100);
  31.         System.out.printf("%.2f%% standard tickets.\n", 1.0 * standardTickets / totalTickets * 100);
  32.         System.out.printf("%.2f%% kids tickets.\n", 1.0 * kidTickets / totalTickets * 100);
  33.     }
  34. }
  35.  
  36. ИЛИ:
  37.  
  38. import java.util.Scanner;
  39.  
  40. public class CinemaTickets {
  41.     public static void main(String[] args) {
  42.         Scanner scanner = new Scanner(System.in);
  43.         int standardTickets = 0, studentTickets = 0, kidTickets = 0;
  44.  
  45.         String movie;
  46.         while (!(movie = scanner.nextLine()).equals("Finish")) {
  47.             int seats = Integer.parseInt(scanner.nextLine()),
  48.                     counter = 0;
  49.  
  50.             String category;
  51.             while (counter != seats && !(category = scanner.nextLine()).equals("End")) {
  52.                 int i = category.equals("standard") ? standardTickets++ :
  53.                         category.equals("student") ? studentTickets++ : kidTickets++;
  54.                 counter++;
  55.             }
  56.             System.out.printf("%s - %.2f%% full.\n", movie, 1.0 * counter / seats * 100);
  57.         }
  58.  
  59.         int totalTickets = studentTickets + standardTickets + kidTickets;
  60.  
  61.         System.out.printf("Total tickets: %d\n", totalTickets);
  62.         System.out.printf("%.2f%% student tickets.\n", 1.0 * studentTickets / totalTickets * 100);
  63.         System.out.printf("%.2f%% standard tickets.\n", 1.0 * standardTickets / totalTickets * 100);
  64.         System.out.printf("%.2f%% kids tickets.\n", 1.0 * kidTickets / totalTickets * 100);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement