I am trying to create a code that allows users to input an item that potentially matches an array item. If it matches the array, it should output the price of the item from a parallel array. If the input item doesn't match the array, the output should be an error message. When I run it, it only returns the error message. Please see code below:
import javax.swing.*;
public class JumpinJive {
static String addIn;
static String QUIT = "xxx";
static final int NUM_ITEMS = 5;
static String addIns[] = {"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"};
static double addInPrices[] = {.89, .25, .59, 1.50, 1.75};
static boolean foundIt;
static int x; //loop control variable
static double orderTotal = 2.00 ; //all orders start with a $2.00 charge
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
addIn = JOptionPane.showInputDialog("Enter coffee add-in or" + QUIT + "to quit: ");
while (addIn != QUIT){
findAddin();
}
System.exit(0);
}
private static void findAddin() {
// TODO Auto-generated method stub
foundIt = false;
for (x = 0; x < NUM_ITEMS; x++){
if (addIn == addIns[x])
{
foundIt = true;
orderTotal += addInPrices[x];
System.out.println("The price for your " + addIns[x] + " coffee is : $ "+ orderTotal );
}
else if (foundIt == false)
{
System.out.println("Sorry, this add-in is not available. Please try again.");
addIn = JOptionPane.showInputDialog("Enter nextcoffee add-in or " + QUIT + " to quit: ");
}
else{
addIn = JOptionPane.showInputDialog("Enter next coffee add-in or " + QUIT + " to quit: ");
}
}
}
}