Write a program to implement a class Clock whose getHours and getMinutes methods return the…

Write a program to implement a class Clock whose getHours and getMinutes methods return the current time at your location. Also include a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutes methods. Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you live in California, a new WorldClock(3) should show the time in NewYork, three time zones ahead.

Include an Alarm feature in the Clock class. When setAlarm(hours, minutes), the clock stores the alarm. When you call getTime and the alarm time has been reached or exceeded, return the time followed by the string “Alarm” and clear the alarm.

I have provided a ClockDemo class which can be used to test the program. Do not change it when you submit it. I provided a Clock class which has shells for all the methods which you should fill in. The same applies to the WorldClock class.

This are the following zip files

Clock.java

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
* Part I: Implement a class Clock whose getHours, getMinutes and
* getTime methods return the current time at your location.
* Return the time as a string.
*
* There are two ways to retrieve the current time as a String:
*
* 1) Before Java 8 use new Date().toString()
* 2) With Java 8, you can use 3 classes in the java.time package:
* Instant, LocalDateTime and ZoneId. Here’s how you do it:
* String timeString = LocalDateTime.ofInstant(Instant.now(),
* ZoneId.systemDefault()).toString()
*
* With either method, you’ll need to extract the hours and
* minutes as a substring.
*
*
* Add an alarm feature to the Clock class.
* 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 followed
* by the string “Alarm” and clear the alarm.
*/
public class Clock
{
. . .

/**
* Sets the alarm.
* @param hours hours for alarm
* @param minutes minutes for alarm
*/
public void setAlarm(int hours, int minutes)
{
// Complete this method
. . .

}

/**
* gets current time composed of hours and minutes
* @return time in string;
*/
public String getTime()
{
// Complete this method
. . .

}

/**
* gets hours
* @return hours of current time in string
*/
public String getHours()
{
// Complete this method
. . .

}

/**
* gets minutes
* @return hours of current time in string
*/
public String getMinutes()
{
// Complete this method
. . .

}

/**
Returns the current Date and Time as a String.
*/
private String currentTime()
{
return LocalDateTime.ofInstant(Instant.now(),
ZoneId.systemDefault()).toString();
}
}

ClockDemo.java

/**
* Tests the alarm feature of the Clock class.
*/
public class ClockDemo
{
public static void main(String[] args)
{
//test WorldClock
System.out.println(“”);
System.out.println(“Testing WorldClock class”);
int offset = 3;
System.out.println(“Offset: ” + offset);
WorldClock wclock = new WorldClock(offset);
System.out.println(“Hours: ” + wclock.getHours());
System.out.println(“Minutes: ” + wclock.getMinutes());
System.out.println(“Time: ” + wclock.getTime());

//test the AlarmClock
System.out.println(“”);
System.out.println(“Testing AlarmClock”);
Clock clock = new Clock();
System.out.println(“Hours:” + clock.getHours());
System.out.println(“Minutes: ” + clock.getMinutes());
System.out.println(“Time: ” + clock.getTime());

//test AlarmClock with alarm
int h = Integer.parseInt(clock.getHours());
int m = Integer.parseInt(clock.getMinutes());

clock.setAlarm(h, m – 1);
System.out.println(“Time:” + clock.getTime());
//test to see if the Alarm is cleared.
System.out.println(“Time: ” + clock.getTime());
}
}

WorldClock.Java

/**
* PART II.
* Provide a subclass of Clock namded WorldClock whose constructor
* accepts a time offset. For example, if you live in California,
* a new WorldClock(3) should show the time in New York, three
* time zones ahead. You should not override getTime.
*/
public class WorldClock extends Clock
{
// Your work goes here
. . .

}

Please if you can use Java that would be great. Thank you!

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
error: Content is protected !!