2014-03-05 71 views
0
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()); 
    } 
} 

我写一个程序所得税计算器,该项目有一个类和测试类。假设计算我输入金额的所得税,但效果不好。我会很感激任何帮助,因为我绝对坚持这一点。所得税计算器

+2

它是如何不工作?你在期待什么,发生了什么? – Andy

回答

0

一开始变化

TaxReturn theCalculator = new TaxReturn(income); 
    System.out.println("The amount of tax is: " + taxReturn.getTax()); 

TaxReturn theCalculator = new TaxReturn(income); 
    System.out.println("The amount of tax is: " + theCalculator .getTax()); 

而且你Constructor抛出Exception,但没有宣布它打算。

所以改为

public TaxReturn(double income) throw IllegalArgumentException { .... 
+0

非常感谢我现在正在开展工作。 – user3344737

+0

伟大请接受我的回答。 –

+0

我是新来的,我该怎么做? – user3344737