Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca74994

Browse files
committed
Revert ":pencil: change super to this"
This reverts commit 315e881.
1 parent eaaeb17 commit ca74994

File tree

1 file changed

+52
-0
lines changed
  • lab9/lab9q1s6434480323/src/lab9q1s6434480323

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package lab9q1s6434480323;
7+
8+
/**
9+
*
10+
* @author ratchanon
11+
*/
12+
public class Truck extends Car {
13+
// Additional Instance Variable
14+
private double M_weight;
15+
private double weight;
16+
17+
18+
public Truck(double gas, double efficiency, double M_weight,double weight) {
19+
super(gas, efficiency);
20+
this.M_weight = M_weight;
21+
22+
if (weight > M_weight){
23+
this.weight = M_weight;
24+
} else {
25+
this.weight = weight;
26+
}
27+
}
28+
29+
@Override
30+
public void drive(double distance){
31+
double additionalGas;
32+
double useGas = distance / super.getEfficiency();
33+
34+
if(this.weight < 1){
35+
additionalGas = 0;
36+
} else if(this.weight <= 10){
37+
additionalGas = useGas * 0.1;
38+
} else if(this.weight <= 20){
39+
additionalGas = useGas * 0.2;
40+
} else {
41+
additionalGas = useGas * 0.3;
42+
}
43+
44+
useGas += additionalGas;
45+
46+
if (useGas > super.getGas()) {
47+
System.out.println("You cannot drive too far, please add gas");
48+
} else {
49+
super.setGas(super.getGas() - useGas);
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)