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
IgorC [24]
3 years ago
8

Modify class Time2 of fig 8.5, (which is split into four pictures) to include a tick method that increments the time stored in a

Time2 object by one second. Provide method incrementMinute to increment the minute by one and method incrementHour to increment the hour by one. Write a program that tests the tick method, the incrementMinute method and the incrementHour method to ensure that they work correctly. Be sure to test the following cases:
a: incrementing into the next minute
b:incrementing into the next hour
c:incrementing into the next day(ie. 11:59:59 PM to 12:00:00AM
Computers and Technology
1 answer:
ArbitrLikvidat [17]3 years ago
4 0

Explanation:

Complete Program:

NOTE:   The newly added statements are highlighted in bold.

// File: Time2.java

public class Time2

{

private int hour; // 0 - 23

private int minute; // 0 - 59

private int second; // 0 - 59

public Time2()

{

 this(0, 0, 0);

}

public Time2(int hour)

{

 this(hour, 0, 0);

}

public Time2(int hour, int minute)

{

 this(hour, minute, 0);

}

public Time2(int hour, int minute, int second)

{

 if(hour < 0 || hour >= 24)

  throw new IllegalArgumentException("hour must be 0-23");

 if(minute < 0 || minute >= 60)

  throw new IllegalArgumentException("minute must be 0-59");

 if(second < 0 || second >= 60)

  throw new IllegalArgumentException("second must be 0-59");

 this.hour = hour;

 this.minute = minute;

 this.second = second;

}

public Time2(Time2 time)

{

 this(time.getHour(), time.getMinute(), time.getSecond());

}

public void setTime(int hour, int minute, int second)

{

 if(hour < 0 || hour >= 24)

  throw new IllegalArgumentException("hour must be 0-23");

 if(minute < 0 || minute >= 60)

  throw new IllegalArgumentException("minute must be 0-59");

 if(second < 0 || second >= 60)

  throw new IllegalArgumentException("second must be 0-59");

 this.hour = hour;

 this.minute = minute;

 this.second = second;

}

public void setHour(int hour)

{

 if(hour < 0 || hour >= 24)

  throw new IllegalArgumentException("hour must be 0-23");

 

 this.hour = hour;

}

public void setMinute(int minute)

{

 if(minute < 0 || minute >= 60)

  throw new IllegalArgumentException("minute must be 0-59");

 

 this.minute = minute;

}

public void setSecond(int second)

{

 if(second < 0 || second >= 60)

  throw new IllegalArgumentException("second must be 0-59");

 

 this.second = second;

}

public int getHour()

{

 return hour;

}

public int getMinute()

{

 return minute;

}

public int getSecond()

{

 return second;

}

public String toUniversalString()

{

 return String.format("%02d:%02d:%02d", getHour(), getMinute(),

   getSecond());

}

public String toString()

{

 return String.format("%d:%02d:%02d %s",

   ((getHour() == 0 || getHour() == 12) ? 12 : getHour() % 12),

   getMinute(), getSecond(), (getHour() < 12 ? "AM" : "PM"));

}

// increment second

public void tick()

{

 if(second < 23)

 {

  second++;

 }

 else if(minute < 59)

 {

  second = 0;

  minute++;

 }

 else if(hour < 23)

 {

  second = 0;

  minute = 0;

  hour++;

 }

 else

 {

  second = 0;

  minute = 0;

  hour = 0;

 }    

}

// increment minute

public void incrementMinute()

{

 if(minute < 59)

 {

  minute++;

 }

 else if(hour < 23)

 {

  minute = 0;

  hour++;

 }

 else

 {

  minute = 0;

  hour = 0;

 }    

}

public void incrementHour()

{

 if(hour < 23)

 {

  hour++;

 }

 else

 {

  hour = 0;

 }    

}

}

------------------------------------------------------------------------------------------------------------

// File: Time2Test.java

public class Time2Test

{

  public static void main( String args[] )

  {      

     Time2 t = new Time2(22, 58, 59);

     System.out.println("Starting time: ");

     System.out.println("Time in 24 hours format: " + t.toUniversalString());

     System.out.println("Time in 12 hours format: " + t);

     System.out.println();

     

     t.incrementMinute();

     System.out.println("After incrementing one minute: ");

     System.out.println("Time in 24 hours format: " + t.toUniversalString());

     System.out.println("Time in 12 hours format: " + t);

     System.out.println();

     

     t.incrementHour();

     System.out.println("After incrementing one hour: ");

     System.out.println("Time in 24 hours format: " + t.toUniversalString());

     System.out.println("Time in 12 hours format: " + t);

     System.out.println();

     

     t.tick();

     System.out.println("After incrementing one second: ");

     System.out.println("Time in 24 hours format: " + t.toUniversalString());

     System.out.println("Time in 12 hours format: " + t);    

     System.out.println();

  }

}

You might be interested in
Write a recursive function is_pow2(n) that returns True if the positive integer n is an integer power of 2, and False otherwise.
bezimeni [28]

Answer:

In Python:

def is_power(n):

   if n > 2:

       n = n/2

       return is_power(n)

   elif n == 2:

       return True

   else:

       return False

Explanation:

This defines the function

def is_power(n):

If n is greater than 0

   if n > 2:

Divide n by 2

       n = n/2

Call the function

       return is_power(n)

If n equals 2

   elif n == 2:

Return True

       return True

If n is less than 2

   else:

Then, return false

       return False

8 0
2 years ago
The term packet is used fairly generically to refer to protocol data unit (PDU). There are PDU equivalent names in the different
Westkost [7]

Answer:

Bits

Explanation:

The protocol data unit is the representative unit of data in the OSI layer of a network. The OSI system has seven layers.

The physical layer is the first layer of the system and the protocol data unit is represented as bits of data.

Note that the term packet is the PDU for data in the network layer of the OSI network system.

4 0
2 years ago
Jordan has been asked to help his company find a way to allow all the workers to log on to computers securely but without using
lana66690 [7]

Answer:

Webcam

Explanation:

A webcam is mainly used for taking images or videos from the computer. the webcam is a combination of two basic words i.e. web and camera. webcam can be connected to any computer via USB. It can be mounted on the desktop and sometimes it comes inbuilt on the laptops.

A webcam is also used for face recognition function to login to a computer system.

so according to the scenario, the most appropriate answer is a webcam.

6 0
3 years ago
What is inputted into a computer system?
Anna [14]

Answer:

Hey mate.....

Explanation:

This is ur answer.....

<em>Input refers to any information, or data, that is sent to a computer for processing. Input is often sent to the computer from a device such as a keyboard, mouse, or other input device. Putting it simple, input is the act of entering data into a computer.</em>

<em />

Hope it helps!

Mark me brainliest....

FOLLOW ME!!!! :)

4 0
2 years ago
What important feature was introduced alongside The Fisherman?​
Bad White [126]

Duplicate? brainly.com/question/13086598

5 0
2 years ago
Read 2 more answers
Other questions:
  • Which of the following is a template definition?
    5·1 answer
  • What are some good websites i can use to test my knowledge?
    11·2 answers
  • Narrowband Satellite Communications supports ______________ data rates for both mobile and fixed users by providing access on a
    8·1 answer
  • Count input length without spaces, periods, or commas Given a line of text as input, output the number of characters excluding s
    8·2 answers
  • Write a program in C++ or C that includes two different enumeration types and has a significant number of operations using the e
    15·1 answer
  • What is GIGO ?<br>plz answer me​
    7·1 answer
  • Which term describes a visual object such as a picture, a table, or a text box?
    14·2 answers
  • What is the name of the process of checking the client's production environment to ensure software and hardware compatibility wi
    5·2 answers
  • 1) SuperFetch is a memory-management technique that a) determines the type of RAM your system requires. b) makes the boot-up tim
    7·1 answer
  • Launa is reviewing several videos from her friends doing the latest dance challenge before they are published on their own
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!