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]
3 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]3 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
A user profile has a login hour restrictions set to. Monday through A user profile has login hour restrictions set to. Monday th
Savatey [412]

Answer:

D

Explanation:

The user will be logged out and any unsaved work-in-progress will be lost.

In a computer program if a user has login hour restrictions this means that such a user will not be able to continue with his/her work when its past the restriction time.

Therefore at 5.01 pm the user will be logged out and any unsaved work-in-progress will be lost.

8 0
2 years ago
Which website domains are most credible?
Leokris [45]

Credible websites usually end in the domain name .org or .edu

3 0
3 years ago
Read 2 more answers
Type the correct answer in the box. Spell all words correctly. Complete the sentence below that describes an open standard in vi
Anika [276]

Answer:

digital

Explanation:

Today, video production has become digital, and all playback devices work on the open standard known as digital technology.​

8 0
3 years ago
When microsoft released word for windows, wordperfect had about 80 percent of the word processing market. microsoft donated free
irina1246 [14]

When Microsoft donated copies of Word program to colleges and universities, the company Microsoft is using a Marketing Strategy in promoting the product. A good promotion will help the product to be known and by words of mouth it will basically promote the product and the users will definitely give comments on how the product performs.

7 0
3 years ago
Linguist study_____
-Dominant- [34]
That's B.

Linguist love all kinds of studies of languages culture writing etc.
6 0
3 years ago
Other questions:
  • 1.
    13·1 answer
  • All of the following are examples of what rigorous coursework in high school might mean except: A) added reading assignments. B)
    7·2 answers
  • Write a MIPS assembly language program that
    11·1 answer
  • I was logging into my origin account and this popped up. I can’t seem to click the NEXT button at the bottom. The blank spaces s
    7·2 answers
  • Define the following term. data, database, DBMS, database system, data- base catalog, program-data independence, user wen', DBA,
    12·1 answer
  • Create a function called is_list_empty that takes a single argument of type list. Your function should return True if the list i
    7·1 answer
  • What is the difference between mutex lock and race condition​
    6·1 answer
  • ¿por que hay peligros en internet?
    11·1 answer
  • Web résumés allow you to include extra graphics and images that you would not include in a traditional résumé. please select the
    9·1 answer
  • To create a datetime object for the current date and time, you can use theGroup of answer choicestoday() method of the date clas
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!