Develop three classes called Bank , Account , and Customer to store account and
ID: 3752097 • Letter: D
Question
Develop three classes called Bank, Account, and Customer to store account and customer information for a bank.
Bank Class
In the homework, your Bank class can have maximum five accounts and five customers.
For the addCustomer() method, your class should add a new customer with the name, address, and SSN number. If your bank has already five customers or a customer with the SSN already exists, your method should return false.
For the openAccount() method, your class should add a new account with the customer’s SSN, account number and the corresponding information. If the account number is already taken by another object or maximum accounts (= five) are already used in the bank, your method should return false. In the program,
one customer can have only one account or no account.
For the closeAccount() method, your class should delete the account with the account number, accNum, from the bank. If the account number doesn’t exist in the bank, your method should return false.
For the accountInfo() method, your class should display the account information with the corresponding customer information. If the account number doesn’t exist in the bank, your method should return false.
For the updateBalance() method, your class should change the balance with the new amount for the account number. If the account number doesn’t exist in the bank or the balance is a negative number, your method should return false.
For the updateAddress() method, your class should update the address of the customer with the SSN. If the customer doesn’t exist in the bank, your method should return false.
Sample Demo Program
This is a sample demo program called BankDemo.java. Your program should display similar messages as the sample run.
public class BankDemo {
public static void main(String[] args) {
Bank csumbBank = new Bank(“CSUMB”);
System.out.println(" ========== Three New Customers ==========");
csumbBank.addCustomer("Tom Smith", "123 University Center 93955",
77777);
csumbBank.addCustomer ("Alice Smith", "123 University Center 93955",
88888);
csumbBank.addCustomer ("Joe Otter", "2440 Ocean Avenue 93900",
99999);
System.out.println(" ========== Three New Accounts ==========");
csumbBank.openAccount(77777, 1000, 1, 10.0);
csumbBank.openAccount(88888, 2000, 1, 50.25);
csumbBank.openAccount(99999, 3000, 2, 100.25);
System.out.println(" ========== Bank Info ==========");
csumbBank.bankInfo();
System.out.println(" ========== Close Account ==========");
System.out.println(csumbBank.closeAccount(1000));
System.out.println(csumbBank.closeAccount(7000));
System.out.println("========== Account Info ==========");
csumbBank.accountInfo(2000);
System.out.println(csumbBank.accountInfo(7000));
}
}
A sample run of your program should look like below.
========== Three New Customers ==========
========== Three New Accounts ==========
========== Bank Info ==========
Bank Name: CSUMB
Number of Customers: 3
Tom Smith: 77777, 123 University Center 93955
Alice Smith: 88888, 123 University Center 93955
Joe Otter: 99999, 2440 Ocean Avenue 93900
Number of Accounts: 3
1000: $10.00 - Tom Smith: 77777
2000: $50.25 - Alice Smith: 88888
3000: $100.25 - Joe Otter: 99999
Bank Total Balance: $160.50
========== Close Account ==========
true
false
========== Account Info ==========
Account Info: Account Number: 2000
Checking account
Balance: $50.25
Customer Info: Alice Smith
123 University Center 93955
SSN: 88888
False
Explanation / Answer
import java.util.*;
class BankAccount {
static Scanner input = new Scanner(System.in);
String name, actype;
int accNo, bal, amt;
BankAccount(String name, int accNo, String actype, int bal) {
this.name = name;
this.accNo = accNo;
this.actype = actype;
this.bal = bal;
}
int deposit() {
System.out.print("Enter amount to deposit:");
amt = input.nextInt();
if (amt < 0) {
System.out.println("Invalid Amount");
return 1;
}
bal = bal + amt;
return 0;
}
int withdraw() {
System.out.println("Your Balance=" + bal);
System.out.print("Enter amount to withdraw:");
amt = input.nextInt();
if (bal < amt) {
System.out.println("Not sufficient balance.");
return 1;
}
if (amt < 0) {
System.out.println("Invalid Amount");
return 1;
}
bal = bal - amt;
return 0;
}
void display() {
System.out.println("Name:" + name);
System.out.println("Account No:" + accNo);
System.out.println("Balance:" + bal);
}
void dbal() {
System.out.println("Balance:" + bal);
}
public static void main(String args[]) {
System.out.println("Enter your Name: ");
String nn = input.nextLine();
System.out.println("Enter Account Number: ");
int num = input.nextInt();
System.out.println("Enter Account Type: ");
String type = input.next();
System.out.println("Enter Initial Balance: ");
int bal = input.nextInt();
BankAccount b1 = new BankAccount(nn, num, type, bal);
int menu;
System.out.println("Menu");
System.out.println("1. Deposit Amount");
System.out.println("2. Withdraw Amount");
System.out.println("3. Display Information");
System.out.println("4. Exit");
boolean quit = false;
do {
System.out.print("Please enter your choice: ");
menu = input.nextInt();
switch (menu) {
case 1:
b1.deposit();
break;
case 2:
b1.withdraw();
break;
case 3:
b1.display();
break;
case 4:
quit = true;
break;
}
} while (!quit);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.