当前位置:编程学习 > JAVA >>

求找逻辑错误

这是一台用于售卖机的程序,这个程序只是给出了金额部分.
用户总共五个选项,前四个是投入不同价值的货币,如果投入超过了价格,系统会提供找零
第五个选项的用处是在达到规定金额之前选择取消,则会显示应该退还你已经投入的金额.
求找出四个逻辑错误,这个是我们考试题啊~求大神帮助啊~


public void dispenseItem(double price)
{
double amount = 0;
char choice = ' ';
do
{
System.out.println("A. $1.00");
System.out.println("B. $0.50");
System.out.println("C. $0.20");
System.out.println("D. $0.10");
System.out.println("Z. Cancel");
System.out.print("Please select: ");
choice = console.nextLine().charAt(0);
switch(choice)
{
case 'A': amount += 1.00;break;
case 'B': amount += 0.50;break;
case 'C': amount += 0.20;break;
case 'D': amount += 0.10;
case 'Z': break;
default: System.out.print("Invalid – Press enter to continue");
console.nextLine();
}
}while(choice != 'Z' || amount < price);
if(choice == 'Z')
{
System.out.println("Item ready!");
}
else
System.out.println("Item cancelled!");
if((choice=='Z'&& amount > 0)||(choice != 'Z' && amount > price))
{
if( choice != 'Z')
amount -= amount;
System.out.println("Your change is $" + amount);
}
System.out.print("Press enter to continue");
console.nextLine();
}
Java switch --------------------编程问答-------------------- 没人么...自己顶一下 --------------------编程问答-------------------- case 'D': amount += 0.10; 后面没有break。。 --------------------编程问答-------------------- while (choice != 'Z' && amount < price); --------------------编程问答-------------------- if (choice != 'Z') {
System.out.println("Item ready!");
} else
System.out.println("Item cancelled!"); --------------------编程问答-------------------- 34行:amount -= price
还有 2,3,4 楼所说的
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,