2012-10-31 73 views
0

我得到一個錯誤,說「預期」。它在這裏代碼我得到它(* ****)。爲什麼我會得到預期的標識符。這是什麼

爲什麼我得到這個?即時通訊初學者,並堅持在這個問題上,並想知道我可以如何解決這個問題。爲什麼我得到一個標識符預計錯誤,我有*。這意味着什麼,我該如何解決這個問題? thankssss

/** 
* TicketMachine models a ticket machine that issues 
* flat-fare tickets. 
* The price of a ticket is specified via the constructor. 
* Instances will check to ensure that a user only enters 
* sensible amounts of money, and will only print a ticket 
* if enough money has been input. 
*/ 
public class TicketMachine 
{ 
// The price of a ticket from this machine. 
private int price; 
// The amount of money entered by a customer so far. 
private int balance; 
// The total amount of money collected by this machine. 
private int total; 

/** 
* Create a machine that issues tickets of the given price. 
*/ 
public TicketMachine(int cost) 
{ 
if (cost > 0) 
{ 
price = cost; 
balance = 0; 
total = 0; 
} 
else 
{ 
System.out.println("can not be minus"); 
} 
} 

/** 
* @Return The price of a ticket. 
*/ 
public int getPrice() 
{ 
return price; 
} 

/** 
* Return The amount of money already inserted for the 
* next ticket. 
*/ 
public int getBalance() 
{ 
return balance; 
} 

/** 
* Receive an amount of money from a customer. 
* Check that the amount is sensible. 
*/ 
public void insertMoney(int amount) 
{ 
if(amount > 0) { 
balance = balance + amount; 
} 
else { 
System.out.println("Use a positive amount rather than: " + 
amount); 
} 
} 

/** 
* Print a ticket if enough money has been inserted, and 
* reduce the current balance by the ticket price. Print 
* an error message if more money is required. 
*/ 
public void printTicket() 
{ 
if(balance >= price) { 
// Simulate the printing of a ticket. 
System.out.println("##################")… 
System.out.println("# The BlueJ Line"); 
System.out.println("# Ticket"); 
System.out.println("# " + price + " cents."); 
System.out.println("##################")… 
System.out.println(); 

// Update the total collected with the price. 
total = total + price; 
// Reduce the balance by the prince. 
balance = balance - price; 
} 
else { 
System.out.println("You must insert at least: " + 
(price - balance) + " more cents."); 

} 
} 

/** 
* Exercise printtickettwo 
*/ 
public void printTicketTwo(); 
int amountLeftToPay; 
amountLeftToPay (***********) = price - balance; 

if (amountLeftToPay > 0) 
{ 
// Simulate the printing of a ticket. 
System.out.println("##################")… 
System.out.println("# The BlueJ Line"); 
System.out.println("# Ticket "); 
System.out.println("# " + price + " cents."); 
System.out.println("##################")… 
System.out.println(); 
} 
else 
{ 
System.out.println.("Amount Still Required); 
} 
} 

/** 
* Return the money in the balance. 
* The balance is cleared. 
*/ 
public int refundBalance() 
{ 
int amountToRefund; 
amountToRefund=balance; 
balance = 0; 
return amountToRefund; 
} 

/** 
* Exercise empty machine money 
*/ 
public int emptyMachine() 
{ 
int emptyMachine; 
emptyMachine = total; 
total = 0; 
return total; 
} 

} 
+1

什麼線是它發生呢? – evanmcdonnal

+0

更改'public void printTicketTwo();'爲'public void printTicketTwo(){'並驗證你的大括號。 – madth3

回答

1

此行public void printTicketTwo();

而是必須

public void printTicketTwo() { *method body* }

編輯 - 一般調試諮詢;當你得到這樣的錯誤時,如果你有錯誤或者錯誤找到最小的行號並且看看那裏的代碼,通常會有一個行號。通常情況下,語法錯誤位於上面提到的行的上方,例如,如果在以下行上有int myInt = 5int mySecondInt = 7;,則錯誤可能會引用第二行,即使它是由於之前在行上省略了一個分號而引起的。

+0

謝謝!我的錯 –

0

Commets已添加到你旁邊做每個錯誤類,現在工作得很好

 public void printTicket() 
    { 
    if(balance >= price) { 
    // Simulate the printing of a ticket. 
    System.out.println("##################"); // you for got ; 
    System.out.println("# The BlueJ Line"); 
    System.out.println("# Ticket"); 
    System.out.println("# " + price + " cents."); 
    System.out.println("##################"); // you for got ; 
    System.out.println(); 

    // Update the total collected with the price. 
    total = total + price; 
    // Reduce the balance by the prince. 
    balance = balance - price; 
    } 
    else { 
    System.out.println("You must insert at least: " + 
    (price - balance) + " more cents."); 

    } 
    } 




public void printTicketTwo() // ; means an extarnl call of another existing method in the class 
{ 
int amountLeftToPay; 
amountLeftToPay = price - balance; // any method must have { method body } 

if (amountLeftToPay > 0) 
{ 
// Simulate the printing of a ticket. 
System.out.println("##################"); 
System.out.println("# The BlueJ Line"); 
System.out.println("# Ticket "); 
System.out.println("# " + price + " cents."); 
System.out.println("##################"); 
System.out.println(); 
} 
else 
{ 
System.out.println("Amount Still Required"); // you have added an extra . which is not needed and you for got the " and the end of Required 
} 
} 
相關問題