package com.test;
成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供常熟網(wǎng)站建設(shè)、常熟做網(wǎng)站、常熟網(wǎng)站設(shè)計、常熟網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、常熟企業(yè)網(wǎng)站模板建站服務(wù),十年常熟做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
import java.util.Scanner;
import com.sun.java_cup.internal.internal_error;
public class Demo {
/**
* @param args
*/
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int c;
int gum=0,cho=0,pop=0,jui=0;
do{
Demo.play_bord();
c=s.nextInt();
if(c0||c6){
System.out.println("1-6 only ,input a new choice");
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("****這是簡易售貨機(jī),請按下數(shù)字選擇服務(wù)*****");
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("***************************");
}
}
剛好以前寫了個 改完給你了
//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("芬達(dá)",?40,?3.0,?2);
blacktea?=?new?Drink("紅茶",?30,?4.0,?3);
greentea?=?new?Drink("綠茶",?20,?5.0,?4);
money?=?500;
for()
{
System.out.println("-------------自動售貨機(jī)-------------");
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("請輸入要執(zhí)行的操作序號:");
Scanner?scannerIndex?=?new?Scanner(System.in);
int?indexScanner?=?scannerIndex.nextInt();
switch(indexScanner)
{
case?1:
System.out.println("請選擇購買的飲料(1.可樂,2.芬達(dá),3紅茶,4.綠茶):");
Scanner?numberScanner?=?new?Scanner(System.in);
int?buyIndex?=?numberScanner.nextInt();
Drink?drink?=?getDrink(buyIndex);
System.out.println("請輸入購買的數(shù)量:");
Scanner?countScanner?=?new?Scanner(System.in);
int?buyCount?=?countScanner.nextInt();
if?(buyCount??0)
{
System.out.println("您選擇了"?+?buyCount?+?"瓶"?+?drink.getName()?+?"."?);
System.out.println("總價格:"?+?drink.getPrice()?*?buyCount?+?"元,請投入1元或5元紙幣。");
System.out.println("確定購買?(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("輸入的數(shù)量有誤!");
break;
case?2:
System.out.println("請輸入管理員密碼:");
Scanner?pwScanner?=?new?Scanner(System.in);
int?password?=?pwScanner.nextInt();
if?(password?==?123)
{
System.out.println("密碼正確,目前的余額為:"?+?money?+?"元。");
}
else
System.out.println("密碼錯誤。");
break;
case?3:
break;
default:
System.out.println("請輸入正確的數(shù)字。");
break;
}
}
}
public?static?Drink?getDrink(int?drinkIndex)
{
Drink?drink?=?null;
switch(drinkIndex)
{
case?1:
drink?=?cola;
System.out.println("您選擇了可樂。");
break;
case?2:
drink?=?fanta;
System.out.println("您選擇了芬達(dá)。");?
break;
case?3:
drink?=?blacktea;
System.out.println("您選擇了紅茶。");
break;
case?4:
drink?=?greentea;
System.out.println("您選擇了綠茶。");
break;
default:
//drink?=?null;
System.out.println("輸入錯誤,請輸入1~4的數(shù)字!");
}
return?drink;
}
}
//創(chuàng)建的Drink類文件Drink.java
package?cn.zhouhan;
public?class?Drink?{
private?String?name;
private?int?number;
private?double?price;
private?double?drinkMoney;
private?int?index;
public?Drink(String?name,?int?number,?double?price,?int?index)
{
this.name?=?name;
this.number?=?number;
this.price?=?price;
this.drinkMoney?=?number?*?price;
this.index?=?index;
}
public?String?getName()
{
return?this.name;
}
public?int?getNumber()
{
return?this.number;
}
public?double?getPrice()
{
return?this.price;
}
public?void?sellDrink(int?count)
{
this.number?-=?count;
this.drinkMoney?+=?this.price?*?count;
}
public?void?UserPrintDrinkInfo()
{
System.out.println("品名:"+?this.name?+",單價:"?+?this.price?+?"元,剩余數(shù)量:"?+?this.number?+?"瓶。");
}
}
public class Change {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("The goods cost:");
int cost=sc.nextInt();
System.out.print("The customer paid:");
int paid=sc.nextInt();
change(cost,paid);
}
public static void change(int cost,int paid){
//unit of costpaid is dollar
int change=(paid-cost)*100;
int numOfTF=0;//number of 25 cents
int numOfT=0;//number of 10 cents
int numOfF=0;//number of 5 cents
if(change0)//payment is not enough
System.out.println("payment is not enough");
else{
numOfTF=(int)change/25;
numOfT=(int)(change-numOfTF*25)/10;
numOfF=(int)(change-numOfTF*25-numOfT*10)/5;
System.out.println("Change is: "+numOfTF+" 25 cents, "+numOfT+" 10 cents, "+numOfF+" 5 cents.");
}
}
}
我說,這位同學(xué),你們學(xué)校布置的題目你們怎么都來這索取答案來了。怎么不自己動手做做,而且你這里需要一個郵箱接收才行,你這樣裸問讓人很奇怪 ~