Question: In Java Programming Overview: Write a program that accepts a time from the keyboard and prints the times in simplified form. Input: The program must

In Java Programming

Overview: Write a program that accepts a time from the keyboard and prints the times in simplified form.

Input: The program must accept times in the following form : : :

where each , , and are integers and the spaces around the colon are

optional.

Overview

Write a program that accepts a time from the keyboard and prints the times in simplified form.

Input

The program must accept times in the following form : : :

where each , , and are integers and the spaces around the colon are optional.

In order to use a Scanner, we need to specify that : is a delimiter character (a character that indicates the end of an expression and the beginning of another similar to a period between sentences). When creating the Scanner the following code is required:

new Scanner(System.in).useDelimiter("\\s*:\\s*");

Prompt the user with the exact phrasing of the sample input / output shown below; note that the input from the keyboard is depicted in red: Enter the time in the form : 1:2:3:

The time consists of 3723 seconds.

Simplified time: 1:2:3:

Requirements

  • The name of the class that contains the main must be TimeInterpreter.

  • Output will generally follow the same input format where days, hours, minutes, and seconds must be followed by a colon (:); see sample output for examples.

  • All times will be output without spaces (or other whitespace).

  • Negative Times. If a specified time is negative, it should be printed with a single leading negative. For example, 0:-2:-34: is output as -2:34:.

  • Simplification. Times must be simplified before printed. For example, 12:2:-34: is simplified and output as 12:1:26.

  • Output Brevity. For input time 0:2:34:, the corresponding output should not list the number of hours (since there are none): 2:34:.

  • A single output print statement will be allowed in the final solution code. That is, a proper solution will construct a String object and output it at the end of the program.

  • You must define and use constants representing the number of seconds per minute, hour, and day.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!