Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FishingBoat {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int budget = Integer.parseInt(scanner.nextLine());
- String season = scanner.nextLine();
- int people = Integer.parseInt(scanner.nextLine());
- double sum = switch (season) {
- case "Spring" -> 3000;
- case "Summer", "Autumn" -> 4200;
- case "Winter" -> 2600;
- default -> 0;
- };
- if (people <= 6) {
- sum *= 0.9;
- } else if (people <= 11) {
- sum *= 0.85;
- } else {
- sum *= 0.75;
- }
- if (people % 2 == 0 && !season.equals("Autumn")) {
- sum *= 0.95;
- }
- if (sum <= budget) {
- System.out.printf("Yes! You have %.2f leva left.", budget - sum);
- } else {
- System.out.printf("Not enough money! You need %.2f leva.", sum - budget);
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class FishingBoat {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String season = scanner.nextLine();
- int people = Integer.parseInt(scanner.nextLine());
- budget -= (season.equals("Spring") ? 3000 : season.equals("Winter") ? 2600 : 4200)
- * (people <= 6 ? 0.9 : people > 11 ? 0.75 : 0.85)
- * (people % 2 == 0 && !season.equals("Autumn") ? 0.95 : 1);
- if (budget >= 0) {
- System.out.printf("Yes! You have %.2f leva left.", budget);
- } else {
- System.out.printf("Not enough money! You need %.2f leva.", Math.abs(budget));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement