1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vivado [14]
2 years ago
15

Create a class called Clock to represent a Clock. It should have three private instance variables: An int for the hours, an int

for the minutes, and an int for the seconds. The class should include a threeargument constructor and get and set methods for each instance variable. Override the method toString which should return the Clock information in the same format as the input file (See below). Read the information about a Clock from a file that will be given to you on Blackboard, parse out the three pieces of information for the Clock using a StringTokenizer, instantiate the Clock and store the Clock object in two different arrays (one of these arrays will be sorted in a later step). Once the file has been read and the arrays have been filled, sort one of the arrays by hours using Selection Sort. Display the contents of the arrays in a GUI that has a GridLayout with one row and two columns. The left column should display the Clocks in the order read from the file, and the right column should display the Clocks in sorted order.
Computers and Technology
1 answer:
Anvisha [2.4K]2 years ago
3 0

Answer:

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, int minutes, int seconds)

{

 setTime (hours, minutes, seconds);

}

public void setTime (int hours, int minutes, int seconds)

{

 if (0 <= hours && hours < 24)

      hr = hours;

 else

      hr = 0;

 

 if (0 <= minutes && minutes < 60)

      min = minutes;

 else

      min = 0;

 

 if (0 <= seconds && seconds < 60)

      sec = seconds;

 else

      sec = 0;

}

 

 //Method to return the hours

public int getHours ( )

{

 return hr;

}

 //Method to return the minutes

public int getMinutes ( )

{

 return min;

}

 //Method to return the seconds

public int getSeconds ( )

{

 return sec;

}

public void printTime ( )

{

 if (hr < 10)

      System.out.print ("0");

 System.out.print (hr + ":");

 if (min < 10)

      System.out.print ("0");

 System.out.print (min + ":");

 if (sec < 10)

      System.out.print ("0");

 System.out.print (sec);

}

 

 //The time is incremented by one second

 //If the before-increment time is 23:59:59, the time

 //is reset to 00:00:00

public void incrementSeconds ( )

{

 sec++;

 

 if (sec > 59)

 {

  sec = 0;

  incrementMinutes ( );  //increment minutes

 }

}

 ///The time is incremented by one minute

 //If the before-increment time is 23:59:53, the time

 //is reset to 00:00:53

public void incrementMinutes ( )

{

 min++;

 

if (min > 59)

 {

  min = 0;

  incrementHours ( );  //increment hours

 }

}

public void incrementHours ( )

{

 hr++;

 

 if (hr > 23)

     hr = 0;

}

public boolean equals (Clock otherClock)

{

 return (hr == otherClock.hr

  && min == otherClock.min

   && sec == otherClock.sec);

}

}

You might be interested in
You write a short story, but you want to make sure your work is protected before you post it online. What should you do to help
Mars2501 [29]
Make sure you but no copyright, author, and date of publication, that may help.
8 0
3 years ago
Identify the careers that require a college degree
Vikentia [17]
Doctor or teacher or an engineer

8 0
2 years ago
What is the troubleshooting process?
sattari [20]
<span>It is a logical, systematic search for the source of a problem in order to solve it, and make the product or process operational again.Troubleshooting is needed to identify the symptoms. ...Troubleshooting is the process of isolating the specific cause or causes of the symptom.</span>
6 0
2 years ago
(Exhibit: Production Possibilities Curves 2) Assume that a nation is operating on production possibilities curve CD. Economic gr
Alex

Answer:

b. shift from curve CD to curve EF.

Required Details of the Question:

The image of the curve required to answer the question has been attached.

Explanation:

A production possibilities curve shows various combinations of the amounts of two goods( in this case capital and consumer goods) which can be produced within the given resources and a graphical representation showing all the possible options of output for the two products that can be produced using all factors of production.

Now the growth of an economy is best illustrated in the image by the shift from curve CD to curve EF, this means that as the nation's production capacity increases, its production possibilities curve shift outward showing an increase in production of both goods.

3 0
3 years ago
1. Data in a smart card can be erased
Ostrovityanka [42]

Answer:

false

true

false

true

true

5 0
3 years ago
Read 2 more answers
Other questions:
  • Mass production usually uses an _______________ ____________ or production line technique.
    7·1 answer
  • Disconnecting or making the equipment safe involves the removal of all energy sources and is known as _____________. A) Isolatio
    8·2 answers
  • How long does it take a letter to arrive?
    9·1 answer
  • While doing online research you enter this keyword search with a truncation character: man* Which of the following would not be
    15·1 answer
  • There is a simple pattern for derermining if a binary number is odd. What is it and why does this pattern occur?
    8·1 answer
  • Să se determine valoarea sumei: l+2+3+…+n pentru un n număr natural citit de la tastatură. Sa se scrie un algoritm care calculea
    13·1 answer
  • Write a function endpoints that takes a list of numbers (eg. [5, 10, 15, 20, 25]) and returns a new list of only the first and l
    15·1 answer
  • Unconformities develop when new sedimentary layers accumulate atop old, eroded layers, resulting in a geologic hiatus. Which of
    9·1 answer
  • Buying a home security system is an example of protecting your home against________.
    5·1 answer
  • Why is computer economics important?​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!