-2
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");
}
}
用戶只需輸入服務的前3個字母並獲得他們輸入的服務及其匹配的價格。這是我的代碼到目前爲止。部分請求的輸出字
你的問題是什麼 –
用戶只需要輸入服務的前3個字母,並獲得他們輸入的服務及其匹配的價格。 – Jokes
你無法解釋你的問題 –