Interfaces & Abstract Classes

Interfaces & Abstract Classes

Bank Account

1.2 What to do

For this lab, you will design and implement the start of a banking solution for a neighborhood bank. There are two types of accounts the bank wants you to implement: one called SavingsAccount and one called CheckingAccount. Your interface and all classes must be in the bank package.

Both accounts can do the following:

Create a new account by specifying a "starter" amount of money to open it with. The starter amount must be greater than or equal to one cent.

Do this: Create a constructor that takes a single parameter (of type double) that represents the "starter amount" for the account. If the amount specified is negative OR the amount is less than one cent ($0.01), throw an IllegalArgumentException

Deposit into their account.

Do this: Create a method called deposit that takes a single parameter (of type double) that represents the amount deposited into the account. If the amount specified is negative, throw an IllegalArgumentException

Withdraw from their account. If the amount specified is greater than the balance available, this operation fails and returns false.

Do this: Create a method called withdraw that reduces the account balance by the amount specified. Return true if the transaction is successful, false otherwise. (Hint: test for a variety of cases here, i.e. values > 0, 0 ...etc, what other cases may cause the withdraw transaction to fail)

Check their balance.

Do this: Create a method getBalance that returns a double (the current account balance)

Non-customer behavior you must implement:

Bank administrators can perform monthly maintenance to assess monthly fees and give a "clean slate" for the subsequent month.

Do this: Create a performMonthlyMaintenance method to charge any fees and then reset transaction counters to zero.

Do this: Create a toString method that prints the account balance in dollars/cents format (e.g: $10.00). You may want to look up the documentation for the String.format method for this part, or use the DecimalFormat class if you wish.

You are required to use the IAccount interface as specified below. Both types of accounts implement this interface, so that the bank can access either account through that common protocol. You will need to consider behavior variations as described below.

Behavior variations for a SavingsAccount withdraw() method: Savings accounts allow for 6 penalty-free withdrawal transactions per month. Savings accounts allow for an unlimited number of deposits per month.

Rules:

If the amount specified for the withdrawal is negative, the operation fails. If the number of withdrawals for the month is greater than 6, a transaction penalty of $14 is deducted from the account when monthly maintenance is performed

Behavior variations for a CheckingAccount performMonthlyMaintenance() method: A minimum balance of $100 must be maintained throughout the month to avoid fees

Rules:

If the checking balance falls below 100 at ANY time during the month (before maintenance is performed) an account maintenance fee of 5 is charged when the monthly maintenance is performed.

Notes

For each method you write:

Design the signature of the method.

Write Javadoc-style comments for that method.

Write the body for the method.

Write one or more tests that check that the method works as specified in all cases.

Avoid duplicating code as much as possible. You will likely want to use an abstract superclass and "push" common method code up to that class. Feel free to create private "helper" methods if you need to.

Be sure to use access modifiers, private, default (no keyword), protected, and public appropriately.

Include JavaDoc for your classes and constructors as appropriate. You do not need to repeat JavaDoc already existing in a superclass or interface when you override a method. (This is true for the course in general.)

Provide a UML class diagram for your solution.

Here is the IAccount interface. This is the "contract" your solution is agreeing to implement

WX:codehelp

相关推荐
deephub4 分钟前
量子机器学习入门:三种数据编码方法对比与应用
人工智能·机器学习·量子计算·数据编码·量子机器学习
AI 嗯啦7 分钟前
计算机视觉----opencv实战----指纹识别的案例
人工智能·opencv·计算机视觉
max50060011 分钟前
基于多元线性回归、随机森林与神经网络的农作物元素含量预测及SHAP贡献量分析
人工智能·python·深度学习·神经网络·随机森林·线性回归·transformer
trsoliu12 分钟前
前端基于 TypeScript 使用 Mastra 来开发一个 AI 应用 / AI 代理(Agent)
前端·人工智能
白掰虾40 分钟前
STM32N6&AI资料汇总
人工智能·stm32·嵌入式硬件·stm32n6·stm32ai
爱思德学术1 小时前
中国计算机学会(CCF)推荐学术会议-C(软件工程/系统软件/程序设计语言):MSR 2026
人工智能·机器学习·软件工程·数据科学
小李独爱秋1 小时前
特征值优化:机器学习中的数学基石
人工智能·python·线性代数·机器学习·数学建模
科兴第一吴彦祖2 小时前
在线会议系统是一个基于Vue3 + Spring Boot的现代化在线会议管理平台,集成了视频会议、实时聊天、AI智能助手等多项先进技术。
java·vue.js·人工智能·spring boot·推荐算法
Lululaurel2 小时前
机器学习系统框架:核心分类、算法与应用全景解析
人工智能·算法·机器学习·ai·分类
居7然2 小时前
解锁AI智能体:上下文工程如何成为架构落地的“魔法钥匙”
人工智能·架构·大模型·智能体·上下文工程