-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTruck.java
102 lines (90 loc) · 3.16 KB
/
Truck.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
// Tanner Loy
// CS 110
// A class which represents a Truck given its Owner,
// make, model, year, mileage, capacity, and number of axles.
public class Truck extends Vehicle{
private int capacity, numAxles;
private static final int DEF_CAPACITY = 1, DEF_AXLES = 2;
/**
* Constructor for the Truck class
* @param owner the owner of the Truck as Person
* @param make the make of the Truck in String
* @param model the model of the Truck in String
* @param year the year of the Truck in int
* @param mileage the mileage of the Truck in int
* @param capacity the capicity of the Truck in int
* @param numAxles the number of axles of the Truck in int
*/
public Truck(Person owner, String make, String model, int year, int mileage, int capacity, int numAxles) {
super(owner, make, model, year, mileage);
this.capacity = capacity;
this.numAxles = numAxles;
}
/**
* Secondary constructor for the Truck class whhich sets the capacity and number of axles to defaults
* @param name the name of the Owner of the Truck in String
* @param address the address of the Owner of the Truck in String
* @param phone the phone number of the Owner of the Truck in String
* @param make the make of the Truck in String
* @param model the model of the Truck in String
* @param year the year of the Truck in int
* @param mileage the milage of the Truck in int
*/
public Truck(String name, String address, String phone, String make, String model, int year, int mileage) {
super(new Person(name, address, phone), make, model, year, mileage);
this.capacity = DEF_CAPACITY;
this.numAxles = DEF_AXLES;
}
// GETTERS AND SETTERS
/**
* Getter for capacity
* @return an int capacity
*/
public int getCapacity() {
return this.capacity;
}
/**
* Getter for numAxles
* @return an int numAxles
*/
public int getNumAxles() {
return this.numAxles;
}
/**
* Setter for capacity
* @param capacity capacity in int
*/
public void setCapacity(int capacity) {
this.capacity = capacity;
}
/**
* Setter for numAxles
* @param numAxles an int numAxles
*/
public void setNumAxles(int numAxles) {
this.numAxles = numAxles;
}
@Override
/**
* Overridden toString() method for Truck
* @return a String containing formatted output
*/
public String toString() {
return String.format("%s\n%s %s %s %s miles %d ton %d axles", getOwner(), getMake(), getModel(), getYear(), getMileage(), capacity, numAxles);
}
@Override
/**
* Overridden equals() method for Truck
* @param o an Object o to be cast to Truck and compared
* @return true if all fields are the same, false otherwise
*/
public boolean equals(Object o) {
if (o.getClass() != this.getClass())
return false;
Truck t = (Truck) o;
if (super.equals(o) && this.capacity == t.capacity && this.numAxles == t.numAxles)
return true;
else
return false;
}
}