-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.java
More file actions
34 lines (30 loc) · 1.07 KB
/
Copy pathTime.java
File metadata and controls
34 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Timer that I ended up implementing into the Game class.
*/
public class Time
{
// instance variables - replace the example below with your own
private int x;
private double startingTime;
private final double SEC_MIN = 60.0;
private final int MIL_SEC = 1000;
private final int HOUR_DAY = 24;
private final double PLAY_MIN = 5.0; //playing time
/**
* Constructor for objects of class Timer
*/
public Time()
{
startingTime = System.currentTimeMillis();
}
public void printTime()
{
double timeElapsed = (System.currentTimeMillis()/MIL_SEC - startingTime/MIL_SEC);
double elapsedTimeInMinutes = timeElapsed / SEC_MIN;
double timeInHours = (elapsedTimeInMinutes*(HOUR_DAY) / PLAY_MIN);
int day = (int) (timeInHours / HOUR_DAY);
int hours = (int)(timeInHours - (day*HOUR_DAY));
int minutes = (int)((timeInHours - (day *HOUR_DAY) - hours)*SEC_MIN);
System.out.println("Time elapsed: " + day + " Days, " + hours + " hours, and " + minutes + " minutes.");
}
}