Language: JavaYour task is to complete the logic to manage a twenty-four-hour clock (no dates, just time) that tracks
the hours, minutes, and sections, and various operations to adjust the time. The framework for your
clock is in the Time class with the four methods you must complete.
1.) advanceOneSecondâ A user calls this method to advance the clock by one second.
a. When the seconds value reaches 60, it rolls over to zero.
b. When the seconds roll over to zero, the minutes advance.
So 00:00:59 rolls over to 00:01:00.
c. When the minutes reach 60, they roll over and the hours advance.
So 00:59:59 rolls over to 01:00:00.
d. When the hours reach 24, they roll over to zero.
So 23:59:59 rolls over to 00:00:00.
2.) compareTo â The user wants to know if a second time is greater than or less than the time
object called, assuming both are on the same date.
a. Returns -1 if this Time is before otherTime.
b. Returns 0 if this Time is the same as otherTime.
c. Returns 1 if this Time is after otherTime.
3.) add â Adds the hours, minutes, and seconds of another time (the offset) to the current time
object. The time should ârolloverâ if it exceeds the end of a 24 hour period.
4.) subtract â Subtracts the hours, minutes, and seconds of another time (the offset) from
the current time object. The time should âroll backâ if it precedes the beginning of a 24 hour
period.
________________________________________________________________________
package clock;
/**
* Objects of the Time class hold a time value for a
* European-style 24 hour clock.
* The value consists of hours, minutes and seconds.
* The range of the value is 00:00:00 (midnight) to 23:59:59 (one
* second before midnight).
*/
public class Time {
private int hours;
private int minutes;
private int seconds;
/**
* Add one second to the current time.
* When the seconds value reaches 60, it rolls over to zero.
* When the seconds roll over to zero, the minutes advance.
* So 00:00:59 rolls over to 00:01:00.
* When the minutes reach 60, they roll over and the hours advance.
* So 00:59:59 rolls over to 01:00:00.
* When the hours reach 24, they roll over to zero.
* So 23:59:59 rolls over to 00:00:00.
*/
public void advanceOneSecond()
{
}
/**
* Compare this time to otherTime.
* Assumes that both times are in the same day.
* Returns -1 if this Time is before otherTime.
* Returns 0 if this Time is the same as otherTime.
* Returns 1 if this Time is after otherTime.
*/
public int compareTo(Time otherTime)
{
return 0;
}
/**
* Add an offset to this Time.
* Rolls over the hours, minutes and seconds fields when needed.
*/
public void add(Time offset)
{
}
/**
* Subtract an offset from this Time.
* Rolls over (under?) the hours, minutes and seconds fields when needed.
*/
public void subtract(Time offset)
{
}

Answers

Answer 1
Answer:

Using the knowledge in computational language in JAVA  it is possible to write a code that user calls this method to advance the clock by one second. When the seconds value reaches 60, it rolls over to zero.

Writting the code:

public class Time

{

   private int hours;

   private int minutes;

   private int seconds;

   

   public void advanceOneSecond()

   {

      seconds++;

      if(seconds >= 60)

      {

             seconds -= 60;

             minutes++;

      }

      if(minutes >= 60)

      {

             minutes -= 60;

             hours++;

      }

      if(hours >= 24)

             hours -= 24;

   }

   

   public int compareTo(Time otherTime)

   {

      if(hours > otherTime.hours)

             return 1;

     

      else if(hours < otherTime.hours)  

             return -1;

      else

      {

             if(minutes > otherTime.minutes)

                    return 1;

             else if(minutes < otherTime.minutes)

                    return -1;

             else

             {

                    if(seconds > otherTime.seconds)

                           return 1;

                    else if(seconds < otherTime.seconds)

                           return -1;

                    else

                           return 0;

             }

      }

   }

   

   public void add(Time offset)

   {

      seconds += offset.seconds;

      minutes += offset.minutes;

      hours += offset.hours;

      if(seconds >= 60)

      {

             seconds -= 60;

             minutes++;

      }

      if(minutes >= 60)

      {

             minutes -= 60;

             hours++;

      }

      if(hours >= 24)

             hours -= 24;

   }

   

   public void subtract(Time offset)

