Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

language Java all parts please thanks ! Objective: Complete and test an instantiable Java class that keeps track of information for a clock time. Description:

language Java all parts please thanks !
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Objective: Complete and test an instantiable Java class that keeps track of information for a clock time. Description: Chapter 9 of your textbook introduces you to the idea writing your own instantiable classes. As you have learned, these are the types of classes from which you can create objects. 1. Start your work by copying the BlueJ project named Assign9Clock (available from Canvas as a zip file) 2. You will see a class already in your project named TestclockTime. This class holds a main () method which tests all the parts of the ClockTime class. 3. Add a new class to your project named ClockTime. This is your instantiable class. Instance variables Each ClockTime object needs 3 private data fields, all integers (please use the exact names as specified below). In your comments, please note that this type of object keeps time in the 24-hour format. 1. hour holds the ClockTime hour setting 2. minute holds the ClockTime minute setting 3. second holds the ClockTime second setting Constructors Test each of these by right-clicking on the class to create the object and then inspecting the object created. This class needs 2 constructors: 1. A default (no parameter) version that sets all instance variables to zeroes. 2. An alternate version that takes 3 integer parameters, holding the hour, minute and second values (IN THAT ORDER) to which the ClockTime object should be initialized. However, the constructor needs to do a little error checking, too: - If the seconds parameter is over 59 , use mod 60 to make it 59 or lower, and add the extra minutes to the minutes parameter. If negative, make it zero. - If the minute parameter is over 59 , use mod 60 to make it 59 or lower, and add the extra hour value to the hours parameter. If negative, make it zero. - If the hour parameter is over 24 , use mod 24 to make it 23 or lower. If negative, make it zero. Instance methods Test each of these by first creating an object on BlueJ's object bench and right-clicking on it to choose and run individual instance methods. 1. "Getter" (Accessor) methods The class should have public "getter" methods for each of the instance variables. The methods must be named: - int getHour() - int getminute () - int getsecond() 2. "Setter" (Mutator) methods The class should have public "setter" methods for each of the instance variables. The methods must be named: - void setHour (int) - void setMinute (int) - void setSecond(int) Please make sure to do the same range checks as required in the constructor, so that the instance variable values are valid. 3. Methods that create Strings There are two ways a time in a 24 -hour clock can be displayed. For example, 3:25:0 in the afternoon can be written as: Your class will contain a method for each version. Inside each method, build a String by concatenating the pieces in the correct sequence. Note that if the hour, minute or second are only one digit in length, your code should include a leading zero in the String that you build and return. Here are the prototypes for each of these public methods: - String tostring() This method creates and returns a String that holds the clock's time in 24-hour format (15:25:00). It does NOT contain A.M. or P.M. in it. - String tostring12() This method creates and returns a String that holds the clock's time in 12-hour format (03:25:00 P.M. ). It will, of course, include A.M. instead of P.M., when appropriate. Here are 2 more public methods to add. Neither is omplicated, but each lets us see, or do, more interesting things vith a given ClockTime: - void advance (int) This method takes a positive integer as input and advances the ClockTime object by that many seconds. Note that if this makes the number of seconds go over 60 , the number of minutes should go up instead. Also, if the number of minutes goes over 60 , the number of hours should go up. If the hours variable goes over 24 , use mod24 on it (as you did in the constructor). Simple if-statements might not be enough for this step; so you'll need either loops or some other trickery... - boolean equals (ClockTime) This method checks to see if the current ClockTime contains the same values as the one sent in the parameter. If so, it returns true, otherwise returns false

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

Step: 3

blur-text-image

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions