Spaces:
Running
Running
| ''' | |
| 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 | |
| ''' |