CMPS271 Project 10 Classes Suppose you are given a class nam

CMPS271 Project 10 Classes Suppose you are given a class named clockTime with the following contents: A Clock Time object represents an hour:minute time during the day or night, such as 10:45 AM or 6:27 PM. public class ClockTime private int hour private int minute; private String amPm: Constructs a new time for the given hour/minute public clockTime (int h, int m, String ap) returns the field values public int getii our public int getMinute Public String getAmPm returns a String for this time: for example, \"6:27 PM\" public String toString Write an instance method advance that will be placed inside the clockTine class. The method accepts a number of minutes as its parameter and moves your object forward in time by that amount of minutes. The minutes passed could be anynon-negative number, even a large number such as 500 or 1000000. Ifnecessary. your object might wrap into the next hour or day.or it might wrap from the moming (AM\") to the evening (PM )or vice versa. (AClockTime object doesn\'t care about what day it is; if you advance by l minute from Il 59 PM, it becomes 12:00 AM.) For example, the following calls would produce the following results: Clock Time time nese clockTime 16, 27, \"PM\"): time. advance (1): 6:2 PM time. advance (30) 6:58 PM time-advance (5): 7:03 PM time advance (60) 8:03 PM time advance (128) 10:11 PM time advance (180); 1/ 1:11 AM time. advance (1440 1:11 AM (1 day later time-advance (21075) 4:26 PM 12 weeks later) Write an instance method istorkTime that will be placed inside the clockTine class. The method returns true if the object is a time during the \"work day\" from 9:00 AM -5:00 PM inclusive; otherwise false. For example, the following objects would return the following results ifthe method were called: 45 false ClockTime to new ClockTine (12

Solution

   public void advance(int m)
   {
       // as long as there are m are available to be added
       while(m>0)
       {
           // if minutes is 59 we need to increase the hour and minutes will be 0
           if(minute==59)
           {
               hour++;
               minute = 0;
           }
           // simple case of increasing minutes
           else
           {
               minute++;
           }
          
           // if hour has become 12 and there is 0 as mins, then we need to change AM to PM and vice versa
           if(hour == 12 && minute == 0)
           {
               //System.out.print(day);
               if(day == \"AM\")
                   day = \"PM\";
               else
                   day = \"AM\";
           }
          
           // if hours becomes 13, it should be 1
           if(hour==13)
           {
               hour = 1;
           }
          
           // everytime reducing m by 1
           m--;
       }
   }

   public boolean isWorkTime()
   {
       // hours are less than 9 AM then it is false
       if(day ==\"AM\" && hour<9)
           return false;
       // greater than 5 PM
       if(day==\"PM\" && hour >=5 && minute > 0)
           return false;
       // if not returning true
       return true;
   }

 CMPS271 Project 10 Classes Suppose you are given a class named clockTime with the following contents: A Clock Time object represents an hour:minute time during

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site