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