【发布时间】:2013-06-24 03:21:31
【问题描述】:
我正在尝试编译程序并收到错误消息:“acc_man.java:46: missing return statement”。我在 acc_man 类下创建了两个银行帐户,另一个类具有 main 方法要使用的所有方法。 Bank_Account 类下的私有方法用于向构造函数传递参数。
代码如下:
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
请指正指正。帮助将不胜感激。
【问题讨论】:
-
不要只是将您的代码飞溅到文本区域中,而是要确保它按文件分隔并且您指出问题出在哪里。
-
能否请您发布完整的异常详细信息