THINK FIRST·CODE LATER

← All labs

Museum ticket prices

Problem

Write TicketPrice. Read an age, whether the visitor is a student (true/false) and the day (Mon … Sun). Rules:

  • age < 0 or > 120 → print Invalid age and stop;
  • under 6: free; 6–17: 30; 65 and over: 25; otherwise 50 yuan;
  • adult students (18–64) get 20 % off;
  • on Saturday and Sunday, add 10 yuan to any non-free ticket.

Print Ticket: 50.00 yuan and one of Free entry, Weekend price, Weekday price.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l6-3-data-1.txt

30 false Mon
What your program must print for l6-3-data-1.txt
Ticket: 50.00 yuan
Weekday price

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l6-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content l6-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.