Answered step by step
Verified Expert Solution
Link Copied!

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 #2
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 no-argument 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 1,2000, 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 setTime(long elapseTime) that sets a new time for the object using the elapsed time. For example, if the elapsed time is 555550000 milliseconds, the hour is 10, the minute is 19 and the second is 10.
Then implement a test class named Driver. In this test class create two Time objects (using new Time() and new Time(555550000)) and displays their hour, minute, and second in the format
hour:minute:second
e.g.10:19:10
Hint: For the no-argument 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 item(s):
Name your Java project as LastnameFirstname_HW02 export then upload the .zip file into the appropriate section under Assignment in D2L.(You 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions

Question

Identify and control your anxieties

Answered: 1 week ago

Question

Understanding and Addressing Anxiety

Answered: 1 week ago