Concept explainers
Design a class named Time. The class contains:
■■ The data fields hour, minute, and second that represent a time.
■■ A no-arg 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, 1970, 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.
Draw the UML diagram for the class then implement the class. Write a
test program that creates three Time objects (using new Time(), new
Time(555550000), and new Time(5, 23, 55)) and displays their hour,
minute, and second in the format hour:minute:second.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images
- Design a class named Fan to represent a fan. The class contains: VideoNote The Fan class ▪ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ▪ A private int data field named speed that specifies the speed of the fan (the default is SLOW). ▪ A private boolean data field named on that specifies whether the fan is on (the default is false). ▪ A private double data field named radius that specifies the radius of the fan (the default is 5). ▪ A string data field named color that specifies the color of the fan (the default is blue). ▪ The accessor and mutator methods for all four data fields. ▪ A no-arg constructor that creates a default fan. ▪ A method named toString() that returns a string description for the fan. If the fan is on, the method returns the fan speed, color, and radius in one combined string. If the fan is not on, the method returns the fan color and radius along with the string "fan is off" in one combined string. Draw the UML…arrow_forwardDesign a class named MyDate. The class contains:■■ The data fields year, month, and day that represent a date. month is 0-based,i.e., 0 is for January.■■ A no-arg constructor that creates a MyDate object for the current date.■■ A constructor that constructs a MyDate object with a specified elapsed timesince midnight, January 1, 1970, in milliseconds.■■ A constructor that constructs a MyDate object with the specified year, month,and day.■■ Three getter methods for the data fields year, month, and day, respectively.■■ A method named setDate(long elapsedTime) that sets a new date forthe object using the elapsed time. Draw the UML diagram for the class then implement the class. Write a testprogram that creates two MyDate objects (using new MyDate() and newMyDate(34355555133101L)) and displays their year, month, and day.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education