# Array Problem

• January 24th, 2010, 06:31 PM
KevinGreen
Array Problem
Hi everyone. I'm trying to finish up this bit of code for some homework, but I can't quite figure out where I'm going wrong. I can get the code to print out fine, but when it goes to itemPrice = validValue[x], it's not changing the price, and defaulting to 15.50. Can someone tell me where I'm going wrong? I don't need the answer, but a nudge in the right direction would be nice. Thanks!

Code :

```import javax.swing.*;   public class Main {   public static void main(String[] args) { final double NUMBER_OF_PIZZAS = 4; String[] validValues = {"S", "M", "L", "X"}; double[] prices = {6.99, 8.99, 12.50, 15.50}; String strItem; int entry; boolean validItem = false; double itemPrice = 0.0; strItem = JOptionPane.showInputDialog(null, "Enter the pizza size you want.\nS - Small\nM - Medium\nL - Large\nX - Extra Large");   for (int x = 0; x < NUMBER_OF_PIZZAS; ++x) { if (strItem.equalsIgnoreCase(validValues[x])) { validItem = true; itemPrice = prices[x]; }   }     if (validItem) { JOptionPane.showMessageDialog(null, "The price of a " + strItem + " pizza is \$" + itemPrice); } else { JOptionPane.showMessageDialog(null, "That's not a valid pizza"); } } }```
• January 24th, 2010, 06:45 PM
copeg
Re: Array Problem
The code you posted should work as expected, and just to be sure I ran it and it worked as expected.
• January 24th, 2010, 08:07 PM
KevinGreen
Re: Array Problem
I found an extra pair of brackets. I think my IDE might not have been compiling it correctly or something. Oh well. Thanks for your help!