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

标签 java

我是一个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/

相关文章:

java - 从命令行获取java进程的 "user.dir"系统属性

java - 如何在基本的纯文本程序中创建类似表格的整洁布局?

Java图形(颜色和字体)

java - 为什么我的 Firestore 数据权限被拒绝?

java - 由于图像太多(只有 20 张图像),无法在 Note 2 上运行应用程序

java - 从其他两个日期创建日期时间

Java程序按顺序打印数字

java - 在 for 循环的最后一次迭代上打印

java - Android HttpURLConnection 方法在 API 23 中被删除?

java - 使用 Java 将 JSON 文件转换为 RDF 格式