gpt4 book ai didi

java - 我的主要方法有什么问题?

转载 作者:行者123 更新时间:2023-12-01 23:31:07 24 4
gpt4 key购买 nike

我是一个java菜鸟。我在 main 方法中不断收到错误。请帮忙!我认为我没有以正确的方式调用这些方法。其他一切都应该正常工作。

import java.util.Scanner;

public class Assignment5 {

public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
inputName(kbd);
inputIncome(kbd);
inputMarried(kbd);
calculateThreshold();
incomeBelowThreshold();
incomeAboveThreshold();
taxBelowThreshold();
taxAboveThreshold();
totalTaxes();
displayResults();

}

public static String inputName (Scanner kbd) {
System.out.print("What is your name?");
String name = kbd.nextLine();
return name;
}

public static double inputIncome (Scanner kbd) {
System.out.print("What is your annual income?");
double userIncome = kbd.nextDouble();
return userIncome;
}

public static char inputMarried (Scanner kbd) {
System.out.print("Are you married? (y for yes, n for no)");
char married = kbd.next().charAt(0);
return married;
}

public static double calculateThreshold (char married) {
double incomeThreshold;
if (married == 'y') {
incomeThreshold = 80000;
} else {
incomeThreshold = 40000;
}
return incomeThreshold;
}

public static double incomeBelowThreshold (double userIncome , double incomeThreshold) {
double incomeBelowThreshold;
if (userIncome <= incomeThreshold) {
incomeBelowThreshold = incomeThreshold - userIncome;
} else {
incomeBelowThreshold = userIncome;
}
return incomeBelowThreshold;
}

public static double incomeAboveThreshold (double userIncome, double incomeThreshold) {
double incomeAboveThreshold;
if (userIncome >= incomeThreshold) {
incomeAboveThreshold = incomeThreshold - userIncome;
} else {
incomeAboveThreshold = 0;
}
return incomeAboveThreshold;
}

public static double taxBelowThreshold (double incomeBelowThreshold) {
double taxBelowThreshold;
taxBelowThreshold = incomeBelowThreshold * .25;
return taxBelowThreshold;
}

public static double taxAboveThreshold (double incomeAboveThreshold) {
double taxAboveThreshold;
taxAboveThreshold = incomeAboveThreshold *.35;
return taxAboveThreshold;
}

public static double totalTaxes (double taxBelowThreshold, double taxAboveThreshold) {
double totalTaxes;
totalTaxes = taxBelowThreshold + taxAboveThreshold;
return totalTaxes;
}

public static void displayResults (String Name, char married, double income, double totalTaxes) {
System.out.print("Name:" + Name);
String marriedStatus;
if (married == 'y') {
marriedStatus = "Married";
} else {
marriedStatus = "Single";
}
System.out.print("Marital Status:" + marriedStatus);
System.out.printf("Income: %.2f" + income);
System.out.printf("Taxes: %.2f" + totalTaxes);
}
}

最佳答案

看起来您的某些方法需要参数,但您没有提供它们。

例如

public static double calculateThreshold (char married){}

您不能调用此方法calculateThreshold();

您需要传入已婚的字符计算阈值('y');

关于java - 我的主要方法有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19261015/

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