class TestTax {
public static void main (String[] args){
NJTax t = new NJTax();
t.grossIncome= 50000;
t.dependents= 2;
t.state= "NJ";
double yourTax = t.calcTax();
double totalTax = t.adjustForStudents(yourTax);
System.out.println("Your tax is " + yourTax);
}
}
class tax {
double grossIncome;
String state;
int dependents;
public double calcTax(){
double stateTax = 0;
if(grossIncome < 30000){
stateTax = grossIncome * 0.05;
}
else{
stateTax = grossIncome * 0.06;
}
return stateTax;
}
public void printAnnualTaxReturn(){
// code goes here
}
}
public class NJTax extends tax{
double adjustForStudents (double stateTax){
double adjustedTax = stateTax - 500;
return adjustedTax;
public double calcTax(){
}
}
}
I am having trouble with the Lesson requirement to:
“Change the functionality of calcTax( ) by overriding it in NJTax. The new version of calcTax( ) should lower the tax by $500 before returning the value.”
How is this accomplished. I just have safaribooksonline and no videos for the solution.
http://download.oracle.com/javase/tutorial/java/IandI/override.html
Class names should start with a capital letter as well. Since I’m not exactly sure what you wanted regarding functionality, here’s just an example. Super refers to the parent class, in this case being
tax. Thus,NJTax‘s calcTax() method returnstax.calcTax() - 500. You also may want to look into using the@Overrideannotation as a way of making it clear that a method is being overridden and to provide a compile-time check.