C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 30PE
icon
Related questions
Topic Video
Question
In java
Project #1: Time Interpreter
Overview
Write a program that accepts a time from the keyboard and prints the times
form.
seconds and in simplified
Input
The program must accept times in the following form:
<hours> [space] <minutes> [space] <seconds>
where each <hours>, <minutes>, and <seconds> are integers and [space] represents the space
being
Prompt the user with the exact phrasing of the sample input / output shown below; note that the input
from the keyboard is depicted in green:
Enter the time in the form <hours minutes seconds>:
1 23
The time consists of 3723 seconds.
Simplified time: 1:2:3
Requirements
The name of the class that contains the main must be TimeInterpreter.
• While input uses spaces between the input numbers, the output format with days, hours, minutes,
and seconds should be delimited by colons; 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.
Transcribed Image Text:Project #1: Time Interpreter Overview Write a program that accepts a time from the keyboard and prints the times form. seconds and in simplified Input The program must accept times in the following form: <hours> [space] <minutes> [space] <seconds> where each <hours>, <minutes>, and <seconds> are integers and [space] represents the space being Prompt the user with the exact phrasing of the sample input / output shown below; note that the input from the keyboard is depicted in green: Enter the time in the form <hours minutes seconds>: 1 23 The time consists of 3723 seconds. Simplified time: 1:2:3 Requirements The name of the class that contains the main must be TimeInterpreter. • While input uses spaces between the input numbers, the output format with days, hours, minutes, and seconds should be delimited by colons; 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.
Sample Input / Output
Please use all of the following examples for test cases (your grader will), but do not limit your tests to
these input times. There is no need to represent time beyond days in your output.
Input Time
Expected Output Time
1 2 3
1:2:3
1 2 90
1:3:30
1 2 -90
1:0:30
48 0 0
2:0:0:0
0 0 0
0 2 -120
1 -300 2
-3:59:58
Recommendations
• Compute the number of seconds represented by the input and use the number of seconds for the
basis of your output; use a long for this quantity.
• Before coding, work out on paper the logic and computations for a given time.
Be thorough in your testing because it is an instructor's (or grader's) job to try and break your
code.
Transcribed Image Text:Sample Input / Output Please use all of the following examples for test cases (your grader will), but do not limit your tests to these input times. There is no need to represent time beyond days in your output. Input Time Expected Output Time 1 2 3 1:2:3 1 2 90 1:3:30 1 2 -90 1:0:30 48 0 0 2:0:0:0 0 0 0 0 2 -120 1 -300 2 -3:59:58 Recommendations • Compute the number of seconds represented by the input and use the number of seconds for the basis of your output; use a long for this quantity. • Before coding, work out on paper the logic and computations for a given time. Be thorough in your testing because it is an instructor's (or grader's) job to try and break your code.
Expert Solution
Step 1

Java code is giving below-

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning