我尝试使用程序和功能创建所得税计算器。代码应该是不言自明的。一切都回归零,有人能给我一些关于我出错的地方吗?
import java.util.Scanner;
public class MyClass {
public static Employee2[] ePlus(final Employee2[] e) {
// Code in progress
return new Employee[0];
}
public static void main(final String[] args) {
Employee2[] e = new Employee2[0];
int counter = 0; //int variable = counter
Scanner scanner = new Scanner(System.in);
e = ePlus(e);
System.out.println(e);
}
}
答案 0 :(得分:1)
你去吧。看看我做了什么,这样你就能明白我和你的不同之处。我还假设你有一个名为TextBoxDeductions的文本框。你也应该有一个CheckBox点击,如果已婚或没有。这个CheckBox我打电话给CheckBoxMarried。我结合了你的2个函数SingleFunction和SingleMarriedFunction。希望它能帮到你!
Function GetTaxLiability(ByVal totalWages As Decimal, ByVal married As Boolean) As Decimal
Dim taxRate As Decimal
If married = True And totalWages < 25000.0 Then
taxRate = 0.13
ElseIf married = True And totalWages >= 25000.0 And totalWages < 45000.0 Then
taxRate = 0.16
ElseIf married = True And totalWages >= 45000.0 And totalWages < 65000.0 Then
taxRate = 0.18
ElseIf married = True And totalWages >= 65000.0 And totalWages < 85000.0 Then
taxRate = 0.2
ElseIf married = True And totalWages >= 85000.0 And totalWages < 100000.0 Then
taxRate = 0.22
ElseIf married = True And totalWages >= 100000.0 Then
taxRate = 0.24
End If
If married = False And totalWages < 25000.0 Then
taxRate = 0.15
ElseIf married = False And totalWages >= 25000.0 And totalWages < 45000.0 Then
taxRate = 0.18
ElseIf married = False And totalWages >= 45000.0 And totalWages < 65000.0 Then
taxRate = 0.22
ElseIf married = False And totalWages >= 65000.0 And totalWages < 85000.0 Then
taxRate = 0.28
ElseIf married = False And totalWages >= 85000.0 And totalWages < 100000.0 Then
taxRate = 0.32
ElseIf married = False And totalWages >= 100000.0 Then
taxRate = 0.35
End If
Return taxRate * totalWages
End Function
Function FederalTax(ByVal taxWithheld As Decimal, ByVal taxLiability As Decimal, ByVal deductions As Integer) As Decimal
Return taxWithheld - taxLiability - (deductions * 750)
End Function
Function StateTax(ByVal totalWages As Decimal) As Decimal
Return totalWages * 0.06
End Function
Function LocalTax(ByVal totalWages As Decimal) As Decimal
Return totalWages * 0.01
End Function
Sub DisplayData()
Dim TaxLiability As Decimal
If CheckBoxMarried.Checked = True Then
TaxLiability = GetTaxLiability(CDec(TextBoxWages.Text), True)
Else
TaxLiability = GetTaxLiability(CDec(TextBoxWages.Text), False)
End If
Label7.Text += "Tax Liability: " + CStr(TaxLiability)
Label7.Text += "Federal Taxes: " + CStr(FederalTax(CDec(TextBoxTaxesWithheld.Text), TaxLiability, CDec(TextBoxDeductions.text)))
Label7.Text += "State Taxes: " + CStr(StateTax(CDec(TextBoxWages.Text)))
Label7.Text += "Local Taxes: " + CStr(LocalTax(CDec(TextBoxWages.Text)))
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DisplayData()
End Sub