0

所以我应该为我的编程课程实验室的介绍制作一台自动售货机。到目前为止,这就是我的 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 完成这个实验,有人有什么建议吗?

4

1 回答 1

2

我的猜测是程序正在启动,但您没有意识到它,因为它正在等待输入。

移动包含扫描输入System.out.print("Enter Price for your item" + "30" );上方的行。keyboard.nextInt像这样:

System.out.print("Enter Price for your item" + "30" );
int cost = keyboard.nextInt ();
于 2012-10-05T23:27:27.070 回答