Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Homework Assignment # 2 Classes and Objects Problem: Implement a class named Time. The class should contain: The data fields for hour, minute, and second
Homework Assignment #
Classes and Objects
Problem:
Implement a class named Time. The class should contain:
The data fields for hour, minute, and second that represent a time.
A noargument constructor that creates a Time object for the current time. The values of the data fields will represent the current time.
A constructor that constructs a Time object with a specified elapsed time since midnight, January in milliseconds. The values of the data fields will represent this time.
A constructor that constructs a Time object with the specified hour, minute, and second.
Three getter methods for the data fields hour, minute, and second, respectively.
A method named setTimelong elapseTime that sets a new time for the object using the elapsed time. For example, if the elapsed time is milliseconds, the hour is the minute is and the second is
Then implement a test class named Driver. In this test class create two Time objects using new Time and new Time and displays their hour, minute, and second in the format
hour:minute:second
eg::
Hint: For the noargument constructor, the current time can be obtained using System.currentTimeMillis The other two constructors will extract the hour, minute, and second from the elapsed time.
Comments and Style
Comment your code.
At the top of the program include your name, a brief description of the problems you are solving and what it does and the due date.
Note: Follow the instructions given.
All blocks must be indented consistently and correctly. Blocks are delimited by opening and closing curly braces.
Opening and closing curly braces must be aligned consistently
Variable names should convey meaning
Requirements
Prompt the user for the inputs and store the values in variables
You must include all the inputs and outputs listed above and perform the calculations correctly
Make the output look attractive. It should be better than the sample run above.
The program should display your name
Hints:
Solve the problem in pieces.
Start early.
Deliverables:
Submit the following items:
Name your Java project as LastnameFirstnameHW export then upload the zip file into the appropriate section under Assignment in DLYou must submit the program regardless of whether it complete or incomplete, correct, or incorrect
Note: Strictly follow the export instructions to submit your assignment.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started