Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.util.Scanner;
- public class MatchTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- BigDecimal budget = new BigDecimal(scanner.nextLine());
- String ticketType = scanner.nextLine().toLowerCase();
- int people = Integer.parseInt(scanner.nextLine());
- BigDecimal ticketPrice = new BigDecimal("249.99");
- BigDecimal transportCosts;
- if (ticketType.equals("vip")) {
- ticketPrice = new BigDecimal("499.99");
- }
- if (people <= 4){
- transportCosts = budget.multiply(new BigDecimal("0.75"));
- } else if (people <= 9) {
- transportCosts = budget.multiply(new BigDecimal("0.60"));
- } else if (people <= 24) {
- transportCosts = budget.multiply(new BigDecimal("0.50"));
- } else if (people <= 49) {
- transportCosts = budget.multiply(new BigDecimal("0.40"));
- } else {
- transportCosts = budget.multiply(new BigDecimal("0.25"));
- }
- BigDecimal moneyForTickets = new BigDecimal(people).multiply(ticketPrice);
- BigDecimal moneyDifference = budget.subtract(moneyForTickets.add(transportCosts));
- String output = String.format("Yes! You have %.2f leva left.", moneyDifference);
- if (moneyDifference.compareTo(BigDecimal.valueOf(0)) < 0) {
- output = String.format("Not enough money! You need %.2f leva.", moneyDifference.abs());
- }
- System.out.println(output);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement