Code works great with integer type array but I need string type or at least when the user enters S...M... for small...or medium (size of pizza) the program displays the price...
Cant seem to make the array sting type and it have it work successfully...
thank you...
import javax.swing.*;
public class PizzaChoice
{
public static void main(String[] args)
{
final int NUMBER_OF_ITEMS = 4;
int[] validValues = {1, 2, 3, 4}; // IF THIS COULD HAVE S, M, L, X, BUT IVE BEEN UNLUCKY FOR ATLEAST 30 HRS
double[] prices = {6.99, 8.99, 12.50, 15.00};
String strItem;
double itemOrdered;
double itemPrice = 0.0;
boolean validItem = false;
strItem = JOptionPane.showInputDialog(null,
" Enter a letter code for the your size of pizza: \n S = Small \n M = Medium \n L = Large \n X = Extra large ");
itemOrdered = Integer.parseInt(strItem);
for(int x = 0; x < NUMBER_OF_ITEMS; ++x)
{
if(itemOrdered == validValues[x])
{
validItem = true;
itemPrice = prices[x];
}
}
if(validItem)
JOptionPane.showMessageDialog(null, "The price for item " +
itemOrdered + " is $" + itemPrice);
else
JOptionPane.showMessageDialog(null,
"Sorry - invalid item entered");
}
}

New Topic/Question
Reply
MultiQuote









|