I'm having an issue getting the variables in the constructors to show up in my output in my main method. I can get the program to work just using methods, however, the problem arises when using constructors. Any help or tip in the right direction would be great!
public class Time {
public static void main (String[] args) {
TimeCalculations time1 = new TimeCalculations();
System.out.println(time1.getCurrentTime());
System.out.println(time1.getElaspedTime());
public static long input() {
Scanner input = new Scanner(System.in);
System.out.println("Enter a time");
return TimeCalculations.elaspedTime = input.nextLong();}
class TimeCalculations {
public long currentTime;
public static long elaspedTime;
public TimeCalculations() {
currentTime = System.currentTimeMillis();
this.currentTime = currentTime;
}
public TimeCalculations(long currentTime, long elaspedTime) {
elaspedTime = currentTime -Time.input();
}
public long getCurrentTime() {
return this.currentTime;
}
public long getElaspedTime() {
return TimeCalculations.elaspedTime;
}
I am sorry! but I didn't get this! "however, the problem arises when using constructors"
Can you please give some more details!
Thanks!
Thanks! for your details. just call the input method in public static void main at first line
}