forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar.java
66 lines (57 loc) · 1.3 KB
/
Car.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
/**
* Car class
*
* Used for the Real Python OOP in Java vs Python article
*
* Requires both Vehicle.java and Device.java
*/
public class Car extends Vehicle implements Device {
private int year; // Year of our car
private int voltage; // Battery voltage
private static int wheels; // How many wheels do we have
/**
* Car constructor
*/
public Car(String color, String model, int year) {
super(color, model);
this.year = year;
this.voltage = 12;
}
/**
* Override the interface method.
*/
@Override
public int getVoltage() {
return voltage;
}
/**
* getYear returns the Car's year
*/
public int getYear() {
return year;
}
/**
* setYear changes Car's year
*/
public void setYear(int year) {
this.year = year;
}
/**
* getWheels returns the number of wheels
*/
public static int getWheels() {
return wheels;
}
/**
* setWheels sets the number wheels
*/
public static void setWheels(int count) {
wheels = count;
}
/**
* Return a human readable string reoresenting the Car
*/
public String toString() {
return "Car: " + getColor() + " : " + getModel() + " : " + getYear();
}
}