我正在编写一个计算所得税的程序,该程序会根据您的个人收入增加税额。我在“退税”行不断收到错误“可变税可能尚未初始化”;但我不确定为什么。到目前为止,这是我的代码:
import java.util.Scanner; //Needed for the Scanner Class
/**
* Write a description of class IncomeTax here.
* @author
* 11/30/2012
* The IncomeTax class determines how much tax you owe based on taxable income.
*/
/**
* The getTax returns the tax for the income.
*/
public double getTax() {
double tax;
if (income <10000.0) {
tax = 0.10;
}
else {
if (income > 10001.0 && income < 30000.0) {
tax = 0.15;
}
else {
if (income > 30001.0 && income < 60000.0) {
tax = 0.25;
}
else {
if (income > 60001.0 && income < 130000.0) {
tax = 0.28;
}
else {
if (income > 130001.0 && income < 250000.0) {
tax = 0.33;
}
else {
if (income > 250001.0) {
tax = 0.35;
}
}
}
}
}
}
return tax;
}
/**
* The constructor accepts an argument for the income field.
*/
public IncomeTax(int i)
{
income = i;
}
/**
* The setIncome method accepts an argument for the income field.
*/
public void SetIncome(int i) {
income = i;
}
/**
* The getIncome method returns the income field.
*/
public int getIncome() {
return income;
}
我还没有完成,我仍然需要为用户编写代码以实际输入他们的信息进行计算,但我不想在不先修复退税行的情况下继续往下走。