-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVehicle.java
152 lines (133 loc) · 3.6 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
// Tanner Loy
// CS 110
// A class which represents a Vehicle given its Owner,
// make, model, year, and mileage.
public class Vehicle {
private Person owner;
private String make, model;
private int year, mileage;
/**
* Constructor for the Vehicle class
* @param owner the owner of the vehicle as a Person
* @param make the make of the Vehicle in String
* @param model the model of the Vehicle in String
* @param year the year of the Vehicle in int
* @param mileage the mileage of the Vehicle in int
*/
public Vehicle(Person owner, String make, String model, int year, int mileage) {
this.owner = owner;
this.make = make;
this.model = model;
this.year = year;
this.mileage = mileage;
}
/**
* Secondary constructor for the Vehicle class which sets the mileage to 0
* @param owner the owner of the vehicle as a Person
* @param make the make of the Vehicle in String
* @param model the model of the Vehicle in String
* @param year the year of the Vehicle in int
*/
public Vehicle(Person owner, String make, String model, int year) {
this.owner = owner;
this.make = make;
this.model = model;
this.year = year;
this.mileage = 0;
}
// GETTERS AND SETTERS
/**
* Getter for owner
* @return a String owner
*/
public Person getOwner() {
return this.owner;
}
/**
* Getter for make
* @return a String make
*/
public String getMake() {
return this.make;
}
/**
* Getter for model
* @return a String model
*/
public String getModel() {
return this.model;
}
/**
* Getter for year
* @return an int year
*/
public int getYear() {
return this.year;
}
/**
* Getter for mileage
* @return an int mileage
*/
public int getMileage() {
return this.mileage;
}
/**
* Setter for owner
* @param owner owner in Person
*/
public void setOwner(Person owner) {
this.owner = owner;
}
/**
* Setter for make
* @param make make in String
*/
public void setMake(String make) {
this.make = make;
}
/**
* Setter for model
* @param model model in String
*/
public void setModel(String model) {
this.model = model;
}
/**
* Setter for year
* @param year year in int
*/
public void setYear(int year) {
this.year = year;
}
/**
* Setter for mileage
* @param mileage mileage in int
*/
public void setMileage(int mileage) {
this.mileage = mileage;
}
// OVERRIDES
@Override
/**
* Overridden toString() method for Vehicle. Person's toString() is invoked.
* @return a String containing formatted output
*/
public String toString() {
return String.format("%s\n%s %s %s %s miles", owner, make, model, year, mileage);
}
@Override
/**
* Overridden equals() method for vehicle. Person's equals() is invoked.
* @param o an Object o to be cast to Vehicle and compared
* @return true if all fields are the same, false otherwise
*/
public boolean equals(Object o) {
if (o.getClass() != this.getClass())
return false;
Vehicle v = (Vehicle) o;
if (this.owner.equals(v.owner) && this.make.equals(v.make) && this.model.equals(v.model) && this.year == v.year && this.mileage == v.mileage)
return true;
else
return false;
}
}