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);
- int personCount = Integer.parseInt(scanner.nextLine());
- String season = scanner.nextLine();
- double personPrice;
- if (season.equals("spring")) {
- if (personCount <= 5) {
- personPrice = 50.00;
- } else {
- personPrice = 48.00;
- }
- } else if (season.equals("summer")) {
- if (personCount <= 5) {
- personPrice = 48.50;
- } else {
- personPrice = 45.00;
- }
- } else if (season.equals("autumn")) {
- if (personCount <= 5) {
- personPrice = 60.00;
- } else {
- personPrice = 49.50;
- }
- } else {
- if (personCount <= 5) {
- personPrice = 86.00;
- } else {
- personPrice = 85.00;
- }
- }
- if (season.equals("summer")) {
- personPrice *= 0.85;
- } else if (season.equals("winter")) {
- personPrice *= 1.08;
- }
- System.out.printf("%.2f leva.", personPrice * personCount);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int personCount = Integer.parseInt(scanner.nextLine());
- String season = scanner.nextLine();
- double personPrice = switch (season) {
- case "spring" -> personCount <= 5 ? 50.00 : 48.00;
- case "summer" -> personCount <= 5 ? 48.50 : 45.00;
- case "autumn" -> personCount <= 5 ? 60.00 : 49.50;
- case "winter" -> personCount <= 5 ? 86.00 : 85.00;
- default -> 0;
- };
- personPrice *=
- season.equals("summer") ? 0.85
- : season.equals("winter") ? 1.08 : 1;
- System.out.printf("%.2f leva.", personPrice * personCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement