Advertisement
Angel_Kalinkov

PBE-17July2016-MatchTickets_AngelKalinkov

Feb 21st, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.util.Scanner;
  3.  
  4. public class MatchTickets {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         BigDecimal budget = new BigDecimal(scanner.nextLine());
  9.         String ticketType = scanner.nextLine().toLowerCase();
  10.         int people = Integer.parseInt(scanner.nextLine());
  11.  
  12.         BigDecimal ticketPrice = new BigDecimal("249.99");
  13.         BigDecimal transportCosts;
  14.  
  15.         if (ticketType.equals("vip")) {
  16.             ticketPrice = new BigDecimal("499.99");
  17.         }
  18.         if (people <= 4){
  19.             transportCosts = budget.multiply(new BigDecimal("0.75"));
  20.         } else if (people <= 9) {
  21.             transportCosts = budget.multiply(new BigDecimal("0.60"));
  22.         } else if (people <= 24) {
  23.             transportCosts = budget.multiply(new BigDecimal("0.50"));
  24.         } else if (people <= 49) {
  25.             transportCosts = budget.multiply(new BigDecimal("0.40"));
  26.         } else {
  27.             transportCosts = budget.multiply(new BigDecimal("0.25"));
  28.         }
  29.         BigDecimal moneyForTickets = new BigDecimal(people).multiply(ticketPrice);
  30.         BigDecimal moneyDifference = budget.subtract(moneyForTickets.add(transportCosts));
  31.  
  32.         String output = String.format("Yes! You have %.2f leva left.", moneyDifference);
  33.         if (moneyDifference.compareTo(BigDecimal.valueOf(0)) < 0) {
  34.             output = String.format("Not enough money! You need %.2f leva.", moneyDifference.abs());
  35.         }
  36.         System.out.println(output);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement