Programming Activity – 10.4

Hello, this is Bndsbon. Welcome to my blog post again. Today, we will be talking about one of the exercises I have completed for the inheritance chapter.

To begin with, here is the question for my exercise.

屏幕快照 2017-06-04 下午4.06.01.png

屏幕快照 2017-06-04 下午4.06.06.png

and here is the UML class diagram

屏幕快照 2017-06-04 下午4.17.58.png

屏幕快照 2017-06-04 下午4.06.21.png

The direct super class for checkingaccount and savingsaccount is bankaccount, which is then connected to the object class. This hierarchy is followed in this project.

These methods could be used in bigger programs such as company applications, that helps to store the salaries of employees. It could also be used to learn one’s current balance, and to decide whether to store the money or not.

I followed the step requested by the exercise and completed the class, here is my code:

屏幕快照 2017-06-04 下午4.19.17.png

I have first imported the java text packet.

This class is the saving account class, which have a “is a” relationship between bankaccount, also known as inheritance. With the help of the inheritance, the saving account is now able to use explicit invocation to use the startBalance in the bankaccount, as indicated below:

屏幕快照 2017-06-04 下午4.23.10.png

Also this saving account is able to generate an interest of 0.03 to the balance, it also inherits the deposit method from the bankaccount super class, indicated by the code below:

屏幕快照 2017-06-04 下午4.25.27.png

This program also offers an protective solution where the inputs for the interest rate must be greater than zero, otherwise it would be not logical, as indicated below:

屏幕快照 2017-06-04 下午4.26.05.png

Also, this program translates the balance and interest rate into string for the class, and the interest rate will be represented as in percentage as indicated below:

屏幕快照 2017-06-04 下午4.27.23.png

Here is how the whole project looks like:

屏幕快照 2017-06-04 下午4.29.02.png

The checkingaccount and checkingaccountclient have a “use a” relationship, also known as dependency.

The checkingaccount and bankaccount have a “is a” relationship.

 

All in all, the inheritance project is very interesting, these methods used in the project could be used in real-life, such as when we are dealing with our money stored in the bank, we were able to see how much balance we have till now. Also, it is very easy to understand how the method works, as they needs to get certain methods from the direct superclass above, the way it functions is like a company with employees and employers. The employees ask for something from the employers and the employers give these things to the employees. I am looking forward to our next lesson!

Leave a comment

Blog at WordPress.com.

Up ↑