User should only have to input the first 3 letters of the service and get the service they entered and its matching price.
Here is my code so far, during research I saw things about using range or index. I'm thinking I need to use range but how do I accomplish this with String value?
import javax.swing.*;
public class CarCareChoice2
{
public static void main(String[] args)
{
final int NUM_OF_ITEMS = 8;
String[] validChoices = {"oil change", "tire rotation", "battery check", "brake inspection"};
int[] prices = {25, 22, 15, 5};
String strOptions;
String careChoice;
double choicePrice = 0.0;
boolean validChoice = false;
strOptions = JOptionPane.showInputDialog(null, "Please enter one of the following care options: oil change, tire rotation, battery check, or brake inspection");
careChoice = strOptions;
for(int x = 0; x < NUM_OF_ITEMS; ++x)
{
if(careChoice.equals(validChoices[x]))
{
validChoice = true;
choicePrice = prices[x];
}
}
if(validChoice)
JOptionPane.showMessageDialog(null, "The price of a(an) " + careChoice + " is $" + choicePrice);
else
JOptionPane.showMessageDialog(null, "Sorry - invalid entry");
}
}