Question

Java Time Class Class declarations are one of the ways of defining new types in Java....

Java Time Class

Class declarations are one of the ways of defining new types in Java. we will create two classes that both represent time values for a 24 hours period. The valid operations are as follows.

int getHours(): returns the number of hours

int getMinutes(): returns the number of minutes

int getSeconds(): returns the number of seconds

String toString(): returns a String representation

boolean equals(Time other): returns true if and only if other designates an object that has the same content as this one

void increase(): increases this time by one second

1 Time1

Declare a class Time1

Declare a constructor initializing values of three instance variables i.e. hours, minutes and seconds. Knowing that the instance variables of the class Time1 has been declared to be private.

getters: implement the access methods that return the value of hours, minutes and seconds respectively

Create the following two class methods: void increase(): increment the time by one seconds and print them. boolean equals(Time1 other): returns true if and only if other designates an object that has the same content as this one

2 Time2

Let’s consider an alternative way of representing time values. Create a new class called Time2.

Inheritance: Class Time2 inherits Time1 and add another instance variable millisecond and initialize it along with instance variables of Time1 using constructor

Override method boolean equals(Time other) of Time1 as now it includes another instance variable i.e. milliseconds.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Java Time Class Class declarations are one of the ways of defining new types in Java....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • This is a Java programming assignment and I want help with the Time class. See below...

    This is a Java programming assignment and I want help with the Time class. See below for assignment details: For this question you must write a java class called Time and a client class called TimeClient. The partial Time class is given below. (For this assignment, you will have to submit 2 .java files: one for the Time class and the other one for the TimeClient class and 2 .class files associated with these .java files. So in total you...

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • [Java] We have learned the class Clock, which was designed to implement the time of day...

    [Java] We have learned the class Clock, which was designed to implement the time of day in a program. Certain application in addition to hours, minutes, and seconds might require you to store the time zone. Please do the following: Derive the class ExtClock from the class Clock by adding a data member to store the time zone. Add necessary methods and constructors to make the class functional. Also write the definitions of the methods and constructors. Write a test...

  • Need help with this java code supposed to be a military time clock, but I need...

    Need help with this java code supposed to be a military time clock, but I need help creating the driver to test and run the clock. I also need help making the clock dynamic. public class Clock { private int hr; //store hours private int min; //store minutes private int sec; //store seconds public Clock () { setTime (0, 0, 0); } public Clock (int hours, intminutes, int seconds) { setTime (hours, minutes, seconds); } public void setTime (int hours,int...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • java problem here is the combination class class Combination {    int first,second,third, fourth;    public...

    java problem here is the combination class class Combination {    int first,second,third, fourth;    public Combination(int first, int second, int third,int fourth)    {        this.first=first;        this.second=second;        this.third=third;        this.fourth=fourth;    }    public boolean equals(Combination other)    {               if ((this.first==other.first) && (this.second==other.second) && (this.third==other.third) && (this.fourth==other.fourth))            return true;        else            return false;    }    public String toString()    {   ...

  • JAVA. Create an application that uses a "PriorityQueue" to perform the following Uses the constructor that rece...

    JAVA. Create an application that uses a "PriorityQueue" to perform the following Uses the constructor that receives a "Comparator" object as an argument Stores 5 "Time1" objects using the "Time1" class shown in Fig. 8.1 on page 331. The class must be modified to implement the "Comparator" interface Displays the "Universal Time" in priority order Note: To determine the ordering when implementing the "Comparator" interface, convert the time into seconds (i.e., hours * 3600 + minutes * 60 + seconds),...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • JAVA PROGRAM. Write a program to implement a class Clock whose getHours and getMinutes methods return the current time a...

    JAVA PROGRAM. Write a program to implement a class Clock whose getHours and getMinutes methods return the current time at your location. Also include a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutes methods. Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you livein California, a new WorldCLock(3) should show the time in NewYork, three time zones ahead. Include an Alarm feature in the Clock class....

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT