Java Program Develop Data Type Time Day Provide Client Methods Return Current Hour Minute Q37122136

JAVA program

Develop a data type for the time of the day. Provide clientmethods that return the current hour, minute, and second, as wellas toString() and compareTo() methods. Develop two implementations:one that keeps the time as a single int value (number of secondssince midnight) and another that keeps three int values, one eachfor second, minutes, and hours.


Answer


//Java program

class Clock1{
   private int second;
   public Clock1(int sec) {
       second = sec;
   }
   public void setSecond(int second) {
       this.second = second;
   }
   public int getHour() {
       return second/3600;
   }
   public int getMinute() {
       int Minute = second%3600;
      

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.