THINK FIRST·CODE LATER

← All labs

Calendar and clock arithmetic with %

Problem

Days of the week are numbered 0 (Sunday) to 6 (Saturday), and hours 0 to 23. ClockMath reads today's day number, a number of days ahead, the current hour and a number of hours ahead, and prints:

  • the day number after those days: (today + daysAhead) % 7;
  • how many full weeks lie in between: daysAhead / 7;
  • the hour after those hours, and how many days later that is.

For the input

2 10 22 5

the program prints

Day number in 10 days: 5
Full weeks in between: 1
Hour in 5 hours: 3
That is 1 day(s) later

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.

l4-7-data-1.txt

2 10 22 5
What your program must print for l4-7-data-1.txt
Day number in 10 days: 5
Full weeks in between: 1
Hour in 5 hours: 3
That is 1 day(s) later

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 < l4-7-data-1.txt

Windows PowerShell does not understand <:

Get-Content l4-7-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.