Knowee
Questions
Features
Study Tools

// BankAccount.java// Parent class BankAccountpublic class BankAccount { private String accountNumber; private double balance; public BankAccount(String accountNumber, double balance) { this.accountNumber = accountNumber; this.balance = balance; } public void deposit(double amount) { balance += amount; } public void withdraw(double amount) { if (balance >= amount) { balance -= amount; } else { System.out.println("Insufficient balance"); } } public double getBalance() { return balance; }}Copy// SavingsAccount.java// Child class SavingsAccountpublic class SavingsAccount extends BankAccount { public SavingsAccount(String accountNumber, double balance) { super(accountNumber, balance); } @Override public void withdraw(double amount) { if (getBalance() - amount < 100) { System.out.println("Minimum balance of $100 required!"); } else { super.withdraw(amount); } }}Copy // Main.java// Main classpublic class Main { public static void main(String[] args) { System.out.println("Create a Bank Account object (A/c No. BA1234) with initial balance of $500:"); //Create a BankAccount object (A/c No. "BA1234") with initial balance of $500 BankAccount BA1234 = new BankAccount("BA1234", 500); // Deposit $1000 into account BA1234 System.out.println("Deposit $1000 into account BA1234:"); BA1234.deposit(1000); System.out.println("New balance after depositing $1000: $" + BA1234.getBalance()); // Withdraw $600 from account BA1234 System.out.println("Withdraw $600 from account BA1234:"); BA1234.withdraw(600); System.out.println("New balance after withdrawing $600: $" + BA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1234") with initial balance of $450 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1234) with initial balance of $450:"); SavingsAccount SA1234 = new SavingsAccount("SA1234",450); // Withdraw $300 from SA1234 SA1234.withdraw(300); System.out.println("Balance after trying to withdraw $300: $" + SA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1000") with initial balance of $300 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1000) with initial balance of $300:"); SavingsAccount SA1000 = new SavingsAccount("SA1000",300); // Withdraw $250 from SA1000 (balance falls below $100) System.out.println("Try to withdraw $250 from SA1000!"); SA1000.withdraw(250); System.out.println("Balance after trying to withdraw $250: $" + SA1000.getBalance()); }}

Question

// BankAccount.java// Parent class BankAccountpublic class BankAccount { private String accountNumber; private double balance; public BankAccount(String accountNumber, double balance) { this.accountNumber = accountNumber; this.balance = balance; } public void deposit(double amount) { balance += amount; } public void withdraw(double amount) { if (balance >= amount) { balance -= amount; } else { System.out.println("Insufficient balance"); } } public double getBalance() { return balance; }}Copy// SavingsAccount.java// Child class SavingsAccountpublic class SavingsAccount extends BankAccount { public SavingsAccount(String accountNumber, double balance) { super(accountNumber, balance); } @Override public void withdraw(double amount) { if (getBalance() - amount < 100) { System.out.println("Minimum balance of 100 required!"); } else { super.withdraw(amount); } }}Copy // Main.java// Main classpublic class Main { public static void main(String[] args) { System.out.println("Create a Bank Account object (A/c No. BA1234) with initial balance of 500:"); //Create a BankAccount object (A/c No. "BA1234") with initial balance of 500BankAccountBA1234=newBankAccount("BA1234",500);//Deposit500 BankAccount BA1234 = new BankAccount("BA1234", 500); // Deposit 1000 into account BA1234 System.out.println("Deposit 1000intoaccountBA1234:");BA1234.deposit(1000);System.out.println("Newbalanceafterdepositing1000 into account BA1234:"); BA1234.deposit(1000); System.out.println("New balance after depositing 1000: "+BA1234.getBalance());//Withdraw" + BA1234.getBalance()); // Withdraw 600 from account BA1234 System.out.println("Withdraw 600fromaccountBA1234:");BA1234.withdraw(600);System.out.println("Newbalanceafterwithdrawing600 from account BA1234:"); BA1234.withdraw(600); System.out.println("New balance after withdrawing 600: "+BA1234.getBalance());//CreateaSavingsAccountobject(A/cNo."SA1234")withinitialbalanceof" + BA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1234") with initial balance of 450 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1234) with initial balance of 450:");SavingsAccountSA1234=newSavingsAccount("SA1234",450);//Withdraw450:"); SavingsAccount SA1234 = new SavingsAccount("SA1234",450); // Withdraw 300 from SA1234 SA1234.withdraw(300); System.out.println("Balance after trying to withdraw 300:300: " + SA1234.getBalance()); // Create a SavingsAccount object (A/c No. "SA1000") with initial balance of 300System.out.println("\nCreateaSavingsAccountobject(A/cNo.SA1000)withinitialbalanceof300 System.out.println("\nCreate a SavingsAccount object (A/c No. SA1000) with initial balance of 300:"); SavingsAccount SA1000 = new SavingsAccount("SA1000",300); // Withdraw 250fromSA1000(balancefallsbelow250 from SA1000 (balance falls below 100) System.out.println("Try to withdraw 250fromSA1000!");SA1000.withdraw(250);System.out.println("Balanceaftertryingtowithdraw250 from SA1000!"); SA1000.withdraw(250); System.out.println("Balance after trying to withdraw 250: $" + SA1000.getBalance()); }}

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This is a Java program that simulates a simple banking system. It has a parent class BankAccount and a child class SavingsAccount that extends BankAccount.

