Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a class Clock with getHours and getMinutes methods to return the current time. (Use new java.util.Date.toString() and extract the time from that string.) Also

Implement a class Clock with getHours and getMinutes methods to return the current time. (Use new java.util.Date.toString() and extract the time from that string.) Also provide a getTime method that returns a string with the hours and minutes by calling your getHours and getMinutes methods. Provide a subclass WorldClock whose constructor accepts a time offset. For example, from California, a new WorldClock(3) will show the time in New York, three time zones ahead. Your WorldClock subclass should override some methods from Clock, but should not override getTime.

Hint: How to extract integer hour and minute from Date() object:

public class Clock { private int hour,minute; public Clock(){ String s=new java.util.Date().toString(); hour=Integer.parseInt(s.substring(11,13)); minute=Integer.parseInt(s.substring(14,16)); } public int getMinute(){ return minute; } public int getHour(){ return hour; } public static void main(String[] args){ Clock c=new Clock(); System.out.printf("%02d:%02d ",c.getHour(),c.getMinute()); } }

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 Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Discuss five types of employee training.

Answered: 1 week ago