-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectric.java
More file actions
38 lines (30 loc) · 1.14 KB
/
Electric.java
File metadata and controls
38 lines (30 loc) · 1.14 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
/**
* File Name : Electric.java
* Author : Kwame Duodu
* Date : June 14, 2020
* Purpose : A program that computes the sales tax for a collection of automobiles of different types.
*/
public class Electric extends Automobile {
private Integer weightInPounds;
//constructor
public Electric(String makeAndModel,double purchasePrice, Integer weightInPounds) {
super (makeAndModel, purchasePrice);
this.weightInPounds = weightInPounds;
}
//overridden method salesTax that returns the total sales tax
@Override
public double salesTax(){
double salesTaxPrice = super.salesTax();
if(weightInPounds < 3000) {
return salesTaxPrice - 200;
} else {
return salesTaxPrice - 150;
}
}
// Overridden toString method that return a string containing the make and the model of the automobile, sales price, sales tax, and weight
@Override
public String toString() {
return String.format("\nMake and Model : %s\n"+ "Sales Price : %.2f\n" + "Sales Tax : %.2f\n"+ "Weight : %d\n"
+ "Electric Vehicle",makeAndModel,purchasePrice, salesTax(),weightInPounds);
}
}