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 7828519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:23:10+00:00 2026-06-02T10:23:10+00:00

The entirety of my programs are below. The problem I am having is that

  • 0

The entirety of my programs are below.

The problem I am having is that my stdout gets flooded by the error messages produced by this particular line of code.

  for(int x = 0; x < 3; x++)
  {
    for(int xx = 0; xx < 6; xx++)
    {
      if(toppings[x].equalsIgnoreCase(validToppings[xx]))
      {price += 0.75;} else {System.out.println("Error in Pizza class: Attempt to set invalid pizza topping " + toppings[x]);};
    }
  }

I would rather not re-write my code that I spent lots of time perfecting, but if I must use a switch statement or something of the like to get a concise error message I will. Although I think my current method is best.

The following is the test for the class,

public class TestPizza
{
  public static void main(String args[])
  {
    int x;
    String t1[] = {"Mushrooms", "Onions", ""};
    String t2[] = {"Pepperoni", "Mushrooms", ""};
    String t3[] = {"Pepperoni", "Mushrooms", "Onions"};
    String t4[] = {"Sausage", "", ""};
    Pizza one = new Pizza();
    Pizza two = new Pizza();
    Pizza three = new Pizza();
    Pizza four = new Pizza();

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

two.setSize(8);
two.addTopping(t2);
two.showValues();

three.setSize(16);
three.addTopping(t3);
three.showValues();

four.setSize(20);
four.addTopping(t4);
four.showValues();

  }
}

This is the class.

// 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[] = {"mushrooms", "pepperonis", "onions", "mushroom", "pepperoni", "onion"};
    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 = 999;
      price = 999;
      baked = false;
    }

    // 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++) {if(toppings[x] != ("")) {System.out.println("With " + toppings[x]);}};
      System.out.println("Price of Pie: $" + price + "\n\n");
    }

    // 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].equalsIgnoreCase(validToppings[xx]))
          {price += 0.75;} else {System.out.println("Error in Pizza class: Attempt to set invalid pizza topping " + toppings[x]);};
        }
      }
    }

  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-02T10:23:11+00:00Added an answer on June 2, 2026 at 10:23 am
      boolean error = false;
      for(int x = 0; x < 3; x++)
      {
        for(int xx = 0; xx < 6; xx++)
        {
          if(toppings[x].equalsIgnoreCase(validToppings[xx]))
          {price += 0.75;} else {error = true;};
        }
      }
      if(error){
        System.out.println("Error in Pizza class: Attempt to set invalid pizza topping");
      }
    

    If you want to keep the topping information aswell, you need to store each topping in a list (just add each time error is set to true), then iterate over that list in the if(error) statement.

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

Sidebar

Related Questions

I am having some difficulty compiling a C++ program that I've written. This program
I would usually search for this error. But in VS C++ Express, this error
I have a program that wants to be called from the command line many
I have a C shell script that calls two C programs - one after
So this one is sort of a language agnostic question that I don't really
After weeks of effort I have managed to write F# programs that use LLVM
I'm working on a practice problem set for C programming, and I've encountered this
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
Do system calls execute in the context of a software interrupt handler in entirety?
Not entirely sure of a good title for this, feel free to edit it

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.