-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vehicle.java
177 lines (146 loc) · 3.66 KB
/
Vehicle.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import java.util.Random;
/**
* @author Parth Patel #500893723
* Vehicle class
* This is the superclass to all the extended classes
*
*/
public class Vehicle
{
/**
* Instance variable mfr is manufacturer name of the Vehicle
* Instance variable color is the Color of car
* Instance variable power is the power source of the Vehicle
* Instance variable numWheels is the number of wheels
*/
private String mfr;
private String color;
private int power;
private int numWheels;
public final int ELECTRIC_MOTOR = 0; //public integer constant ELECTIRC_MOTOR
public final int GAS_ENGINE = 1; //public integer constant GAS_ENGINE
private int VIN;
/**
* Constructor method to initialize the instance variables
* @param mfr is the manufacturer name
* @param color is the Color of car
* @param power is the power source of the car
* @param numWheels is the number of wheels
*/
public Vehicle(String mfr, String color, int power, int numWheels)
{
Random r = new Random();
this.mfr = mfr;
this.color = color;
this.power = power;
this.numWheels = numWheels;
VIN = 100 + r.nextInt(399);
}
/**
* @return mfr
* returns the string containing manufacturer name
*/
public String getMfr()
{
return mfr;
}
/**
* @param mfr1
* sets the mfr variable to the parameter passed to the method
*/
public void setMfr(String mfr1)
{
mfr = mfr1;
}
/**
* @return color of the car
*/
public String getColor()
{
return color;
}
/**
* @param color
* sets the color variable to the parameter passed to the method
*/
public void setColor(String color1)
{
color = color1;
}
/**
* @return power
* returns the value of the variable power
*/
public int getPower()
{
return power;
}
/**
* @param power
* sets the variable power to the parameter passed to the method
*/
public void setPower(int power1)
{
power = power1;
}
/**
* @return numWheels
* returns the value assigned to the variable numWheels
*/
public int getNumWheels()
{
return numWheels;
}
/**
* @param numWheels1
* sets the variable value to the parameter passed to the method
*/
public void setNumWheels(int numWheels1)
{
numWheels = numWheels1;
}
/**
* @return returns a string indicating if the vehicle has a Gas Engine or Electric Motor
* depending upon the input passed in the constructor for the variable power
*/
public String getEngineType()
{
int i = getPower();
if(i == 0)
return "GAS_ENGINE";
else if(i == 1)
return "ELECTRIC_MOTOR";
else
return "Invalid input for the variable engineType";
}
/**
* @return VIN
* this method returns the VIN number of the car which is generated by the random number object
* created in the constructor
*/
public int getVIN()
{
return VIN;
}
/**
* @return a string containing the name of manufacturer and the color of the Vehicle
*/
public String display()
{
return "VIN: " + getVIN() + " " + getMfr() + " " + getColor();
}
/**
* @param takes an object as a parameter and checks whether two objects are same
* on the basis of their Manufacturer name, Engine type and Number of wheels
* of all the variables match then it @returns true, it not it @returns false.
*/
public boolean equals(Object other)
{
Vehicle otherO = (Vehicle)other;
if((getMfr().equals(otherO.getMfr())) &&
(getPower() == (otherO.getPower()))&&
(getNumWheels() == (otherO.getNumWheels())))
return true;
return false;
}
}