public class Bank { private Account[] accounts = new Account[100]; private int s
ID: 3893302 • Letter: P
Question
public class Bank {
private Account[] accounts = new Account[100];
private int size;
private int capacity;
private static final int SAVINGS = 0;
private static final int CHECKING = 1;
private static final int SENIOR = 0;
private static final int ADULT = 1;
private static final int STUDENT = 2;
private static final int INIT_CAPACITY = 100;
/** Creates a new instance of Bank */
public Bank() ;
/********************************************************************
* Creates a new account.
* pre: customer information must be not null and types must be valid
* post: New account added to bank
* @param customerName String Account owner's name
* @param customerAddress String Owner's address
* @param customerAge int Owner's age (in years)
* @param customerPhoneNumber String Owner's phone number
* @param customerType int Owner's type of customer within bank
* @param typeAccount int Account type (savings or checking)
* @return String New account number
*/
public String addAccount(String customerName, String customerAddress,
int customerAge, String customerPhoneNumber,
int customerType, int typeAccount);
/***********************************************************************
* Make a deposit into account.
* pre: amount must be a positive integer
* post: Account's balance increases
* @param accountNumber String Account's number
* @param amount double Amount to deposit
* @return double New balance
*/
public String makeDeposit(String accountNumber, double amount);
/***********************************************************************
* Make a withdrawal from account.
* pre: amount must be a positive integer
* post: Account's balance decreases
* @param accountNumber String Account's number
* @param amount double Amount to withdraw
* @return double New balance
*/
public String makeWithdrawal(String accountNumber, double amount){
int index = find(accountNumber);
accounts[index].withdrawal(amount);
return Double.toString(accounts[index].getBalance());
}
/***********************************************************************
* Returns account information as a string so it can be displayed
* @param accountNumber String Account's number
* @return String Account information as a String object
*/
public String getAccount(String accountNumber);
/***********************************************************************
* Given an account number tells if the account exists or not
* @param accountNumber String Account's number
* @return int TRUE if accountNumber exists in accounts[]. Otherwise, -1.
*/
private int find(String accountNumber);
/***********************************************************************
/** You need to create private method : Allocate to allocate a new array to hold the transactions. */
private void reallocate(); {
if(account[99]==null){
System.out.println("Not Full");
}
else
account=new Account[account.length*2];
}
}
Explanation / Answer
public class Bank {
private Account[] accounts = new Account[100];
private int size;
private int capacity;
private static final int SAVINGS = 0;
private static final int CHECKING = 1;
private static final int SENIOR = 0;
private static final int ADULT = 1;
private static final int STUDENT = 2;
private static final int INIT_CAPACITY = 100;
/** Creates a new instance of Bank */
public Bank() ;
/********************************************************************
* Creates a new account.
* pre: customer information must be not null and types must be valid
* post: New account added to bank
* @param customerName String Account owner's name
* @param customerAddress String Owner's address
* @param customerAge int Owner's age (in years)
* @param customerPhoneNumber String Owner's phone number
* @param customerType int Owner's type of customer within bank
* @param typeAccount int Account type (savings or checking)
* @return String New account number
*/
public String addAccount(String customerName, String customerAddress,
int customerAge, String customerPhoneNumber,
int customerType, int typeAccount){
if (size >= 100){
reallocate();
accounts[size] = new Account(customerName,customerAddress,customerAge,customerPhoneNumber,customerType, typeAccount)
String accountNumber = accounts[size].getAccountNumber();
size++;
return accountNumber;
}
/***********************************************************************
* Make a deposit into account.
* pre: amount must be a positive integer
* post: Account's balance increases
* @param accountNumber String Account's number
* @param amount double Amount to deposit
* @return double New balance
*/
public String makeDeposit(String accountNumber, double amount){
int index = find(accountNumber);
if (index != -1){
accounts[index].deposit(amount);
return Double.toString(accounts[index].getBalance());
}
else {
System.out.println("Account not found");
}
return "";
}
/***********************************************************************
* Make a withdrawal from account.
* pre: amount must be a positive integer
* post: Account's balance decreases
* @param accountNumber String Account's number
* @param amount double Amount to withdraw
* @return double New balance
*/
public String makeWithdrawal(String accountNumber, double amount){
int index = find(accountNumber);
if (index != -1){
accounts[index].withdrawl(amount);
return Double.toString(accounts[index].getBalance());
}
else {
System.out.println("Account not found");
}
return "";
}
/***********************************************************************
* Returns account information as a string so it can be displayed
* @param accountNumber String Account's number
* @return String Account information as a String object
*/
public String getAccount(String accountNumber){
int index = find(accountNumber);
if (index != -1){
return accounts[index].toString();
}
else {
System.out.println("Account not found");
}
return "";
}
/***********************************************************************
* Given an account number tells if the account exists or not
* @param accountNumber String Account's number
* @return int TRUE if accountNumber exists in accounts[]. Otherwise, -1.
*/
private int find(String accountNumber){
for(int i = 0; i<size; i++){
if (accounts[i].getAccountNumber().equals(accountNumber))
return i;
}
return -1;
}
/***********************************************************************
/** You need to create private method : Allocate to allocate a new array to hold the transactions. */
private void reallocate(); {
if(account[99]==null){
System.out.println("Not Full");
}
else
account=new Account[account.length*2];
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.