File size: 1,703 Bytes
e9df8ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40efd14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'''
The program comes with a predefined code to read the age of the user. Your task is to print the ticket price on the screen according to the following rules:

0 - 9 years old: 2 euros
10 to 64 years old: 5 euros
over 65: free of charge


If the user enters a negative number, a message will be printed indicating an incorrect input. See the three example printouts below for a sample of the printouts:



 Example 1:
Give an age: 7
Ticket price is 2 euros
 

Example 2:
Give an age: 94
The ticket is free
 

Example 3:
Give an age: -1
The input is unviable
'''


import java.util.Random;
import java.util.Scanner;



public class Test{
    public static void main(String[] args){
        final Random r = new Random();
        
            Scanner lukija = new Scanner(System.in);
            System.out.print("Give an age: ");
            int age = Integer.valueOf(lukija.nextLine());
            
            
            if (age <0) {
              System.out.println("The input is unviable");
            }
            else if (age <10) {
              System.out.println("Ticket price is 2 euros");
            }
            else if (age <65) {
              System.out.println("Ticket price is 5 euros");
            }
            else {
              System.out.println("The ticket is free");
            }
    }
}





'''
Testing with input 7
Give an age: 7
Ticket price is 2 euros

Testing with input 14
Give an age: 14
Ticket price is 5 euros

Testing with input 19
Give an age: 19
Ticket price is 5 euros

Testing with input 84
Give an age: 84
The ticket is free

Testing with input 69
Give an age: 69
The ticket is free

Testing with input -4
Give an age: -4
The input is unviable



'''