The BankAccount class has two private variables: accountNumber and balance. It has a constructor to initialize these variables and methods to deposit, withdraw, and check the balance.

The SavingsAccount class extends BankAccount and overrides the withdraw method to ensure that the account maintains a minimum balance of $100.

The Main class creates instances of BankAccount and SavingsAccount, and performs operations like deposit and withdrawal to demonstrate the functionality of these classes.

For example, it creates a BankAccount object with account number "BA1234" and initial balance of 500,deposits500, deposits 1000 into it, and then withdraws 600fromit.ItalsocreatesaSavingsAccountobjectwithaccountnumber"SA1234"andinitialbalanceof600 from it. It also creates a `SavingsAccount` object with account number "SA1234" and initial balance of 450, and tries to withdraw $300 from it.

It also demonstrates the minimum balance requirement of the SavingsAccount by trying to withdraw an amount that would cause the balance to fall below $100.

This problem has been solved

Similar Questions

public class Account{       private int accountNumber;       private String holderName;       private double balance;                    public Account(int accountNumber, String holderName, double balance) {              this.accountNumber = accountNumber;              this.holderName = holderName;              this.balance = balance;       } } public class Main{       public static void main(String args[]) {              Account accObj1=new Account(1001,"Chandru",50000);                           System.out.println(accObj1);                    }}If the above code should give the output as “Account Number : 1001, Holder : Chandru, Balance : 50000”, which method should be overridden and that method should be written in which class.Select one:a.Override toString() method in Account classb.Override tostring() method in Account classc.Override tostring() method in Main classd.Override toString() method in Main class

Write a java program to create a bank account with Name of the account holder, type of account(savings or current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance. Input 1: Enter the customers: Reena Savings 123 1000 Robin Current 456 2000 Praveen Savings 789 3000 Sherin Current 234 2500 Deena Savings 567 2000 Enter choice: 1. Credit 2. Debit

Declare a method public double calculateInterest() in the class Account. Just declare this method without providing any definition/implementation.Make necessary changes to the class declaration. public class Account{       private int accountNumber;       private String holderName;       private double balance;                 // Declare the method calculateInterest              }

Program that creates a class Account that stores a variable balance. The class has methods to startaccount, to deposit money, to withdraw money and tell the current balance amoun

Write a C++ program to implement a class called BankAccount that represents a simple bank account. The class should have private member variables for account number and balance. Include member functions to deposit and withdraw money from the account.Testcase:Input:Rs.1000.0  // initial balanceRs.500.0  // depositRs.200.0   // withdrawOutput:Rs.1300.0  // final balance Input:Rs.2000.0  // initial balanceRs.1000.0  // depositRs.4000.0   // withdrawOutput:NA  // final balance

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.