So for my java class I have to write a program that accepts toppings and adds 75 cents to total price for every topping. I haven’t bothered for null testing yet because of this error. Essentially I will have:
list1 = Valid Toppings
list2 = User Toppings
User toppings can be entered in any order so it doesn’t make any sense to match them as a parallel array. You can see the logic I have used in the code snippet below, but it is not legal. My terminal vomits everywhere when I try to compile. How would I go about implementing the logic below, or perhaps a better way of implementing my logic completely?
for(x = 0; toppings.length < 3; x++)
{
if(toppings[x].equals(for(xx = 0; validToppings[0].length < 3; xx++) {validToppings[xx]})
{setSize(size); price += .75;}
else
{System.out.println("Error in Pizza class: Attempt to set invalid pizza topping" + x + "(" + toppings[x] + ")")};
}
I’m not sure what you’re trying to do. If you are trying to test whether one array of strings is in another array of strings, (as in, a ‘subset’ in Set Theory). Then why not use
ArrayList, something like this: (sorry if my syntax is a little off it’s been a while since I did java)