gpt4 book ai didi

java - 程序没有在我的 if else 语句中分配值

转载 作者:行者123 更新时间:2023-12-02 02:22:02 26 4
gpt4 key购买 nike

我对 Java 很陌生,我的任务是制作一个税务计算器。一切似乎都工作正常,但当我最后打印时,联邦税总是打印 0。我在开始时进行了 double ,然后尝试通过 else if 语句根据情况重新分配它。

//2353161 Tomas Pospisil
import java.util.Scanner;

public class PaymentCalculator {

public static void main(String[] args){
//Create Scanner for user input
Scanner input = new Scanner(System.in);

//Ask the user for Gross Pay
System.out.print("Please Enter Gross Pay: ");
double GrossPay = input.nextInt();

//Establish the integer for Number of Exemptions
int NoE = 0;

//Establish the integer for the value of exemption
double exemptionvalue = 0;

double federaltaxes = 0;

//Ask the user if they are married
System.out.print("Are you married: ");
String marriedstatus = input.next();

//If yes make the number of Exemptions equal the user input
if (marriedstatus.equals("yes")) {
System.out.print("Please enter Number of Exemptions: ");
NoE = input.nextInt();
}
//If not make the number of exemptions equal 1
else if(marriedstatus.equals("no")) {
NoE = 1;
}
//If NoE is greater than 4 make it 5 for later use
if (NoE >4) {
NoE = 5;
}

// Depending on the number of exemptions the program assigns it a value for later use
switch (NoE) {
case 1:
exemptionvalue = 1000;
break;
case 2:
exemptionvalue = 1800;
break;
case 3:
exemptionvalue = 2400;
break;
case 4:
exemptionvalue = 3600;
break;
case (5):
exemptionvalue = 4000;
break;
}

//Calculate adjusted wages
double adjustedwages = GrossPay - exemptionvalue;

// Figure out the tax percentage
if (GrossPay >= 10000) {
federaltaxes = GrossPay * 0;
}
else if (GrossPay <= 30000 && GrossPay >= 10000) {
federaltaxes = GrossPay * 0.15 ;
}
else if (GrossPay > 30000) {
federaltaxes = GrossPay * 0.20 ;
}


//Program calculates the FICA
double FICA = (GrossPay * .065);

//Program calculates Medicare
double Medicare = (GrossPay * .014);

//Program calculates the federal taxes


//Program Calculates Net Pay
double NetPay = GrossPay - (FICA + Medicare + federaltaxes);


//Program prints the results
System.out.println(" Payroll Taxes");
System.out.println("Gross.....$ " + GrossPay);
System.out.println("Exemptions: " + NoE);
System.out.println("Federal Taxes.....$ " + federaltaxes);
System.out.println(" FICA.....$ " + FICA);
System.out.println(" Medicare.....$ " + Medicare);
System.out.println("-----------------------------");
System.out.println("Net Pay.....$ " + NetPay);







}
}

最佳答案

这是给您带来麻烦的 block 。

if (GrossPay >= 10000) {
federaltaxes = GrossPay * 0;
}

任何高于 10000 的 GrossPay 金额都将通过条件并乘以 0。

关于java - 程序没有在我的 if else 语句中分配值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48370344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com