-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicle.java
More file actions
91 lines (81 loc) · 1.87 KB
/
Vehicle.java
File metadata and controls
91 lines (81 loc) · 1.87 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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
public class Vehicle
{
//instance variables
private String mfr;
private String color;
private int numWheels;
public boolean answer;
//enum used to set static final value for ELECTRIC_MOTOR and GAS_ENGINE
enum PowerSource
{
ELECTRIC_MOTOR, GAS_ENGINE;
}
//creating reference to enum so it can be assigned to the constructer
public PowerSource power;
/**
* Constructor: initializes mfr, color, power, numWheels
*/
public Vehicle(String mfr, String color, PowerSource power, int numWheels)
{
this.mfr = mfr;
this.color = color;
this.power = power;
this.numWheels = numWheels;
}
/**
Returns the power source
@return the power source
*/
public PowerSource getPower()
{
return power;
}
/**
Returns the manufacturer
@return the manufacturer
*/
public String getMfr()
{
return mfr;
}
/**
Returns the color
@return the color
*/
public String getColor()
{
return color;
}
/**
Returns the number of wheels
@return the number of wheels
*/
public int getNumWheels()
{
return numWheels;
}
/**
Returns the boolean value true or false if vehicles are equal
@return answer
*/
public boolean equal(Vehicle other)
{
if (this.getPower() == other.getPower() && this.getMfr() == other.getMfr() && this.getNumWheels() == other.getNumWheels())
{
answer = true;
}
else
{
answer = false;
}
return answer;
}
/**
Returns the string containing manufacturer name and color seperated by a space
@return the display
*/
public String display()
{
return mfr + " " + color;
}
}