Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:15:58+00:00 2026-06-02T09:15:58+00:00

Now that I can successfully iterate through my loop of possible valid toppings I

  • 0

Now that I can successfully iterate through my loop of possible valid toppings I am not able to add the 0.75 surcharge for toppings in my program. I was hoping you could tell me why that is. The program in its entirety is at the bottom. The two parts which concern me are

public class TestPizza
{
  public static void main(String args[])
  {
    int x;
    String top[] = {"Mushrooms", "Onions", ""};
    Pizza one = new Pizza();
    Pizza two = new Pizza();
    Pizza three = new Pizza();

one.setSize(12);
one.addTopping(top);
one.showValues();

  }
}

And

// setPrice() assigns a price to the pie
public void addTopping(String programToppings[])
{
  for(int x = 0; x < 3; x++)
  {
    toppings[x] = programToppings[x];
  }
  for(int x = 0; x < 3; x++)
  {
    toppings[x] = toppings[x].toLowerCase();
  }
  for(int x = 0; x < 3; x++)
  {
    for(int xx = 0; xx < 6; xx++)
    {
      if(toppings[x].equals(validToppings[xx]))
      {price += 0.75;}
    }
  }
}

I do not see why the .equals method is not working and assigning the odd sum of change to the final price…

// This custom class is used to create Pie objects
// It stores the data about the Pie in four variables:
// size, price, type and baked
// It lets the program that creates the Pie object set these values using four methods:
// setSize, setPrice, setType and bake

public class Pizza
{

  // Declare four variables that can store the values for each pie
  // Each Pie object will have their own, separate copy of these variables 12.
    private int size;
    private double price;
    private boolean baked;
    private int x;
    private int xx;
    private String validToppings[] = new String[6];
    private String toppings[] = new String[3];


    // The "constructor" method is called when a new pie
    // object is first created. We use it to set "default" values.
    // Our typical pie is 10 inches, costs $8 and is not baked yet
    // We don't yet know what the pie filling will be
    Pizza()
    {
      size = 8;
      price = 10.0;
      baked = false;
      String validToppings[] = {"mushrooms", "pepperonis", "onions", "mushroom", "pepperoni", "onion"};
      String toppings[] = new String[3];
    }

    // showValues() is a void method that displays the values of the
    // current Pie
    public void showValues()
    {
      System.out.println("Pie Size: " + size);
      for(int x = 0; x < 3; x++) {System.out.println("With " + toppings[x]);};
      System.out.println("Price of Pie: $" + price);
    }

    // getSize() returns the size of the pie
    public int getSize()
    {
      return size;
    }
    // getPrice() returns the price of the pie
    public double getPrice()
    {
      return price;
    }
    // baked() returns whether or not the pie is baked
    public boolean getBaked()
    {
      return baked;
    }
    // setSize() assigns a size to the pie
    public void setSize(int thisSize)
    {
      size = thisSize;
      switch(size)
      {
        case 8: price = 10.00; break;
        case 12: price = 14.00; break;
        case 16: price = 18.00; break;
        default: System.out.println("Error in Pizza class: Attempt to set invalid Pizza size."); break;
      }
    }

    // setPrice() assigns a price to the pie
    public void addTopping(String programToppings[])
    {
      for(int x = 0; x < 3; x++)
      {
        toppings[x] = programToppings[x];
      }
      for(int x = 0; x < 3; x++)
      {
        toppings[x] = toppings[x].toLowerCase();
      }
      for(int x = 0; x < 3; x++)
      {
        for(int xx = 0; xx < 6; xx++)
        {
          if(toppings[x].equals(validToppings[xx]))
          {price += 0.75;}
        }
      }
    }

  public void bake()
  {
    baked = true;
  };

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:16:02+00:00Added an answer on June 2, 2026 at 9:16 am
     Pizza()
    {
      size = 8;
      price = 10.0;
      baked = false;
      String validToppings[] = {"mushrooms", "pepperonis", "onions", "mushroom", "pepperoni", "onion"};
      String toppings[] = new String[3];
    }
    

    Here,

    String validToppings[] = {"mushrooms", "pepperonis", "onions", "mushroom", "pepperoni", "onion"};
    

    is local to the constructor and no way connected to the global ‘validToppings[]’. Look into it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im working right now on a program that can divide, add, ect, but, im
Now while I know that you can not perform inheritance like you would in
I've successfully built a program that can read Mifare 1K Card using Qt on
Now that I can make useful user controls in WPF (thanks to this stackoverflow
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Following on from this question I now have code that can attach to a
Now that I know I can no longer communicate with Twitter mashups out there,
I read somewhere (can't find it now) that large exception hierarchies are a waste
Other than that I don't know if I can reproduce it now that it's
I understand that you can now create MVC-specific user controls, but will my existing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.