package edu.westga.taxcalculator.model;
/**
* Creates a taxReturn object
*/
public class TaxReturn {
private double income;
/**
* Constructor for the TaxReturn class
*
* @param income
* the income of the person.
*/
public TaxReturn(double income) {
if (income < 0) {
throw new IllegalArgumentException(
"Income can't be less than zero.");
}
this.income = income;
}
public void getTax() {
if (income <= 50000) {
income *= 0.01;
} else if (income <= 75000) {
income *= 0.02;
} else if (income <= 100000) {
income *= 0.03;
} else if (income <= 250000) {
income *= 0.04;
} else if (income <= 500000) {
income *= 0.05;
} else
income *= 0.06;
}
}
package edu.westga.taxcalculator.controller;
import java.util.Scanner;
import edu.westga.taxcalculator.model.TaxReturn;
public class TaxCalculatorController {
public static void main(String[] args) {
System.out.println("Please enter your income: ");
Scanner theScanner = new Scanner(System.in);
double income = theScanner.nextDouble();
TaxReturn theCalculator = new TaxReturn(income);
System.out.println("The amount of tax is: " + taxReturn.getTax());
}
}
我写一个程序所得税计算器,该项目有一个类和测试类。假设计算我输入金额的所得税,但效果不好。我会很感激任何帮助,因为我绝对坚持这一点。所得税计算器
它是如何不工作?你在期待什么,发生了什么? – Andy