)补全程序实现自动投币售货机功能,要求如下:(提供部分功能程序)投币金额接收2或3元2元矿泉水选择商品有(1)净净矿泉水,(2)甜甜矿泉水和(3)美美矿泉水之一3元饮料选择商品有(1)爽口可乐,(2)清凉雪碧,和(3)雪山果汁之一要求有金额不符和选择错误提示功能importjava.util.Scanner;publicclassMachineSell{publicstaticvoidmain(Stringargs[]){intmoney;intdrinkKind;System.out.printf("投入金额:2或3元(回车确认):");Scannerreader=newScanner(System.in);money=reader.nextInt();//【补全功能代码】
时间: 2023-05-14 11:05:40 浏览: 102
import java.util.Scanner;
public class MachineSell {
public static void main(String args[]) {
int money;
int drinkKind;
System.out.printf("投入金额:2或3元(回车确认):");
Scanner reader = new Scanner(System.in);
money = reader.nextInt();
if (money != 2 && money != 3) {
System.out.println("金额不符,请重新投币");
return;
}
if (money == 2) {
System.out.println("请选择矿泉水:1.净净矿泉水 2.甜甜矿泉水 3.美美矿泉水");
drinkKind = reader.nextInt();
if (drinkKind == 1) {
System.out.println("净净矿泉水出货");
} else if (drinkKind == 2) {
System.out.println("甜甜矿泉水出货");
} else if (drinkKind == 3) {
System.out.println("美美矿泉水出货");
} else {
System.out.println("选择错误,请重新选择");
}
} else if (money == 3) {
System.out.println("请选择饮料:1.爽口可乐 2.清凉雪碧 3.雪山果汁");
drinkKind = reader.nextInt();
if (drinkKind == 1) {
System.out.println("爽口可乐出货");
} else if (drinkKind == 2) {
System.out.println("清凉雪碧出货");
} else if (drinkKind == 3) {
System.out.println("雪山果汁出货");
} else {
System.out.println("选择错误,请重新选择");
}
}
}
}
阅读全文