Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main5 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String week = scanner.nextLine();
- int age = Integer.parseInt(scanner.nextLine());
- int price = 0;
- boolean isTrue = age < 0 || age > 122;
- switch (week) {
- case "Weekday":
- if (age >= 0 && age <= 18) {
- price = 12;
- } else if (age > 18 && age <= 64) {
- price = 18;
- } else if (age > 64 && age <= 122) {
- price = 12;
- }
- break;
- case "Weekend":
- if (age >= 0 && age <= 18) {
- price = 15;
- } else if (age > 18 && age <= 64) {
- price = 20;
- } else if (age > 64 && age <= 122) {
- price = 15;
- }
- break;
- case "Holiday":
- if (age >= 0 && age <= 18) {
- price = 5;
- } else if (age > 18 && age <= 64) {
- price = 12;
- } else if (age > 64 && age <= 122) {
- price = 10;
- }
- break;
- default:
- System.out.println("Error!");
- break;
- }
- if (isTrue) {
- System.out.println("Error!");
- } else {
- System.out.println(String.format("%d$", price));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement