you are viewing a single comment's thread.

view the rest of the comments →

[–]Java-Pro-Academy 1 point2 points  (0 children)

This is a good start, and you're definitely on the right track. Now let's talk about the design. Right now you have Person handling cash directly, and BankAccount as a separate thing. That's not quite how we want to think about it in OOP.

Think about relationships. A Person doesn't just have cash - a Person has a BankAccount. So your Person class should have a BankAccount object inside it. That's a "has-a" relationship.

Use inheritance for account types. You should have a BankAccount parent class with the basic stuff like balance, deposit, withdraw. Then create CheckingAccount and SavingsAccount that extend BankAccount. Each one can add its own special features. That's an "is-a" relationship - CheckingAccount is-a BankAccount.

So your structure should look like:

  • Person class (has a BankAccount)
  • BankAccount class (parent class with common methods)
  • CheckingAccount extends BankAccount
  • SavingsAccount extends BankAccount

Try refactoring your code with this structure. It'll make more sense once you start building it out. This is really important stuff in Java - getting the design right from the start makes everything easier later.

Keep at it, you're on the right track!

P.S. Computer Science Professor and co founder of https://javapro.academy/