Advertisement
ivobora

Cinema Tickets 6 задача

Apr 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int standardCount = 0;
  9.         int studentCount = 0;
  10.         int kidCount = 0;
  11.         int people = 0;
  12.  
  13.  
  14.         String filmName = scanner.nextLine();
  15.         while (!"Finish".equals(filmName)){
  16.             int freeSpaces = Integer.parseInt(scanner.nextLine());
  17.             int peopleInRoom = 0;
  18.             for (int i = 0; i < freeSpaces; i++){
  19.                 String type = scanner.nextLine();
  20.                 if ( "End".equals(type)){
  21.                     break;
  22.                 }
  23.                 peopleInRoom++;
  24.                 people++;
  25.                 switch (type){
  26.                     case "standard":
  27.                         standardCount++;
  28.                         break;
  29.                     case "student":
  30.                         studentCount++;
  31.                         break;
  32.                     case "kid":
  33.                         kidCount++;
  34.                         break;
  35.                 }
  36.             }
  37.             double perc = (peopleInRoom*1.0/freeSpaces) * 100;
  38.             System.out.printf("%s - %.2f%% full.", filmName, perc).println();
  39.             filmName = scanner.nextLine();
  40.         }
  41.         double standardPerc = (standardCount*1.0/people) * 100;
  42.         double studentPerc = (studentCount*1.0/people) * 100;
  43.         double kidPerc = (kidCount*1.0/people) * 100;
  44.  
  45.         System.out.printf("Total tickets: %d",people).println();
  46.         System.out.printf("%.2f%% student tickets.", studentPerc).println();
  47.         System.out.printf("%.2f%% standard tickets.", standardPerc).println();
  48.         System.out.printf("%.2f%% kids tickets.", kidPerc);
  49.  
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement