Design a bank teller application that allows the teller to create/add accounts (
ID: 3723082 • Letter: D
Question
Design a bank teller application that allows the teller to create/add accounts (checking or savings), deposit to accounts, withdraw from accounts, apply interest to savings accounts, update interest rate, process monthly fee on checking accounts, and display all information for an account. Store the accounts ArrayList of objects and use static methods where necessary. The BankAccount and CheckingAccount classes are created for you and can be found in Moodle. The SavingsAccount class has been started but you must complete the 6 tasks in the file before you can use savings account. CheckingAccount and SavingsAccount inherit from the BankAccount class. Be aware you may need to add a field to the BankAccount class in order to identify accounts.
Be sure to test the application with multiple input values and types of accounts. Test each task multiple times.
You may add other functionality you consider relevant but be sure to include what is listed above at a minimum.
Explanation / Answer
1) Account.java
package accountProject;
import java.util.Set;
public class Account {
private double intialBalance;
private String accountName;
public Account(double balance){
if(balance >0){
intialBalance=balance;
}
else{
System.out.println("enter positive Value");
}
}
public double getIntialBalance() {
return intialBalance;
}
public void setIntialBalance(double intialBalance) {
if(intialBalance<0){
System.out.println("Balance can not be naegative");
}
else{
this.intialBalance = intialBalance;
}
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public void credit(double balance) throws NegativeBalanceException{
if(balance <0){
System.out.println("enter valid amount");
}
else if( balance > intialBalance){
throw new NegativeBalanceException("You dont have that much amount to withdraw , your balance is "+intialBalance );
}
else{
intialBalance=intialBalance-balance;
}
// else if(balance > intialBalance){
//
//
// }
}
public void debit (double balance){
if(balance <0 ){
System.out.println("enter valid amount");
}
else{
intialBalance=intialBalance+balance;
}
}
}
2)
SavingAccount.java
package accountProject;
public class SavingAccount extends Account {
private double rate;
public SavingAccount(double balance,double rate) {
super(balance);
this.rate=rate;
// TODO Auto-generated constructor stub
}
public double getRate() {
return rate;
}
public void setRate(double rate) {
this.rate = rate;
}
public double calculateInterest(){
double interest=(getIntialBalance()*1*getRate())/100;
return interest;
}
}
3) CheckingAccount.java
package accountProject;
public class CheckingAccount extends Account {
double chargedFee;
public double getChargedFee() {
return chargedFee;
}
public void setChargedFee(double chargedFee) {
this.chargedFee = chargedFee;
}
public CheckingAccount(double balance, double chargedFee) {
super(balance);
this.chargedFee = chargedFee;
}
public void credit(double balance) throws NegativeBalanceException{
double finalAmount;
if(balance <0 || balance >getIntialBalance()){
throw new NegativeBalanceException("you dont have enough balance");
}
else{
finalAmount=getIntialBalance()-balance-getChargedFee();
}
if(finalAmount<getIntialBalance()){
setIntialBalance(finalAmount);
}
}
public void debit (double balance){
double finalAmount;
if(balance>0){
finalAmount=getIntialBalance()+balance-getChargedFee();
setIntialBalance(finalAmount);
}
}
}
4) AccountTester.java
package accountProject;
import java.io.ObjectInputStream.GetField;
import java.util.Scanner;
public class AccountTester {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter intial balance");
double balance=scan.nextDouble();
Account account=new Account(balance);
System.out.println("enter account Name");
String name=scan.next();
account.setAccountName(name);
System.out.println("enter rate of interest");
double rate=scan.nextDouble();
SavingAccount savingAcc=new SavingAccount(account.getIntialBalance(), rate);
double interest=savingAcc.calculateInterest();
System.out.println("before credting price "+ savingAcc.getIntialBalance());
savingAcc.debit(interest);
System.out.println("after credting price "+ savingAcc.getIntialBalance());
System.out.println("Checking demo");
System.out.println("enter charge fee");
double chargefee=scan.nextDouble();
CheckingAccount checkingAcc=new CheckingAccount(account.getIntialBalance(), chargefee);
System.out.println("before debitng price "+ checkingAcc.getIntialBalance());
double amount=scan.nextDouble();
checkingAcc.debit(amount);
System.out.println("after debiting price "+ checkingAcc.getIntialBalance());
}
}
package accountProject;
public class NegativeBalanceException extends Exception {
public NegativeBalanceException(String exception) {
super(exception);
// TODO Auto-generated constructor stub
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.