Question: Why won't this code work in Netbeans? This is my project: (in photos you will find my code) The second programming project involves writing a
Why won't this code work in Netbeans? This is my project: (in photos you will find my code)
The second programming project involves writing a program that computes the sales tax for a collection of automobiles of different types. This program consists of four classes. The first class is the Automobile class, which contains the automobiles make and model, and purchase price, which is specified in whole dollars. It should have three methods: 1. A constructor that allows the make and purchase price to be initialized. 2. A method named salesTax that returns the base sales tax computed as 5% of the sales price. 3. A toString method that returns a string containing the make and model of the automobile, the sales price, and the sales tax, appropriately labeled. The Automobile class has two subclasses. The first is Electric. It has an additional instance variable that contains its weight in pounds stored as an integer. It should have the same three methods: 1. A constructor that allows the automobiles make and model, purchase price and weight to be initialized. 2. An overridden method salesTax that returns the total sales tax. The sales tax for an electric automobile consists of the base sales tax of 5% that applies to all automobiles minus a discount. If the weight is less than 3000 pounds the discount is $200. Otherwise it is $150. 3. An overridden toString method that returns a string containing the make and model of the automobile, the sales price, sales tax and the weight, appropriately labeled. The second subclass is Hybrid. It has an additional instance variable that contains the number of miles per gallon stored as an integer. It should have the same three methods: 1. A constructor that allows the automobiles make and model, purchase price and miles per gallon to be initialized. 2. An overridden method salesTax that returns the total sales tax The sales tax for a hybrid automobile consists of the base sales tax of 5% minus a discount. If the number of miles per gallon is less than 40, the discount is $100. Otherwise there is an additional discount of $2 for every mile per gallon in excess of 40. 3. An overridden toString method that returns a string containing the make and model of the automobile, the sales price, sales tax and the number of miles per gallon, appropriately labeled.



// Automobile.java public class Automobile //set visibity as protected to //access from sub classes electric and Hybrid protected String make; protected String model; protected double purchasePrice; protected final double TAX_RATE=0.05; /*Automobile constructor*/ public Automobile(String make, String model, double price) { this.make=make; this.model=model; this.purchasePrice=price; /*Override the salesTax method*/ public double salesTax() return purchase Price*TAX_RATE; /*Override to String method*/ public String toString return String.format("Make: %s Model: %s Sales: $%.2f Sales tax: $%.2f" make, model, purchase Price, salesTax()); }//end of the Automobile class //Electric.java public class Electric extends Automobile //instance variable private double weight; /*constructor*/ public Electric(String make, String model, double price, double weight) super(make, model, price); this.weight=weight; //Calculate discount based on weight //Discount is 200 if weight is below 3000 //Otherwise it is 150 public double salesTax() { double discount=0; if(weight
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
