0
votes

This is a fairly basic program. When I try to print the summaryOutput method and billOutput method, I get errors saying the parameters cannot be resolved as a variable.

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

public class 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);
}

import java.util.Scanner;

public class PizzaInput { Scanner keyboard = new 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);



    }

}

public class PizzaOrder { private final double CHEESE_PRICE = 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; 

}

}

3
You are not having correct syntax for sysoutLokesh
where are your numcheese,numPepperoni declared and initialized? please edit that in your postVihar
I have 4 classes.The user inputs the values for these variables. I am new to this website and am not sure how to edit my post.user4068802

3 Answers

0
votes

Remove "String" from the following line as you are calling a method and not defining it. Also, billOutput has been twice. Avoid name collisions.

System.out.println(output.billOutput(String billOutput));
0
votes

when you say following

output.summaryOutput (numCheese, numPepperoni, numSausage, numVegetarian)

it will try to search the same variable name (numCheese, numPepperoni, numSausage, numVegetarian) in current method/class, which are not defined and hence it is not able to figure it out.

Please define those or else refer it properly

also ther is no definition for summaryOutput1 and as @pooja suggested

System.out.println(output.billOutput(String billOutput));//where is the param billOutput?

should be like

System.out.println(output.billOutput(billOutput));
0
votes

Go through the following code set and identify the changers that you have to do inside of your application

public class PizzaOutput {

    private int numCheese;
    private int numPepperoni;
    private int numSausage;
    private int numVegetarian;

    public PizzaOutput(){}

    public PizzaOutput(int numSausage, int numCheese, int numPepperoni, int numVegetarian) {
        this.numSausage = numSausage;
        this.numCheese = numCheese;
        this.numPepperoni = numPepperoni;
        this.numVegetarian = numVegetarian;
    }

    public int getNumCheese() {
        return numCheese;
    }

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

    public int getNumPepperoni() {
        return numPepperoni;
    }

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

    public int getNumSausage() {
        return numSausage;
    }

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

    public int getNumVegetarian() {
        return numVegetarian;
    }

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

    public String summaryOutput(int numSausage, int numCheese, int numPepperoni, int numVegetarian){
        setNumSausage(numSausage);
        setNumCheese(numCheese);
        setNumPepperoni(numPepperoni);
        setNumVegetarian(numVegetarian);

        return "Sausage : "+ getNumSausage()+ "  Cheese : "+getNumCheese()+ " Pepeeroni : "+ getNumPepperoni()+ " Vegetarian : "+getNumVegetarian();
    }

    public String billOutPut(String bOutput){
        // Enter here your code to get the bill
        return "Bill Output"; // return the bill as a String
    }
}

-> pay attention on the instance variables declaration
-> Your had not declared the return statements inside the both "summaryOutput" and "billOutPut" methods. Therefore you have to declare the return statement as a single statement
-> According to your code structure calling the both methods are enough to get the output and not need to call both methods inside the SOP