-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathElapsedTime.java
62 lines (56 loc) · 1.45 KB
/
ElapsedTime.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* A class representing an elapsed time measurement
* in hours and minutes.
* @author Mary Adams
* @version 1.0
*/
public class ElapsedTime {
/*
* The hours portion of the time
*/
private int hours;
/**
* The minutes portion of the time
*/
private int minutes;
/**
* Constructor initializing hours to timeHours and
* minutes to timeMins.
* @param timeHours hours portion of time
* @param timeMins minutes portion of time
*/
public ElapsedTime(int timeHours, int timeMins) {
hours = timeHours;
minutes = timeMins;
}
/**
* Default constructor initializing all fields to 0.
*/
public ElapsedTime() {
hours = 0;
minutes = 0;
}
/**
* Prints the time represented by an ElapsedTime
* object in hours and minutes.
*/
public void printTime() {
System.out.print(hours + " hour(s) " + minutes + " minute(s)");
}
/**
* Sets the time to timeHours:timeMins.
* @param timeHours hours portion of time
* @param timeMins minutes portion of time
*/
public void setTime(int timeHours, int timeMins) {
hours = timeHours;
minutes = timeMins;
}
/**
* Returns the total time in minutes.
* @return an int value representing the elapsed time in minutes.
*/
public int getTimeMinutes() {
return ((hours * 60) + minutes);
}
}