Question: Please answer in Java The goal output is given below: 1:00:00 1:00:00 AM 19:00:30 7:00:30 PM Objective To get more practice writing classes with constructors

Please answer in Java

Please answer in Java The goal output is given below: 1:00:00 1:00:00AM 19:00:30 7:00:30 PM Objective To get more practice writing classes withconstructors and methods in Java For this lab, you will create aclass called Time that will allow us to store and work with

The goal output is given below: 1:00:00 1:00:00 AM 19:00:30 7:00:30 PM Objective To get more practice writing classes with constructors and methods in Java For this lab, you will create a class called Time that will allow us to store and work with time objects. Your class should contain the following: Private instance variables for storing the hours, minutes, and seconds. The hours will be in 24-hour format (e.g. 17 is 5:00 PM). A default constructor that sets the time to midnight. A constructor that takes hours, minutes and seconds as parameters. A method called increment" that takes a number of seconds as a parameter, and increases the time by that many seconds (you may have to increase the hour and minute as well). A method called "print" that takes one parameter, a boolean called military". If military is true, you should print the time in 24-hour format, otherwise print in the 12-hour AM/PM format. You are just writing the Time class for this lab. To test your class, you can use this main class: public class Main { public static void main(String args[]) { Time t1 = new Time(); // midnight Time t2 = new Time (17, 30, 0); // 5:30 PM // add an hour onto t1, then print it in both formats t1.increment(3600); t1.print(true); t1.print(false); A method called "print" that takes one parameter, a boolean called military". If military is true, you should print the time in 24-hour format, otherwise print in the 12-hour AM/PM format. You are just writing the Time class for this lab. To test your class, you can use this main class: public class Main { public static void main(String args[]) { Time t1 = new Time(); // midnight Time t2 = new Time(17, 30, 0); // 5:30 PM // add an hour onto t1, then print it in both formats t1.increment(3600); t1.print(true); t1.print(false); // add an hour and a half, and 30 seconds onto t2 t2. increment(5430); // print t2 in both formats t2.print(true); t2.print(false); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!