-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar.java
134 lines (102 loc) · 3.11 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
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
public class Car {
int maxSpeed = 100;
int minSpeed = 0;
double weight = 4079;
boolean isTheCarOn = false;
char condition = 'A';
String nameOfCar = "Sertac";
double maxFuel = 16;
double currentFuel = 8;
double mpg = 26.4;
int numberOfPeopleInCar = 1;
int maxNumberOfPeopleInCar = 6;
public Car() {
}
public Car(int customMaxSpeed, double customWeight, boolean customIsTheCarOn){
maxSpeed = customMaxSpeed;
weight = customWeight;
isTheCarOn = customIsTheCarOn;
}
// getters and setters
public int getMaxSpeed() {
return this.maxSpeed;
}
public void setMaxSpeed(int newMaxSpeed){
this.maxSpeed = newMaxSpeed;
}
public int getMinSpeed() {
return this.minSpeed;
}
public double getWeight() {
return this.weight;
}
public boolean getIsTheCarOn() {
return this.isTheCarOn;
}
public void printVariables(){
System.out.println("The max speed is: " + maxSpeed);
System.out.println("The min speed is: " + minSpeed);
System.out.println("The weight is: " + weight);
System.out.println("Is the car on?: " + isTheCarOn);
System.out.println("The condition is: " + condition);
System.out.println("Car name is: " + nameOfCar);
System.out.println("Number of people in the car: " + numberOfPeopleInCar);
}
public void wreckCar(){
condition = 'C';
}
public void upgradeMaxSpeed() {
setMaxSpeed(getMaxSpeed() + 10);
}
public void getIn(){
// numberOfPeopleInCar = numberOfPeopleInCar + 1;
// numberOfPeopleInCar++;
if (numberOfPeopleInCar < maxNumberOfPeopleInCar){
numberOfPeopleInCar++;
System.out.println("Someone got in");
}
else {
System.out.println("The car is full " + numberOfPeopleInCar + "=" + maxNumberOfPeopleInCar);
}
}
public void getOut(){
//numberOfPeopleInCar--;
if (numberOfPeopleInCar > 0){
numberOfPeopleInCar--;
}
else{
System.out.println("No one is in the car " + numberOfPeopleInCar);
}
}
public double howManyMilesTillOutOfGas(){
return currentFuel * mpg;
}
public double maxMilesPerFillUp(){
return maxFuel * mpg;
}
public void turnTheCarOn(){
if (isTheCarOn == false){
isTheCarOn = true;
}
else{
System.out.println("The car is already on " + isTheCarOn);
}
}
public static void main(String[] args) {
Car tommyCar = new Car();
tommyCar.getOut();
tommyCar.getOut();
tommyCar.getIn();
tommyCar.getIn();
tommyCar.getIn();
tommyCar.getIn();
tommyCar.getIn();
tommyCar.getIn();
tommyCar.getIn();
tommyCar.turnTheCarOn();
tommyCar.turnTheCarOn();
//System.out.println("Christmas car");
//Car christmasPresent = new Car(550, 2000, false);
//christmasPresent.printVariables();
}
}