Question: Please design and implement a Java class named BankAccount that supports the following operations: 1) to create an account with the account number (a string)
Please design and implement a Java class named BankAccount that supports the following operations: 1) to create an account with the account number (a string) and initial balance $0.0; 2) to deposit money; 3) to withdraw money; 4) to check balance; 5) to provide the account number; Use the attached Main class to test your class. The results should look like: ---------------------------------------- Balance in Account BA-123-001 is $0.0 Balance in Account BA-654-002 is $0.0 $100.0 is deposited to Account BA-123-001 $500.25 is deposited to Account BA-654-002 Low Balance. Operation is rejected. $40.0 is withdrawn from Account BA-654-002 Balance in Account BA-123-001 is $100.0 Balance in Account BA-654-002 is $460.25 ----------------------------------------- public class Main { public static void main(String[] args) { //create two accounts BankAccount account1 = new BankAccount("BA-123-001"); BankAccount account2 = new BankAccount("BA-654-002"); //check balance System.out.println("Balance in Account " + account1.getAccountNumber() + " is $" + account1.getBalance()); System.out.println("Balance in Account " + account2.getAccountNumber() + " is $" + account2.getBalance()); System.out.println(); // print an empty line //deposit account1.deposit(100); account2.deposit(500.25); System.out.println(); // print an empty line //withdraw account1.withdraw(150); account2.withdraw(40); System.out.println(); // print an empty line //check balance again System.out.println("Balance in Account " + account1.getAccountNumber() + " is $" + account1.getBalance()); System.out.println("Balance in Account " + account2.getAccountNumber() + " is $" + account2.getBalance()); } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
