Question
This is what I need to do.... Add an alarm feature to the Clock class from Assignment #17. When setAlarm(hours, minutes) is called, the clock
This is what I need to do.... Add an alarm feature to the Clock class from Assignment #17. When setAlarm(hours, minutes) is called, the clock stores the alarm. When you call getTime, and the alarm time has been reached or exceeded, return the time concatenated with the string "Alarm!" and then clear the alarm. Also add a toString method to return the current time, and if an alarm is set, return the alarm time also.
This is my code
public class Clock{ public Clock() { } public int getHours(){ int hour = new java.util.Date().getHours(); return hour; } public int getMinutes(){ int minute = new java.util.Date().getMinutes(); return minute; } public String getTime(){ String date = ""; String hr = Integer.toString(getHours()); if (hr.length() == 1) date = date + "0" + hr + ":"; else date = date + hr + ":"; String min = Integer.toString(getMinutes()); if (min.length() == 1) date = date + "0" + min; else date = date + min; return date; } //////////////////////////////////////////////////////////
public class ClockTester { public static void main(String[] args) { Clock c1 = new Clock(); System.out.println("Clock: "+c1.getTime()); } }
JAVA OOP thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started