Need help with this java code supposed to be a military time clock, but I need help creating the driver to test and run the clock. I also need help making the clock dynamic.
If you have any doubts, please give me comment...
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);
}
}
public class ClockDriver{
public static void main(String[] args) {
Clock clock = new Clock();
clock.setTime(3, 15, 20);
clock.printTime();
System.out.println();
clock.incrementHours();
clock.incrementSeconds();
clock.printTime();
System.out.println();
clock.incrementMinutes();
clock.printTime();
System.out.println();
Clock otherClock = new Clock(4, 16, 21);
System.out.println(clock.equals(otherClock));
otherClock.incrementMinutes();
System.out.println(clock.equals(otherClock));
}
}
Need help with this java code supposed to be a military time clock, but I need...
[Java] We have learned the class Clock, which was designed to implement the time of day in a program. Certain application in addition to hours, minutes, and seconds might require you to store the time zone. Please do the following: Derive the class ExtClock from the class Clock by adding a data member to store the time zone. Add necessary methods and constructors to make the class functional. Also write the definitions of the methods and constructors. Write a test...
Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...
I need help displaying two zeroes in hours:minutes:seconds. In Java. I need some help for the time to display correctly. I want it to display double zeroes. 06:00:00 and 12:00:00. public class Clock { String name; static int uid=100; int id; int hr; int min; int sec; public Clock() { this.name="Default"; this.id=uid; this.hr=00; this.min=00; this.sec=00; uid++; } public Clock(String name, int hr, int min, int sec) { if (hr<=24 && min <=60 && sec <=60) { this.hr = hr; this.min...
This is a Java programming assignment and I want help with the Time class. See below for assignment details: For this question you must write a java class called Time and a client class called TimeClient. The partial Time class is given below. (For this assignment, you will have to submit 2 .java files: one for the Time class and the other one for the TimeClient class and 2 .class files associated with these .java files. So in total you...
Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...
Can someone please help me with the following java assignment. So in this assignment you will begin with the starterProject I provide and then add to it. I am also asking that before you begin you really look at the starterProject because this is the object-oriented basics. The starterProject is the exact same as the ClassClockExample.zip in Module 5. I’ve also done this using a clock because it is something that you already know how it works. Remember that OOD and OOP is...
need help with this JAVA lab, the starting code for the lab is below. directions: The Clock class has fields to store the hours, minutes and meridian (a.m. or p.m.) of the clock. This class also has a method that compares two Clock instances and returns the one that is set to earlier in the day. The blahblahblah class has a method to get the hours, minutes and meridian from the user. Then a main method in that class creates...
HI C PROGRAMMING COULD YOU,, Rewrite the program to have it display the time on the second line of the display, using the HH:MM:SS format. Use the 24-hour format for the hours, in other words, have the time go from 00:00:00 to 23:59:59. #include<LiquidCrystal.h> LiquidCrystal LcdDriver(11, 9, 5, 6, 7, 8); int minutes = 27; //These global integers keep the value of the clock int sec = 10; int hr = 10; const long interval = 1000; //This interval is...
D Question 6 4 pts Figure 1: clock Type |-hr: int -min: int -sec; int setTime (int, int, int): void get Time (inte, int&, int&) const: void printTime() const: void increment seconds(): int +incrementMinutes(): int +increment Hours(): int -equalTime (const clockType.) const: bool Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? none zero two three D Question 4 4 pts Consider the following class...
I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...