Task 9B - Inheritance, Polymorphism, Overriding, Enums and more
Identify and write the code of classes, their attributes, behavior and relationships that shall fulfil below requirements. Think and decide yourself where you need to use which type, where enum make sense, where overloading, overriding and inheritance can help etc. to devise a solution that is reusable and maintainable. It has nothing to do with how real banking work, so don’t worry if something do not make sense to you.
A bank allow citizens to open accounts, each account must have an id, opening balance, account holder name, and age. Bank offers 3 types of accounts i.e. current account, saving account and investment account. Bank gives no profit on current accounts but to others. So, the saving and investment account are earning accounts, means the account holders of saving and investment accounts make profit from their deposits.
Both earning based account shall expose a public behavior to retrieve total earnings (how it’s calculated is explained below). All saving accounts has a category that is fixed and do not change i.e. young saver, adult saver, and senior citizen saver. Category shall be auto assigned to each saving account at the time of account opening (means at the time of object instantiation) depending on the age of account holder i.e. young, adult, and senior citizen for age below 35, from 35 to 50 age, and above 50, respectively. Bank gives 6% annual profit to young savers, 7% profit to adult savers and 8% to senior citizen savors. Users can withdraw and deposit any time in current and saving accounts, no extra fee is charged.
Each investment account has a type too. The type indicate for how much duration the investment is made. These types are fixed and shall not change during the life cycle of account. These types include one year, three year or five year. It must be specified at the time of account opening. Bank gives 10% profit who open investment account for one year, 12% per year for three year investment and 14% profit who open account for 5 years investment plan. For example, if a person open an investment account with 3 year plan with initial balance of 100,000, after a year, his earning shall be 112000. For more than one year plan, the investment shall be compounded for subsequent years e.g. if an account belong to 3 year investment plan that was opened with 100,000 PKR investment. First year profit shall be calculated on 100,000, resulting into 112,000, the second year profit of 12% shall be calculated on 112,000 and so on. Bank discourage withdraws from all type of investment accounts, when an account holder withdraw some amount from investment account, bank deduct 4% of that amount as surcharge.
Define a static behavior getTotalProfitPaid in Account class that shall take one or more earning accounts objects as argument and return the total amount the bank must pay as profit to all those account holders collectively.
Please add following features in your assignment (in addition to what is written above)
- Above mentioned profit ratios are fixed for each Type and Category, shift profit ratio inside each enum to make the code of getTotalEarnings simple.
- Define getTotalEarnings such that it shall return the total profit. It shall not update the balance. If the account holder want to reinvest, he/she shall call the deposit method again and pass the profit in it).
- Background: A person who submit tax return each year is called Filer. They submit their all details of income sources, assets and expenses to goverment each year and pay the tax due, in return, government gives them some benefits. For example, when they withdraw cash from bank, buy a plot or car, win a lucky draw or get some profit from any type investment, government charge them less tax as compared to non-filers.
Update code such that when any earning account is created, it should take a boolean value to represent whether the account holder is filer or not. Update withdraw method for all accounts such that if the account holder is filer, charge 2% tax and incase of non-filer, charge 4% tax on the profit earned. In same way, when getTotalEarnings is called on earning acounts, return the earning after deducting tax i.e. 25% from non-filer and 15% from filer. 15% of profit. This is called capital gain tax. - On all accounts, bank deduct 2.5% of balance as Zakat each year. Bank allow account holders to declare if Zakat is not applicable to them when a new account is opened. If a peson opt-out, the bank do not deduct the Zakat on such accounts. Implement this requirement in your code and also define a method deductZakat, it shall deduct zakat depending on what the account holder declared at the time of opening the account (i.e. at the time of object instantiation). It shall decrease the balance according to Zakat due and return the amount deducted.
- Make a test class, create 5 to 7 different types of accounts object. Print each account holder earning and also print total profit paid by the bank (implemented in getTotalProfitPaid).
- Consider this point a bonus feature that is not required. Its only for those who think they are good programmers.
Background: In many countries, currency loose its value because of inflation e.g. you get less petrol for 100 PKR today as compared to 5 years ago. Check this link for latest inflation rates in different countries.
Define a method getRealProfitRatio, it should return the actual profit percentage that the account holder got i.e. after deducting government tax, zakat, and adjusting the rate of inflation (how much value the account holder lost by investing with bank because of inflation and taxes). So, for all earning accounts you shall store country along with year in which the account is opened, as it would impact the real profit. Search Capital Gain Tax in 7 countries from Google (use 15% if you could not find for a country). Take consective 5 years e.g. 2018-2022 and store inflation rate of each year for each country (take maximum 7 countries from this list). Store country names, inflation rate, years etc. in such a way that structure should be flexible i.e. adding more countires data should not require change in code but in data only. Must include Japan, China, Pakistan and Lebanon with 3 others of your choice. Take real inflation rates of year 2021 from this link and take inflation rate of 2022 from this forecast. Search real inflation rates or scale down with right proportion for years 2018-2020. Create a test class, in its main method, create 7 InvestmentAccount in year 2018 with 5 years plan in 7 different countries. Print which country is best for the long term investment.
Comments
Post a Comment