Create a class named “BankAccount” that has the attributes bank, accountNumber, accountName. Implement setters and getters for these attributes. Create two classes: “DebitAccount” and “CreditAccount”, which both inherit from BankAccount. DebitAccount class has the following additional attributes and methods: double balance - cannot be negative setter and getter for balance withdraw(double amount) - subtracts balance with the said amount and displays new balance. Does not do anything if amount is greater than balance deposit(double amount) - adds amount to balance and displays new balance
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Inheritance in Java
- Create a class named “BankAccount” that has the attributes bank, accountNumber, accountName. Implement setters and getters for these attributes.
- Create two classes: “DebitAccount” and “CreditAccount”, which both inherit from BankAccount.
DebitAccount class has the following additional attributes and methods:
double balance - cannot be negative
CreditAccount class has the following additional attributes and methods:
double creditBalance - can be negative
Inputs
1. Char input for type of account (D/C)
2. Following lines are operations
- {amount} : for withdraw and pay methods + {amount/rate} : for deposit and interest 0 if stop
CSample Output
Step by step
Solved in 2 steps with 1 images