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
Why can't you test a program for run-time errors when it has compile-time (syntax) errors
Leno4ka [110]

Answer:

your computer will not allow it

Explanation:

because it is not one of the main dyonostics

6 0
3 years ago
Suppose a worker needs to process 100 items. the time to process each item is exponentially distributed with a mean of 2 minutes
stiks02 [169]
Suppose a worker nneeds to process100 items
7 0
3 years ago
Images from your .............. can be copied and pasted in a folder on your computer ​
Alenkasestr [34]

I think the answer is document

7 0
3 years ago
Do you think that the TV set has outlived its utility as a household appliance? Research how convergence with internet technolog
kherson [118]

Answer:

What is Computer? & technology

7 0
2 years ago
TRUE OR FALSE - SQL language is used to query data in a Relational Database?
Gelneren [198K]

Answer:

Yes I agree with the other person who answered that

5 0
3 years ago
Other questions:
  • Dfd symbols are referenced by using all ____ letters for the symbol name.
    9·1 answer
  • The main characteristic of ____ is that its source code is published with the software.
    7·1 answer
  • After a chart has been inserted and formatted, is it possible to change the data range it refers to or to add new rows of data?
    14·1 answer
  • Are computer virus and human virus the same​
    6·1 answer
  • What is the most likely result of making a plan for life after high school
    14·1 answer
  • The acronym pies is used to describe improvised explosive devices (ied) components. pies stands for:
    13·2 answers
  • 14. Which of the following information about the ESRT T-teen rating rating is FALSE?
    15·1 answer
  • What will the following code display? int numbers[4] = { 99, 87 }; cout &lt;&lt; numbers[3] &lt;&lt; endl; a. 87 b.0 d. 34. What
    12·1 answer
  • During system testing, developers test the program in an environment that is very similar to how the program will eventually be
    11·2 answers
  • Addition substraction and multiplication are examples of the set of _____ provided by the int data type
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!