c=s.nextInt();
}
switch(c){
case 1:
System.out.println("here is your gum");
gum++;
break;
case 2:
System.out.println("here is your chocolate");
cho++;
break;
case 3:
System.out.println("here is your popcorn");
pop++;
break;
case 4:
System.out.println("here is your juice");
jui++;
break;
case 5:
System.out.println(gum+" gum are sold");
System.out.println(cho+" chocolate are sold");
System.out.println(pop+" popcorn are sold");
System.out.println(gum+" juice are sold");
break;
case 6:
System.out.println("system exit");
}
}while(c!=6);
}
public static void play_bord(){
System.out.println("****这是简易售货机,请按下数字选择服务*****");
System.out.println("[1]:get gum");
System.out.println("[2]:get chocolate");
System.out.println("[3]:get popcorn");
System.out.println("[4]:get juice");
System.out.println("[5]:dispaly totalsold");
System.out.println("[6]:quit");
System.out.println("***************************");
}
}
刚好以前写了个 改完给你了
求一个简易自动售货机的代码(java)要用创建类封装性,输出的时候要有提示语句 , 代码类似以下图片//Example类文件Example.java
package cn.zhouhan;
import java.util.Scanner;
public class Example {
static Drink cola, fanta, blacktea, greentea;
static int money;
public static void main(String[] args) {
// TODO Auto-generated method stub
cola = new Drink("可乐", 50, 2.0, 1);
fanta = new Drink("芬达", 40, 3.0, 2);
blacktea = new Drink("红茶", 30, 4.0, 3);
greentea = new Drink("绿茶", 20, 5.0, 4);
money = 500;
for(;;)
{
System.out.println("-------------自动售货机-------------");
cola.UserPrintDrinkInfo();
fanta.UserPrintDrinkInfo();
blacktea.UserPrintDrinkInfo();
greentea.UserPrintDrinkInfo();
System.out.println("----------------------------------");
System.out.println("1.购买饮料");
System.out.println("2.管理员查询");
System.out.println("3.返回");
System.out.println("请输入要执行自助售货机java代码的操作序号自助售货机java代码:");
Scanner scannerIndex = new Scanner(System.in);
int indexScanner = scannerIndex.nextInt();
switch(indexScanner)
{
case 1:
System.out.println("请选择购买的饮料(1.可乐自助售货机java代码,2.芬达自助售货机java代码,3红茶,4.绿茶):");
Scanner numberScanner = new Scanner(System.in);
int buyIndex = numberScanner.nextInt();
Drink drink = getDrink(buyIndex);
System.out.println("请输入购买的数量:");
Scanner countScanner = new Scanner(System.in);
int buyCount = countScanner.nextInt();
if (buyCount0)
{
System.out.println("您选择了" + buyCount + "瓶" + drink.getName() + "." );
System.out.println("总价格:" + drink.getPrice() * buyCount + "元 , 请投入1元或5元纸币 。");
System.out.println("确定购买自助售货机java代码?(1.确定,2.退款):");
Scanner sureScanner = new Scanner(System.in);
int sure = sureScanner.nextInt();
if (sure == 1)
{
drink.sellDrink(buyCount);
money += drink.getPrice() * buyCount;
System.out.println("您购买了" + buyCount + "瓶" + drink.getName() + " , 交易成功." );
}
if (sure ==2 )
{
System.out.println("退款成功!");
}
}
else
System.out.println("输入的数量有误!");
break;
case 2:
System.out.println("请输入管理员密码:");
Scanner pwScanner = new Scanner(System.in);
int password = pwScanner.nextInt();
推荐阅读
- java源代码怎么移植到,java源代码怎么移植到数据库
- 怎么查看加显卡的真实型号,怎么看自己的显卡型号
- 疯狂游戏厅单机,疯狂游戏厅单机内购版
- 如何下载煤炉电商,煤炉怎么下单
- c语言自动求和函数 c语言自动求和函数是什么
- oracle查询表的建表语句,oracle怎么看建表语句
- ppt中如何显示图表数据,ppt怎么用图表体现数据
- java清除键盘缓存代码 java清理
- wordpress小工具点,wordpress小程序插件