我需要編寫一個程序,幫助便利店職員決定是否向顧客出售啤酒。啤酒只能賣給21歲或以上的人,並且有足夠的錢(啤酒成本爲5.00美元)。如果客戶太年輕,告訴他們在返回之前必須等待多少年。如果他們的錢太少,告訴他們需要多少錢。我不知道該怎麼做,請幫忙。編寫一個Java程序來幫助便利店職員決定是否向顧客出售啤酒?
import java.util.Scanner;
public class example1 {
public static void main (String [] args) {
Scanner scan = new Scanner (System.in);
int age;
double beerPrice;
double cash;
System.out.print("Please type customer age:");
age = scan.nextInt();
System.out.println();
System.out.print ("Type customer cash amount:");
cash= scan.nextDouble();
System.out.println();
if (age <= 21) {
System.out.println(21-age);
}
}
}
這就是我到目前爲止所做的。每次運行該程序時,如果年齡在21歲或以上,那麼當我不想要時它仍會打印年齡。請幫我完成這個程序。不要求出手。
對我的作品 - 不打印出來歲的時候我進入22.你確定你正在運行顯示的版本? – DNA 2015-03-02 17:15:24
謝謝大家的幫助! – Kyle 2015-03-02 17:32:37