Try to search your question here, if you can't find : Ask Any Question Now ?

Identifier Expected Error in Pizza Class Problem

HomeCategory: stackoverflowIdentifier Expected Error in Pizza Class Problem
Avatargaurav asked 4 months ago

I keep getting an identifier expected error where it says “public double calcTotal(calcCost){” towards the end of my code. Note that I’m calling a method from a different class. What is the problem there? Also, please feel free to point out any other errors you see in my code. I’m scared that once I fix this one error, 10 more will pop up when I try to compile again. Thank you!

public class PizzaOrder {
  private String [] m_Pizza; //array for base type Pizza
  private int m_numPizzas;

  //default constructor
  public PizzaOrder() {
    m_Pizza = null;//new String[0]
    m_numPizzas = 0;

  //overloaded Pizza
  public PizzaOrder(String [] Pizza, int numPizzas) {
    m_Pizza = Pizza;
    m_numPizzas = numPizzas;

  //public methods
  public void setPizza (String [] Pizza){
    m_Pizza = Pizza;
  public String getPizza () {
    return m_Pizza;
  public void setNumPizzas (int numPizzas) {
    m_numPizzas = numPizzas;
  public int getNumPizzas () {
    return numPizzas;

  public void addPizza(Pizza pizza) {
    if (m_Pizza.length() <= m_numPizzas) {
      m_Pizza.length() = m_numPizzas;
      //m_Pizza[m_numPizzas] = Pizza; //pizza array has same amount of items as numPizzas
    else {
      System.out.println("Adding an additional pizza was unuccessful.");

public double calcTotal(calcCost){
    double totalCost = 0;
    double Cost = calcCost(); //calling calcCost function
    for (int i = 0; i < m_Pizza.length(); i++) { //goes through array
      calcCost(m_Pizza[i]); //calculates cost for each pizza in array
      Cost += totalCost; //adds each cost to total
    return totalCost;

  public String toString() {
    double total = calcTotal(calcCost); //stores calcTotal function in total variable
    System.out.println("You ordered a " + m_Pizza + ". Your total cost is: " + total);

1 Answers
Best Answer
AvatarMikhail answered 4 months ago
Your Answer

13 + 8 =

Popular Tags

WP Facebook Auto Publish Powered By :