In: Computer Science
The citizens of Javaland require a program that calculates the personal income tax owed by
each taxpayer.
Write the code for a class method
calculateTaxableIncome
that accepts the following 5
inputs:
General Income
Investment Income
Other Income
Regular Deductions
Other Deductions
The method calculates the amount of a citizen’s taxable income. Taxable income is obtained
by summing all income and subtracting all deductions. Note that only 50% of Other
Deductions are tax deductible.
The signature for this method is:
public static double calculateTaxableIncome(double generalIncome, double
investmentIncome, double otherIncome, double regularDeductions,
double otherDeductions)
Note that all calculated monetary values should be rounded to 2 decimal places.
Write the code for a class method
calculateIncomeTax
that accepts the following input:
Taxable Income. The method calculates the amount of income tax due to the Government of
Javaland based on a citizen’s calculated taxable income. Income tax is calculated as a
percentage of taxable income based on the following rules:
10% on the first $20,000 of taxable income
12% on the next $20,000 of taxable income
15% on the next $20,000 of taxable income
20% on all remaining taxable income
The signature for this method is:
public static double calculateIncomeTax(double taxableIncome)
Comp 122 Assignment 03 page
2
Note that all calculated monetary values should be rounded to 2 decimal places.
Save these methods’ source code in your methods class
SOLUTION-
I have solve the problem in Java code with comments for easy
understanding :)
CODE-
//java code
//class
public class incomeTax {
//declaration
double generalIncome;
double InvestmentIncome;
double otherIncome;
double regularDeductions;
double otherDeductions;
public double getGeneralIncome() {
return generalIncome;
}
public void setGeneralIncome(double generalIncome) {
this.generalIncome = generalIncome;
}
public double getInvetmentIncome() {
return InvestmentIncome;
}
public void setInvestmentIncome(double investmentIncome) {
InvestmentIncome = investmentIncome;
}
public double getOtherIncome() {
return otherIncome;
}
public void setOtherIncome(double otherIncome) {
this.otherIncome = otherIncome;
}
public double getRegularDeductions() {
return regularDeductions;
}
public void setRegularDeductions(double regularDeductions) {
this.regularDeductions = regularDeductions;
}
public double getOtherDeductions() {
return otherDeductions;
}
public void setOtherDeductions(double otherDeductions) {
this.otherDeductions = otherDeductions;
}
public incomeTax(double generalIncome, double
investmentIncome, double otherIncome, double
regularDeductions,
double otherDeductions) {
super();
this.generalIncome = generalIncome;
InvestmentIncome = investmentIncome;
this.otherIncome = otherIncome;
this.regularDeductions = regularDeductions;
this.otherDeductions = otherDeductions;
}
public static double calculateTaxableIncome(double
generalIncome, double investmentIncome, double otherIncome, double
regularDeductions,
double otherDeductions)
{
return
generalIncome+investmentIncome+otherIncome-regularDeductions-(0.5*otherDeductions);
}
@Override
public String toString() {
return "incomeTax [generalIncome=" + generalIncome +
", InvestmentIncome=" + InvestmentIncome + ", otherIncome="
+ otherIncome +
", regularDeductions=" + regularDeductions + ", otherDeductions=" +
otherDeductions
+ ",
getGeneralIncome()=" + getGeneralIncome() + ",
getInvetmentIncome()=" + getInvetmentIncome()
+ ",
getOtherIncome()=" + getOtherIncome() + ", getRegularDeductions()="
+ getRegularDeductions()
+ ",
getOtherDeductions()=" + getOtherDeductions() + "]";
}
public static void main(String[] args) {
// TODO Auto-generated method
stub
incomeTax I =new
incomeTax(5400,7800,8000,4500,5300);
double
taxableIncome=I.calculateTaxableIncome(5400,7800,8000,4500,5300);
double incometax;
if (taxableIncome<=20000)
incometax=10*taxableIncome/100;
else if(taxableIncome>=20000
&& taxableIncome<=40000)
incometax=20*taxableIncome/100;
else if(taxableIncome>=40000
&& taxableIncome<=60000)
incometax=15*taxableIncome/100;
else
incometax=20*taxableIncome/100;
System.out.println(I.toString());
System.out.println("Income taax to
be paaid to the government is "+incometax);
}
}
OUTPUT:
incomeTax [generalIncome=5400.0, InvestmentIncome=7800.0,
otherIncome=8000.0, regularDeductions=4500.0,
otherDeductions=5300.0, getGeneralIncome()=5400.0,
getInvetmentIncome()=7800.0, getOtherIncome()=8000.0,
getRegularDeductions()=4500.0, getOtherDeductions()=5300.0]
Income taax to be paaid to the government is
1405.0
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------