我正在尝试编译一个程序并收到一条错误消息:“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
请指正并指正。帮助将不胜感激。