-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTruck.java
More file actions
28 lines (23 loc) · 801 Bytes
/
Copy pathTruck.java
File metadata and controls
28 lines (23 loc) · 801 Bytes
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
// Create a subclass of the Car class and name it Truck. The Truck class has the following fields and methods.
// int weight;
// double getSalePrice();
// for this method implement this: If weight>2000, 10%discount. Otherwise, 20%discount.
public class Truck extends Car {
int weight;
public Truck(int speed, double regularPrice, String color, int weight) {
super(speed, regularPrice, color);
this.weight = weight;
}
@Override
double getSalePrice() {
double discountPrice;
if (weight > 2000) {
//10% discount
discountPrice = super.regularPrice * 0.10;
} else {
//20% discount
discountPrice = super.regularPrice * 0.20;
}
return super.regularPrice - discountPrice;
}
}