所以我应该为我的编程课程实验室的介绍制作一台自动售货机。到目前为止,这就是我的 Java 代码的样子。
import java.util.Scanner;
public class VendingMachine
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
final int quarter = 25;
final int dime = 10;
final int nickel = 15;
int cost = keyboard.nextInt ();
int totalChange = 100 - cost;
int totalQuarters= totalChange/quarter;
totalChange = totalChange % quarter;
int totalDimes = totalChange/dime;
totalChange = totalChange % dime;
int totalNickels = totalChange/nickel;
totalChange = totalChange % nickel;
System.out.print("Enter Price for your item" + "30" );
}
}
我需要它做的是这个。
Enter a price for item (from 25 cents to a dollar, in 5-cent increments): 45
You bought and item for 45 cents and gave me a dollar, so your change is
2 quarters,
0 dimes, and
1 nickels.
使用值 30、65 和 100。由于某种原因,程序不会在 Blue J 中启动..所以我知道推荐使用 Eclipse,但我想我想用 Blue J 完成这个实验,有人有什么建议吗?