-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCar.java
More file actions
61 lines (51 loc) · 1.16 KB
/
Car.java
File metadata and controls
61 lines (51 loc) · 1.16 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
public class Car {
String make = "Chevrolet";
String model;
int year = 2020;
String color = "Blue";
double price = 50000.00;
String name;
// constructors, can have multiple if different parameters
Car() {
}
Car(String name) {
this.name = name;
}
Car(String make, String model) {
this.make = make;
this.model = model;
}
// copy constructor
Car(Car x) {
this.copy(x);
}
void drive() {
System.out.println("You drive the car");
}
void brake() {
System.out.println("You brake the car");
}
// overriding toString built-in method
public String toString() {
return make + "\n" + model + "\n" + color + "\n" + year;
}
// getters
public String getMake() {
return make;
}
public String getModel() {
return model;
}
// setters
public void setMake(String make) {
this.make = make;
}
public void setModel(String model) {
this.model = model;
}
// copy method
public void copy(Car x) {
this.setMake(x.getMake());
this.setModel(x.getModel());
}
}