2013-06-24 63 views
0

我正在嘗試編譯程序並收到錯誤消息:「acc_man.java:46:return return statement」。我在類acc_man下創建了兩個銀行帳戶,而另一個類具有主方法使用的所有方法。 Bank_Account類下的私有方法用於將參數傳遞給構造函數。在主要方法中缺少return語句

的代碼如下:

import java.io.*; 
import java.util.*; 

class acc_man { 
public static void main (String[] args) throws IOException { 

Bank_Account sav_account = new Bank_Account(); 
Bank_Account cr_account = new Bank_Account(); 
BufferedReader stdin = new BufferedReader 
(new InputStreamReader (System.in)); 

System.out.println ("Please choose Account: 1.Savings 2.Credit"); 
int acc_type = Integer.parseInt (stdin.readLine()); 

System.out.println ("What do you want to do: 1. Deposit 2. Withdraw "); 
int tr_type = Integer.parseInt (stdin.readLine()); 

System.out.println ("Please enter amount"); 
int amount = Integer.parseInt (stdin.readLine()); 

if (acc_type < 2) 

    if (tr_type < 2) 
    sav_account.deposit (amount); 
    sav_account.print(); 

    if (tr_type > 1) 
    sav_account.withdraw (amount); 
    sav_account.print(); 

if (acc_type > 1) 

    if (tr_type < 2) 
    sav_account.deposit (amount); 
    sav_account.print(); 

    if (tr_type > 1) 
    sav_account.withdraw (amount); 
    sav_account.print(); 

}// method main 
}// class acc_man 

class Bank_Account { 

private int amount; 
private int balance; 

public int Bank_Account (int initial_balance) { 

balance = initial_balance; 
} 
// end constructor 

public int deposit (int amount) { 

balance = balance + amount; 

return balance; 
} 
//end method deposit 

public int withdraw (int amount) { 

balance = balance - amount; 
return balance; 
} 

//end method withdraw 

private int set_balance (int initial_balance) { 

initial_balance = balance; 
return initial_balance; 
} 

// end method set_balance 

public void print() { 

System.out.println ("Current balance of the account is:" + balance); 
} 


// end method print 
} 
//end class Bank_Account 

請修正建議。幫助將不勝感激。

+0

而不是隻是潑到你的代碼到textarea,確保它是由文件分開,並指出**問題的地方**。 –

+0

請您發佈完整的異常詳情 – vkrams

回答

0

主要方法應該是在一個公共類

public class acc_man { 
    public static void main (String[] args) throws IOException { 
      // ........ your codes 

    } 
} 
0

構造函數使用類的名稱,並沒有返回類型。

替換: 公衆詮釋BANK_ACCOUNT(INT initial_balance){

balance = initial_balance; 
} 
// end constructor 

有了:

public Bank_Account (int initial_balance) { 

balance = initial_balance; 
} 
// end constructor 
0

刪除INT聲明在構造函數

public Bank_Account (int initial_balance) { 
    balance = initial_balance; 
} 

它拋出,因爲是像正常方法解析