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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started