Tax class First step is to create a class called Tax (Tax.java) it will not cont
ID: 3588011 • Letter: T
Question
Tax class
First step is to create a class called Tax (Tax.java) it will not contain a main method.
The Tax class will be very simple it will contain two private instance variables:
o taxPayerNameasaString
o incomeasaninteger
The following public methods will have to be implemented:
o A default constructor
o A parameterised constructor
o Two setmethods(mutators)
o Two getmethods(accessors)
o computeTax()method*
*You will also create a public value returning method to return the calculated tax. The tax can be derived from the calculation according to the tax rates as assignment 1. In other words the tax will be retrieved via your computeTax() method, which is a user-defined method inside the Tax class and it does not contain the keyword static.
Explanation / Answer
Here is the Tax class for you:
class Tax
{
String taxPayerName;
int income;
//Default constructor.
Tax()
{
taxPayerName = "";
income = 0;
}
//Parameterised constructor.
Tax(String name, int incm)
{
taxPayerName = name;
income = income;
}
//Two mutators.
public void setTaxPayerName(String name)
{
taxPayerName = name;
}
public void setIncome(int incm)
{
income = incm;
}
//Two accessors.
public String getTaxPayerName() { return taxPayerName; }
public int getIncome() { return income; }
public double computeTax()
{
return income * 0.01; //As you didn't gave any logic on how to implement the tax, I just took it as 10% of income.
//You can modify this function logic as per your requirement.
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.