Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!