0

私はJava初心者です。メインメソッドでエラーが発生し続けます。助けてください!メソッドを正しい方法で呼び出していないと思います。他のすべてが機能するはずです。

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);
    }
}
4

5 に答える 5

3

一部のメソッドが引数を期待しているように見えますが、それらを提供していません。

例えば

public static double calculateThreshold (char married){}

このメソッドを呼び出すことはできませんcalculateThreshold();

結婚した calculateThreshold ('y'); の文字を渡す必要があります。

于 2013-10-09T00:40:40.760 に答える
0

ありがとうございました!!!!!!

calculate threshold(char) in the type Assignment 5 is not applicable for the arguments ()

今後は、実際のエラーに関するできるだけ多くの情報を常に投稿してください。みんなに推測させないでください:)

この場合:

1) "married" の戻り値を保存します。

   public static void main(String[] args) {
        ...
        char married = inputMarried(kbd);

2) 次に、それを「calculateThreshold()」に渡します。「threshold()」の戻り値を保存します。

    ...
    double threshold = calculateThreshold (married);

3) プログラムの残りの部分についても、必ず同じことを行ってください。

于 2013-10-09T00:43:41.817 に答える
0

実際、すべてのメソッドは、次のメソッドに配信されると思われるいくつかの回答を返します...

あなたの間違いは、返された値を変数に割り当てていないことです..それを修正してください

于 2013-10-09T00:44:02.803 に答える
0
public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        inputName(kbd);
        inputIncome(kbd);
        inputMarried(kbd);
        // modify this line calculateThreshold();
        calculateThreshold('a');
        // modify this line incomeBelowThreshold();
        incomeBelowThreshold(2.1, 2.2);
        // modify this line incomeAboveThreshold();
        incomeAboveThreshold(2.1, 2.2);
        // modify this line taxBelowThreshold();
        taxBelowThreshold(2.1);
        // modify this line taxAboveThreshold();
        taxAboveThreshold(2.1);
        // modify this line totalTaxes();
        totalTaxes(2.1, 2.1);
        // modify this line displayResults();
        displayResults("",'a', 2.1, 2.1);

    }
于 2013-10-09T00:44:15.477 に答える
0

1 つのエラーは、パラメーターを必要とするメソッドがありますが、パラメーターを渡していないことです。 calculateThreshold()たとえば、 は 1 つのパラメーターをincomeBelowThreshold()取り、2 つを取ります。また、入力ルーチンから値を返していません。これはエラーではありませんが、(編集やコンパイルの方法によっては) 警告としてフラグが立てられる場合がありますが、入力ルーチンからの値を他のルーチンに渡し、おそらくそれらを変換する必要があります。予め。

于 2013-10-09T00:43:00.720 に答える