Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member to represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, set the balance to 0. Provide three member functions: - credit($amount) should add amount to the current balance - debit($amount) should ensure that amount does not exceed the current balance and then reduce the current balance by amount. The balance should not change if amount exceeds the balance. - getBalance() should return the current balance Note: Create a set of test data and then write a program to test the class
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:
Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member to represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, set the balance to 0. Provide three member functions:
- credit($amount) should add amount to the current balance
- debit($amount) should ensure that amount does not exceed the current balance and then reduce the current balance by amount. The balance should not change if amount exceeds the balance.
- getBalance() should return the current balance
Note: Create a set of test data and then write a program to test the class.
Step by step
Solved in 2 steps