急!java的自动售货机找零程序

急!java的自动售货机找零程序,第1张

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 cost&paid 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(change<0)//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.")

}

}

}

X1,X2,X3分别检测到1、5、10元;X4汽水按钮,X5咖啡按钮,X7找零按钮;

Y1汽水灯,Y2咖啡灯,Y3汽水阀,Y4咖啡按阀,Y5找零等,Y6找零阀;


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/11306917.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存