【发布时间】:2018-09-14 16:49:22
【问题描述】:
我正在学习高级编程课程,目前正在学习 Java。我们应该设计一家商店。我的部分代码遇到了一些麻烦。我决定开一家卖不同种类苹果的商店。如果您运行我的代码并输入苹果的名称以了解更多信息,程序将结束。我希望它循环回到询问您是否想了解任何一种苹果的部分。这是我目前所拥有的。
System.out.println("Bradley's Apple Store");
System.out.println(" ");
System.out.println("Today we have eight different kinds of apples. They are Alderman apples, Akane apples, Akero apples, Alkeme apples, Ambrosia Apples, Allington Pippin apples, and American Summer Pearmain apples");
System.out.println(" ");
System.out.println("If you would like to hear about any of the kinds of apples, type in the name of the apple. If you would just like to purchase apples, then type purchase.");
String input = scan.nextLine(); //For information on the apples
if (input.equalsIgnoreCase("Alderman"))
System.out.println("An English (possible Scottish) culinary apple, thought to have originated in the 1920s. $4.00/lb");
if (input.equalsIgnoreCase("Akane"))
System.out.println("One of the best early-season apples, better known in the USA than Europe, but would appeal to European tastes too. $6.00/lb");
if (input.equalsIgnoreCase("Akero"))
System.out.println("An heirloom apple variety from Sweden, quite widely grown in Scandanavia, very handsome fruit. $2.00/lb");
if (input.equalsIgnoreCase("Alkeme"))
System.out.println("A very attractive early Cox-style apple, slightly sharper than Cox, sometimes known as Early Windsor. $9.00/lb");
if (input.equalsIgnoreCase("Ambrosia"))
System.out.println("A sweet modern apple variety from western Canada, quite similar to Golden Delicious. Discovered as a chance seedling in an orchard in British Columbia. $7.00/lb");
if (input.equalsIgnoreCase("Allington Pippin"))
System.out.println("A versatile English apple, with a strong pineapple-like flavour, useful for both cooking and eating. $3.00/lb");
if (input.equalsIgnoreCase("American Summer Pearmain"))
System.out.println("An excellent early eating apple, also good for cooking. Medium size, yellow-green fruit is flushed and streaked red to purple red. Sweet, very juicy flesh. $25.00/lb");
if (input.equals("purchase"))
System.out.println("What would you like to buy?: ");
}
}
感谢您的帮助。
【问题讨论】:
-
while 循环应该可以解决问题
-
使用
while循环