Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String stageOfTheChampionship = scanner.nextLine(),
- typesOfTickets = scanner.nextLine();
- int ticketCount = Integer.parseInt(scanner.nextLine());
- String selfieWithTheTrophy = scanner.nextLine();
- double ticketPrice = 0, totalPrice;
- if (stageOfTheChampionship.equals("Quarter final")) {
- if (typesOfTickets.equals("Standard")) {
- ticketPrice = 55.50;
- } else if (typesOfTickets.equals("Premium")) {
- ticketPrice = 105.20;
- } else if (typesOfTickets.equals("VIP")) {
- ticketPrice = 118.90;
- }
- } else if (stageOfTheChampionship.equals("Semi final")) {
- if (typesOfTickets.equals("Standard")) {
- ticketPrice = 75.88;
- } else if (typesOfTickets.equals("Premium")) {
- ticketPrice = 125.22;
- } else if (typesOfTickets.equals("VIP")) {
- ticketPrice = 300.40;
- }
- } else if (stageOfTheChampionship.equals("Final")) {
- if (typesOfTickets.equals("Standard")) {
- ticketPrice = 110.10;
- } else if (typesOfTickets.equals("Premium")) {
- ticketPrice = 160.66;
- } else if (typesOfTickets.equals("VIP")) {
- ticketPrice = 400.00;
- }
- }
- totalPrice = ticketPrice * ticketCount;
- if (totalPrice > 4000) {
- totalPrice *= 0.75;
- selfieWithTheTrophy = "N";
- } else if (totalPrice > 2500) {
- totalPrice *= 0.90;
- }
- if (selfieWithTheTrophy.equals("Y")) {
- totalPrice += ticketCount * 40;
- }
- System.out.printf("%.2f\n", totalPrice);
- }
- }
- Решение със switch и тернарен оператор:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String stageOfTheChampionship = scanner.nextLine(),
- typesOfTickets = scanner.nextLine();
- int ticketCount = Integer.parseInt(scanner.nextLine());
- String selfieWithTheTrophy = scanner.nextLine();
- double ticketPrice = switch (stageOfTheChampionship) {
- case "Quarter final" -> switch (typesOfTickets) {
- case "Standard" -> 55.50;
- case "Premium" -> 105.20;
- case "VIP" -> 118.90;
- default -> 0;
- };
- case "Semi final" -> switch (typesOfTickets) {
- case "Standard" -> 75.88;
- case "Premium" -> 125.22;
- case "VIP" -> 300.40;
- default -> 0;
- };
- case "Final" -> switch (typesOfTickets) {
- case "Standard" -> 110.10;
- case "Premium" -> 160.66;
- case "VIP" -> 400.00;
- default -> 0;
- };
- default -> 0;
- };
- double totalPrice = ticketPrice * ticketCount;
- selfieWithTheTrophy = totalPrice > 4000 ? "N" : selfieWithTheTrophy;
- totalPrice *= totalPrice > 4000 ? 0.75 : totalPrice > 2500 ? 0.90 : 1;
- totalPrice += selfieWithTheTrophy.equals("Y") ? ticketCount * 40 : 0;
- System.out.printf("%.2f\n", totalPrice);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement