当前位置: 首页 > 知识库问答 >
问题:

参数不能解析为变量?

郎刚捷
2023-03-14

这是一个相当基本的程序。当我尝试打印SummaryOutput方法和BillOutput方法时,我会出现错误,表示参数不能解析为变量。

public class PizzaDriver{

    public static void main(String[] args) {
          PizzaOrder order = new PizzaOrder(); 
          PizzaOutput output = new PizzaOutput();
          PizzaInput input = new PizzaInput(); 

          System.out.println(output.menuOutput()); 
          input.readInput(order); 

          System.out.println(summaryOutput1 = output.summaryOutput (numCheese, numPepperoni, numSausage, numVegetarian));
          System.out.println(output.billOutput(String billOutput));
    }
}

公共类PizzaOutput{

public String menuOutput()
{
    String menuOutput1 = "Item        \t Price \nCheese  \t $2.40 \n Sausage \t $3.00 \nPepperoni \t $3.00 \nVegertarian \t $3.00";

    return menuOutput1;

}

public void summaryOutput(int numCheese,int numPepperoni,int numSausage,int numVegetarian)
{
    System.out.println("Cheese: " + numCheese); 

    System.out.println("Pepperoni: " + numPepperoni); 

    System.out.println("Sausage: " + numSausage);

    System.out.println("Vegetarian: " + numVegetarian);


}

public void billOutput(double subTotal, double tax, double carryOut, double totalBill)
{
    System.out.println("Subtotal : " +subTotal);

    System.out.println("Tax : " + tax);

    System.out.println("carryOut : " +carryOut);

    System.out.println("Total Bill: " + totalBill);
}

导入java.util.scanner;

公共类PizzaInput{Scanner键盘=新扫描器(System.in);

public int numCheese, numPepperoni, numSausage, numVegetarian; 



public void readInput(PizzaOrder order)
{
    System.out.print("How many Cheese Pizzas would you like?");
    int numCheese = keyboard.nextInt(); 

    order.setCheese(numCheese); 

    System.out.print("How many Pepperoni pizzas would you like?");
    int numPepeperoni = keyboard.nextInt(); 

    order.setPepperoni(numPepperoni);

    System.out.print("How many Sausage pizzas would you like?");
    int numSausage = keyboard.nextInt(); 

    order.setSausage(numSausage);

    System.out.print("How many Vegetarian pizzas would you like?");
    int numVegetarian = keyboard.nextInt(); 

    order.setVegetarian(numVegetarian);



    }

}

公共级披萨订单{私人最终双份奶酪价格=2.40;

private final double PEPPERONI_PRICE = 3.00;

private final double SAUSAGE_PRICE = 3.00;

private final double VEGETARIAN_PRICE = 3.50; 

private final double SALES_TAX = .025; 

private final double CARRY_OUT = .10; 


public int numCheese, numPepperoni, numSausage, numVegetarian; 


public int getCheese()
{
    return numCheese; 
}

public void setCheese(int numCheese)
{
    this.numCheese=numCheese;
}


public int getPepperoni()
{
    return numPepperoni; 
}

public void setPepperoni(int numPepperoni)
{
    this.numPepperoni=numPepperoni; 
}


public int getSausage()
{
    return numSausage; 
}

public void setSausage(int numSausage)
{
    this.numSausage= numSausage; 
}

public int getVegetarian()
{
    return numVegetarian; 
}

public void setVegetarian(int numVegetarian)
{
    this.numVegetarian = numVegetarian; 
}






public double calculateSubTotal()
{
    double cheeseTotal= numCheese * CHEESE_PRICE; 

    double pepperoniTotal = numPepperoni * PEPPERONI_PRICE; 

    double sausageTotal = numSausage * SAUSAGE_PRICE; 

    double vegetarianTotal = numVegetarian * VEGETARIAN_PRICE; 

    double subTotal = cheeseTotal + pepperoniTotal + sausageTotal + vegetarianTotal; 

    double tax = (subTotal) * SALES_TAX; 

    double totalBill = (tax + subTotal) * CARRY_OUT; 

    return totalBill; 

}

共有1个答案

拓拔弘亮
2023-03-14

在调用方法而不是定义方法时,从下面一行中删除“string”。而且,billoutput已经执行了两次。避免名称冲突。

System.out.println(output.billOutput(String billOutput));
 类似资料:
  • 对不起,我不知道这个问题的标题是什么。 我在C中有一个函数,它以λ作为参数。 然后我尝试调用这个函数。 我的问题是,我无法从lambda函数内部访问变量,如果我试图用

  • Windows 10、Visual Studio 2019、C 17: 编译错误:无法将参数2从“int(\u cdecl*)(int)”转换为“…” 如果没有模板(int func(int size)),代码编译正常。如何修改它以使编译器理解可变参数?

  • 我有一个jsp proyect作为表示层来显示来自java类的函数的结果(一个简单的字符串)。该类位于src目录中。 我没有用Eclipse创建这些类。它们来自另一个项目,但它们都放在src目录中(java类的位置)。jsp似乎无法识别它们。

  • 我对JSP是新手。我正在学习useBean方法,在 http://www.studytonight.com/jsp/getproperty-tag.php 我得到了一个错误:在jsp文件中:/hello1的第5行发生了一个错误。jsp PersonBean无法解析为类型