   {

      if(offset.seconds > seconds)

      {

             minutes--;

             seconds = seconds + 60;

      }

      seconds -= offset.seconds;

      if(offset.minutes > minutes)

      {

             hours--;

             minutes = minutes + 60;

      }

      minutes -= offset.minutes;

      if(offset.hours > hours)

      {

             hours += 24;

      }

      hours -= offset.hours;

   }

}

See more about JAVA at brainly.com/question/18502436

#SPJ1


Related Questions

NEED HELP IMMEDIATELY!! Highlight the upsides and downsides of seeking online help for a technical problems.
It is possible to force the Hardware Simulator to load a built-in version of chip Xxx. This can be done by:
Regarding computer protection, quarantining is defined as ________. Select one: A. placing a found virus in a secure area on the hard drive B. deleting an infected file C. repairing an infected file D. updating your antivirus software
Why is OS important in every data processing system? Please Answer Fast! ​
software that interprets commands from the keyboard and mouse is also known as the? A. desktop B. Operating system C. operating disk D. hard drive

What is the earliest version of the present day Internet?

Answers

Answer:

ARPANET is the earliest version of the present-day Internet.

Explanation:

ARPANET is the type of network that is used before the Internet in the year 1967. It was advanced in the control of U.S ARPA(Advanced Research Projects Agency). After the year of 1980, it was given to the military network for the protection of the data network but after all, it is for the small area network and the Internet is the World Wide network.

Your friend sees an error message during Windows startup about a corrupted bootmgr file. He has another computer with a matching configuration and decides to copy the bootmgr file from the working computer to the computer with the problem. However, your friend is having problems finding the bootmgr file and asks for your help. What is your best response?

Answers

Answer:

He should remove any removable devices from the PC , change the boot device to USB or CD drive and insert the installation disk or a created ISO USB file to install

Explanation:

You text file begins with the following rows. The pattern is a description of the item to be repaired, its color, and the issue. bike, red, flat tire bike, blue, broken chain skate, blue, loose wheel mitt, red, torn lace Your program starts with the following lines. import csv aFile = open("data\broken.txt","r") aReader = csv.reader(aFile) countRed = 0 for item in aReader: When you write code to count the number of times red is the color, what is the index of "red"?

Answers

Answer: the answer is 1

Explanation:

edge 2021

Given an array A of n + m elements. It is know that the first n elements in A are sorted and the last m elements in A are unsorted. Suggest an algorithm (only pseudo code) to sort A in O(mlogm +n) worst case running time complexity. Justify.

Answers

Answer:

Explanation:

We can divide array A into two arrays B , C

B would contain the sorted n elements.

C would contain the unsorted m elements.

Now we can sort C using merge sort with worst time complexity mlogm.

When you will have array C sorted you can concatenate with B and put it back in A.

Create a query that will list all technician names, employee numbers, and year hired in order by year hired (Newest to Oldest).

Answers

Answer:

SELECT TECHNAME, EMPNUM, YEAR FROM EMPLOYEE ORDER BY YEAR DESC

Explanation:

The table definition is not given;

However, I'll make the following assumptions

Table Name:

Employee

Columns:

Technician name will be represented with Techname

Employee number will be represented with Empnum

Year Hired will be represented with Year

Having said that; the sql code is as follows:

SELECT TECHNAME, EMPNUM, YEAR FROM EMPLOYEE ORDER BY YEAR DESC

The newest year hired will be the largest of the years;

Take for instance:

An employee hired in 2020 is new compared to an employee hired in 2019

This implies that the year has to be sorted in descending order to maintain the from newest to oldest.

what are "open source" programming language? Give examples of open source languages. Discuss the pros and cons of open source language.

Answers

Answer:

  The open source is the programming language that basically falls inside the parameters of the protocol of open-source convention. This fundamentally implies the language are not proprietary, with the specific arrangements (contingent upon the open source permit), can be adjusted and based upon in a way that is available to general society.

The python and ruby are the main examples of the open source programming language.

The disadvantage of the open source is that it is not much compatible as compared to all other software. It is not user friendly and easy for using the software.

The advantage of the open source programming is that it is available at low cost and it has high availability.

Other Questions