Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class E04MatchTickets {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- BigDecimal budget = new BigDecimal(scanner.nextLine());
- String ticketType = scanner.nextLine();
- int people = Integer.parseInt(scanner.nextLine());
- BigDecimal transportCharges = new BigDecimal("0.00");
- BigDecimal moneyForTickets = new BigDecimal("0.00");
- BigDecimal moneyDiff = new BigDecimal("0.00");
- if (people >= 1 && people < 5) {
- transportCharges = new BigDecimal("0.75").multiply(budget);
- } else if (people >= 5 && people < 10) {
- transportCharges = new BigDecimal("0.60").multiply(budget);
- } else if (people >= 10 && people < 24) {
- transportCharges = new BigDecimal("0.50").multiply(budget);
- } else if (people >= 24 && people < 50) {
- transportCharges = new BigDecimal("0.40").multiply(budget);
- } else if (people >= 50) {
- transportCharges = new BigDecimal("0.25").multiply(budget);
- }
- switch (ticketType) {
- case "Normal":
- moneyForTickets =
- new BigDecimal(people).multiply(
- new BigDecimal("249.99"));
- break;
- case "VIP":
- moneyForTickets =
- new BigDecimal(people).multiply(
- new BigDecimal("499.99"));
- break;
- default:
- moneyForTickets =
- new BigDecimal(people).multiply(
- new BigDecimal("249.99"));
- break;
- }
- DecimalFormat decimalFormetter = new DecimalFormat("0.00");
- moneyDiff = budget.subtract(
- transportCharges.add(moneyForTickets));
- String result = String.format(
- "Yes! You have %s leva left.",
- decimalFormetter.format(moneyDiff.setScale(
- 2, BigDecimal.ROUND_HALF_UP)));
- if (moneyDiff.compareTo(BigDecimal.valueOf(0)) < 0) {
- result = String.format(
- "Not enough money! You need %s leva.",
- decimalFormetter.format(moneyDiff.setScale(
- 2, BigDecimal.ROUND_HALF_UP).abs()));
- }
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement