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 destination = scanner.nextLine(),
- cabinType = scanner.nextLine();
- int overnights = Integer.parseInt(scanner.nextLine());
- double dayPrice;
- if (destination.equals("Mediterranean")) {
- if (cabinType.equals("standard cabin")) {
- dayPrice = 27.50;
- } else if (cabinType.equals("cabin with balcony")) {
- dayPrice = 30.20;
- } else {
- dayPrice = 40.50;
- }
- } else if (destination.equals("Adriatic")) {
- if (cabinType.equals("standard cabin")) {
- dayPrice = 22.99;
- } else if (cabinType.equals("cabin with balcony")) {
- dayPrice = 25.00;
- } else {
- dayPrice = 34.99;
- }
- } else {
- if (cabinType.equals("standard cabin")) {
- dayPrice = 23.00;
- } else if (cabinType.equals("cabin with balcony")) {
- dayPrice = 26.60;
- } else {
- dayPrice = 39.80;
- }
- }
- double totalSum = dayPrice * 4 * overnights;
- if (overnights > 7) {
- totalSum *= 0.75;
- }
- System.out.printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination, totalSum);
- }
- }
- Решение с тернарен оператор:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String destination = scanner.nextLine(),
- cabinType = scanner.nextLine();
- int overnights = Integer.parseInt(scanner.nextLine());
- double dayPrice = destination.equals("Mediterranean")
- ? (cabinType.equals("standard cabin") ? 27.50 : cabinType.equals("cabin with balcony") ? 30.20 : 40.50)
- : destination.equals("Adriatic")
- ? (cabinType.equals("standard cabin") ? 22.99 : cabinType.equals("cabin with balcony") ? 25.00 : 34.99)
- : (cabinType.equals("standard cabin") ? 23.00 : cabinType.equals("cabin with balcony") ? 26.60 : 39.80);
- double totalSum = dayPrice * 4 * overnights * (overnights > 7 ? 0.75 : 1);
- System.out.printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination, totalSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement