有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

bluej Java:计算税

我正在写一个计算所得税的程序,根据你的个人收入增加税额。我在“返回税”一行中不断收到错误“可变税可能未初始化”但我不知道为什么。以下是我目前的代码:

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;
}

我还没有完成,我仍然需要为用户编写代码,以实际输入他们的信息进行计算,但我不想在不首先修复报税行的情况下再进一步


共 (0) 个答案