2012-10-05 38 views
0

所以我應該爲我的介紹編程類實驗室做一個自動售貨機。到目前爲止,這是我的Java代碼的樣子。基本的Java程序不會運行在Blue-J

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。出於某種原因,在藍J..so程序將無法啓動,我知道Eclipse的建議,但我認爲我要完成這個實驗與藍Ĵ,任何人有任何提示?

+0

我們不是在這裏爲他人填寫作業! (因爲作業標籤已被棄用...沒有意義!) – t0mm13b

回答

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(); 
+0

是啊,看起來像是這個問題,謝謝! –

+0

你能幫我解決我的問題嗎? –

+0

@liam有什麼問題嗎? –