Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Is there anyway to do this program a different way without using Intger.parseInt like so public class Clock { public int getHours(){ String s=new java.util.Date().toString();

Is there anyway to do this program a different way without using Intger.parseInt like so

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;

}

}

############ WorldClock.java ###### public class WorldClock extends Clock{ private int offset; public WorldClock(int offset) { this.offset = offset; } public int getHours(){ String s=new java.util.Date().toString(); int hour= Integer.parseInt(s.substring(11,13)); hour = (hour + offset)%24; return hour; } public int getMinutes(){ String s=new java.util.Date().toString(); int minute= Integer.parseInt(s.substring(14,16)); return minute; } } JAVA OOP

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

1. Explain how technology has changed the learning environment.

Answered: 1 week ago