Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 int getHours(){ String s=new java.util.Date().toString(); int hour= Integer.parseInt(s.substring(11,13)); return hour; } public int getMinutes(){ String s=new java.util.Date().toString(); int minute= Integer.parseInt(s.substring(14,16)); 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 WorldClock extends Clock{ private int offset; public WorldClock(int offset){ this.offset = offset; } public int getHours(){ int hour = (super.getHours() + offset)%24; return hour; } public int getMinutes(){ return super.getMinutes(); } }

///////////////////////////////////////////////////////////////

public class ClockTester { public static void main(String[] args) { Clock clock1 = new Clock(); Clock clock2 = new WorldClock(3); System.out.println("Clock: "+clock1.getTime()); System.out.println("WorldClock: "+clock2.getTime());

} }

Thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

U11 Informing Industry: Publicizing Contract Actions 317

Answered: 1 week ago