Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
okay, I a m very new to Java and not so great at it, though I don't think I'm that bad either,
Anyway, I have to implement a method in a clock class. Every time I try to figure a way to implement the elapsedTime method I get an error message--"inner classes cannot have static declarations"--or--"Cannot find symbol: method timeElapsed(Clock, Clock) location: class TC". when I create a class TC I get the error, "inner classes cannot have static declarations" when I remove static from my timeElapsed method the error is "non-static method cannot be referenced from static context".
on top of this I'm really not sure how to even code for this method I'm trying to create(method timeElapsed)--you see the time elapsed should equal the difference between c1(clock 1) and c2(clock 2). PLease, Pleasee, Please help me!
Here is my code so far:
public class TimeCalculator {
private int days;
private int hours;
private int minutes;
int d= days;
int h=hours;
int m = minutes;
public static void timeElapsed(Clock start, Clock end) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public String toString(){
String a = days +"," + hours + minutes;
return a;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
TimeCalculator Tc = new TimeCalculator();
Clock c1 = new Clock("Wednesday", 10, 00);
Clock c2 = new Clock("Friday", 19, 30);
System.out.println("Start Time:" + c1);
System.out.println("End time:" + c2);
TC.timeElapsed(c1, c2);
System.out.println("Elapsed Time:" + Tc);
}
}
class Clock{
private int day_of_week;
private long hours;
private long minutes;
private String [] dow = {"Sunday, Monday, Tuesday, Wednesday, Thursday, Friday"};
final long WEEKMINUTES = 7*24*60;
final long DAYMINUTES =24*60;
final long HOURMINUTES =60;
public Clock(String s, int h, int m){
hours=h;
minutes=m;
day_of_week=1;
for (int i =0; i