-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speed.java
52 lines (47 loc) · 1.08 KB
/
Speed.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
public class Speed
{
private String units = "miles";
private String timeUnits = "hour";
private int velocity = 0;
Speed()
{
}
Speed(String u, String tu)
{
setUnits(u);
setTimeUnits(tu);
}
public String getSpeed()
{
String vString = Integer.toString(velocity);
return vString + " " + units + " per " + timeUnits;
}
public String getUnits() {
return units;
}
public void setUnits(String units) {
if(units.equals("miles") || units.equals("kilometers") || units.equals("meters"))
this.units = units;
else
{
System.out.println(units + " is an invalid type of units");
}
}
public String getTimeUnits() {
return timeUnits;
}
public void setTimeUnits(String timeUnits) {
if(timeUnits.equals("hour") || timeUnits.equals("minute") || timeUnits.equals("second"))
this.timeUnits = timeUnits;
else
{
System.out.println(timeUnits + " is an invalid type of timeUnits");
}
}
public int getVelocity() {
return velocity;
}
public void setVelocity(int velocity) {
this.velocity = velocity;
}
}