Advertisement
Guest User

Untitled

a guest
Jun 4th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CinemaVoucher {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int voucherValue = Integer.parseInt(scanner.nextLine());
  8.         int tickets = 0;
  9.         int other = 0;
  10.         int price;
  11.  
  12.         String command = scanner.nextLine();
  13.         while (!command.equals("End")) {
  14.             String purchase = command;
  15.  
  16.             if (purchase.length() > 8) {
  17.                 price = purchase.charAt(0) + purchase.charAt(1);
  18.             } else {
  19.                 price = purchase.charAt(0);
  20.             }
  21.  
  22.             if (price > voucherValue) {
  23.                 break;
  24.             }
  25.  
  26.             if (purchase.length() > 8) {
  27.                 tickets++;
  28.             } else {
  29.                 other++;
  30.             }
  31.  
  32.             voucherValue = voucherValue - price;
  33.  
  34.             command = scanner.nextLine();
  35.         }
  36.  
  37.         System.out.println(tickets);
  38.         System.out.println(other);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement