Java 如何使用方法并在Switch语句中调用它们

Java 如何使用方法并在Switch语句中调用它们,java,Java,我正在为课堂制作一个税务计算器,但我不太明白如何在我的个案中分离我的代码 println("Please enter your filing status: "); println("Enter 0 for single filers,"); println(" 1 for married filing jointly,"); println(" 2 for married filing separately, or"); println(

我正在为课堂制作一个税务计算器,但我不太明白如何在我的个案中分离我的代码

  println("Please enter your filing status: ");
    println("Enter 0 for single filers,");
    println("      1 for married filing jointly,");
    println("      2 for married filing separately, or");
    println("      3 for head of household");
    double tax = 0;
    DecimalFormat df = new DecimalFormat("#.00");
    int filingStatus = readInt("Status: ");
    switch (filingStatus) {
        case 0: double taxableIncomes = readDouble("Please enter your taxable income: ");
        if (taxableIncomes <= 8925)
        {
            tax = (taxableIncomes * TEN);
            println("You owe: $" + df.format(tax));
        }
        if (taxableIncomes > 8925 && taxableIncomes <= 36250)
        {    
            tax = 892.5 + FIFTEEN * (taxableIncomes - 8925);
            println("You owe: $" + df.format(tax));
        }
        if (taxableIncomes > 36250 && taxableIncomes <= 87850)
        {
            tax = 892.5 + 4098.75 + TWENTYFIVE * (taxableIncomes - 36250);
            println("You owe: $" + df.format(tax));
        }
        if (taxableIncomes > 87850 && taxableIncomes <= 183250)
        {
            tax = 892.5 + 4098.75 + 12900 + TWENTYEIGHT * (taxableIncomes - 87850);
            println("You owe: $" + df.format(tax));
        }
        if (taxableIncomes > 183250 && taxableIncomes <= 398350)
        {
            tax = 892.5 + 4098.75 + 12900 + 26712 + THIRTYTHREE * (taxableIncomes - 183250);
            println("You owe: $" + df.format(tax));
        }
        if (taxableIncomes > 398350 && taxableIncomes <= 400000)
        {
            tax = 892.5 + 4098.75 + 12900 + 26712 + 70983 + THIRTYFIVE * (taxableIncomes - 183250);
            println("You owe: $" + df.format(tax));
        }
        if (taxableIncomes > 400000)
        {
            tax = 892.5 + 4098.75 + 12900 + 26712 + 70983 + 577.5 + THIRTYNINE * (taxableIncomes - 183250);
            println("You owe: $" + df.format(tax));
        }   
        break;

并复制并粘贴案例0下的所有代码:它告诉我需要类、接口或枚举。

“需要类、接口或枚举”是一个语法错误。不要将其与如何构造代码混淆。从编译开始——理解并修复您遇到的每个错误。然后找出如何更好地构造它,并添加其余的功能。我让程序在每种情况下都能正常工作,并且没有编译错误。只有当我尝试将代码移动到不同的方法中,然后在每种情况下调用它们时,它才会停止工作。你需要弄清楚“停止工作”意味着什么,并解决任何问题。对我来说,将每个案例分为不同的方法的最佳方式是什么?我曾经尝试使用一个私有的方法来征税,使用taxableIncomes作为一个参数,但我不能在该方法的末尾返回税款,因为它一直告诉我“找不到可变税”,我认为这是因为每个if语句中都定义了税。我该如何报税,以便它识别由依赖于taxableIncomes的if语句确定的可变税?我写了另一个标题,比如这个私有的double tax(double taxableIncomes),我使用double tax=tax(taxableIncomes)在案例0下调用该方法,但它一直告诉我它找不到可变税
private double tax()