我正在創建一些代碼,用於向用戶顯示服務及其相應價格的array
。包含陣列和While循環的用戶輸入
每當用戶選擇的服務,我要顯示給用戶的服務的價格...
如果用戶希望進行用於將多個服務,我希望計算機問他們,直到他們另有說法。
此外,我需要使用累加器來添加用戶請求的服務的價格。
到目前爲止,這是我所:
import java.util.Scanner;
public class Assign3
{
public static void carMake(String bmw)
{
Scanner input = new Scanner(System.in);
//declare and intialize parallel arrays, Services and Prices and display them to the user
String[] services = {"Oil Change" , "Tire Rotation", "Air Filter", "Fluid Check"}; //intialize list of services
double[]price = {39.99, 49.99, 19.99, 10.99}; //initialize corresponding price for services
for(int i= 0; i < services.length; i++)
{
System.out.print(services[i]+ "....");
System.out.print(price[i] + "\t");
}
System.out.println("What service do you want done?: ");
String service= input.nextLine();
}
public static void main(String[]args)
{
String bmw = "fancy car";
carMake(bmw);
}
}
你的意思是類似這樣的東西:http://stackoverflow.com/questions/40689994/printing-all-the-items/ – DevilsHnd
,你也一樣例如,選項的狀態號碼油更換爲1或用戶是否必須鍵入「換油」?你將如何記住用戶的選擇? –
用戶將不得不輸入換油信息。 我希望系統使用累加器(i ++)來添加用戶想要完成的每個服務,並在他們選擇了他們想要的所有服務時給它們一個通用服務。 –