Advertisement
svephoto

Cinema [Java]

Nov 27th, 2019
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Cinema {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int capacity = Integer.parseInt(scanner.nextLine());
  8.         String input = scanner.nextLine();
  9.  
  10.         int totalPeople = 0;
  11.         double finalPrice = 0;
  12.         double ticketPrice = 5.00;
  13.         double discount = 5.00;
  14.  
  15.         while (!"Movie time!".equals(input)) {
  16.             if (totalPeople <= capacity) {
  17.                 int numberOfPeople = Integer.parseInt(input);
  18.                 totalPeople += numberOfPeople;
  19.  
  20.                 double currentSum = ticketPrice * numberOfPeople;
  21.  
  22.                 if (numberOfPeople % 3 == 0) {
  23.                     currentSum -= discount;
  24.                 }
  25.  
  26.                 finalPrice += currentSum;
  27.  
  28.                 if (totalPeople > capacity) {
  29.                     finalPrice -= currentSum;
  30.                     break;
  31.                 }
  32.  
  33.                 input = scanner.nextLine();
  34.             }
  35.         }
  36.  
  37.         if ("Movie time!".equals(input)) {
  38.             System.out.printf("There are %d seats left in the cinema.%n", capacity - totalPeople);
  39.         }
  40.  
  41.         if (totalPeople > capacity) {
  42.             System.out.println("The cinema is full.");
  43.         }
  44.  
  45.         System.out.printf("Cinema income - %.0f lv.", finalPrice);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement