Banks offer various types of accounts, such as savings, checking, certificate of
ID: 665240 • Letter: B
Question
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet with their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write. Another type of account that is used to save money for the long term is certificate of deposit (CD).
In this programming exercise, you use abstract classes and pure virtual functions to design classes to manipulate various types of accounts. For simplicity, assume that the bank offers three types of accounts: savings, checking, and certificate of deposit, as described next.
Scenarios in every types of bank accounts:
Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance and has a higher interest rate.
Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no monthly service charge, a minimum balance requirement, unlimited check writing and lower interest; and a third with no monthly service charge, a higher minimum requirement, a higher interest rate, and unlimited check writing.
Certificate of deposit (CD): In an account of this type, money is left for some time, and these accounts draw higher interest rates than savings or checking accounts. Suppose that you purchase a CD for six months. Then we say that the CD will mature in six months. Penalty for early withdrawal is stiff.
Available Classes:
bankAccount: Every bank account has an account number, the name of the owner, and a balance. Therefore, instance variables such as name, accountNumber, and balance should be declared in the abstract class bankAccount. Some operations common to all types of accounts are retrieve account owner’s name, account number, and account balance; make deposits; withdraw money; and create monthly statement. So include functions to implement these operations. Some of these functions will be pure virtual.
checkingAccount: A checking account is a bank account. Therefore, it inherits all the properties of a bank account. Because one of the objectives of a checking account is to be able to write checks, include the pure virtual function writeCheck() to write a check.
serviceChargeChecking: A service charge checking account is a checking account. Therefore, it inherits all the properties of a checking account. For simplicity, assume that this type of account does not pay any interest, allows the account holder to write a limited number of checks each month, and does not require any minimum balance. Include appropriate named constants, instance variables, and functions in this class.
noServiceChargeChecking: A checking account with no monthly service charge is a checking account. Therefore, it inherits all the properties of a checking account. Furthermore, this type of account pays interest, allows the account holder to write checks, and requires a minimum balance.
highInterestChecking: A checking account with high interest is a checking account with no monthly service charge. Therefore, it inherits all the properties of a no service charge checking account. Furthermore, this type of account pays higher interest and requires a higher minimum balance than the no service charge checking account.
savingsAccount: A savings account is a bank account. Therefore, it inherits all the properties of a bank account. Furthermore, a savings account also pays interest.
highInterestSavings: A high-interest savings account is a savings account. Therefore, it inherits all the properties of a savings account. It also requires a minimum balance.
certificateOfDeposit: A certificate of deposit account is a bank account. Therefore, it inherits all the properties of a bank account. In addition, it has instance variables to store the number of CD maturity months, interest rate, and the current CD month.
Note that the classes bankAccount and checkingAccount are abstract. That is, we cannot instantiate objects of these classes. The other classes in Figure above are not abstract.
#include<iostream>
#include<iomanip>
#include<string>
class bankAccount
{
public:
int getAccountNumber();
double getBalance();
string getName();
void setName(string name);
void withdraw(double balance);
void deposit(double balance);
abstract void createMonthlyStatement();
private:
int accountNumber;
string name;
double balance;
}
class savingsAccount: public bankAccount
{
public:
void writeCheck(double);
}
class checkingAccount: public banckAccount
{
public:
void writeCheck( double balance);
}
class ServiceChecking: public checkingAccount
{
public:
double getServiceChargeAccount();
void setServiceChargeAccount();
double getServiceChargeChecks();
void setServiceChargeChecks();
int getNumberOfChecksWritten();
void setNumberOfChecksWritten(int );
void writeCheck();
private:
double ACCOUNT_SERVICE_CHARGE = 10.00;
int MAXIMUM_NUM_OF_CHECKS = 5;
protected:
double serviceChargeAccount;
double serviceChargeCheck;
int numberOfChecksWritten;
}
class noServiceChecking: public checkingAccount
{
public:
double getMinimumBalance();
void getMinimumBalance(double);
void writeCheck(double);
void withdraw(double);
private:
double MIN_BALANCE = 1000.00;
double INTEREST_RATE = 0.02;
protected:
double minimumBalance;
double interestRate;
}
class highInterestChecking: public noServiceChecking
{
public:
double getInterestRate();
void setInterestRate(double);
private:
double INTEREST_RATE=0.05;
double MIN_BALANCE=5000.00;
}
Explanation / Answer
Hope this will helps you..
import java.io.*;
class BankWork
{
final int max_limit=20;
final int min_limit=1;
final double min_bal=500;
private String name[]=new String[20];
privateint accNo[]=newint[20];
private String accType[]=new String[20];
privatedouble balAmt[]=newdouble[20];
staticint totRec=0;
//constructor
BankWork()
{
for(int i=0;i<max_limit;i++)
{
name[i]="";
accNo[i]=0;
accType[i]="";
balAmt[i]=0.0;
}
}
//TO ADD NEW RECORDpublicvoid newEntry()
{
String str;
int acno;
double amt;
boolean permit;
permit=true;
if (totRec>max_limit)
{
System.out.println(" Sorry we cannot admit you in our bank... ");
permit=false;
}
if(permit = true) //Allows to create new entry
{
totRec++; // Incrementing Total Record
System.out.println(" =====RECORDING NEW ENTRY=====");
try{
accNo[totRec]=totRec; //Created AutoNumber to accNo so no invalid id occurs
System.out.println("Account Number : "+accNo[totRec]);
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Name : ");
System.out.flush();
name[totRec]=obj.readLine();
System.out.print("Enter Account Type : ");
System.out.flush();
accType[totRec]=obj.readLine();
do{
System.out.print("Enter Initial Amount to be deposited : ");
System.out.flush();
str=obj.readLine();
balAmt[totRec]=Double.parseDouble(str);
}while(balAmt[totRec]<min_bal); //Validation that minimun amount must be 500
System.out.println(" ");
}
catch(Exception e)
{}
}
}
//TO DISPLAY DETAILS OF RECORDpublicvoid display()
{
String str;
int acno=0;
boolean valid=true;
System.out.println(" =====DISPLAYING DETAILS OF CUSTOMER===== ");
try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Account number : ");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println(" Invalid Account Number ");
valid=false;
}
if (valid==true)
{
System.out.println(" Account Number : "+accNo[acno]);
System.out.println("Name : "+name[acno]);
System.out.println("Account Type : "+accType[acno]);
System.out.println("Balance Amount : "+balAmt[acno]+" ");
}
}
catch(Exception e)
{}
}
//TO DEPOSIT AN AMOUNTpublicvoid deposit()
{
String str;
double amt;
int acno;
boolean valid=true;
System.out.println(" =====DEPOSIT AMOUNT=====");
try{
//Reading deposit value
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Account No : ");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println(" Invalid Account Number ");
valid=false;
}
if (valid==true)
{
System.out.print("Enter Amount you want to Deposit : ");
System.out.flush();
str=obj.readLine();
amt=Double.parseDouble(str);
balAmt[acno]=balAmt[acno]+amt;
//Displaying Depsit Details
System.out.println(" After Updation...");
System.out.println("Account Number : "+acno);
System.out.println("Balance Amount : "+balAmt[acno]+" ");
}
}
catch(Exception e)
{}
}
//TO WITHDRAW BALANCEpublicvoid withdraw()
{
String str;
double amt,checkamt;
int acno;
boolean valid=true;
System.out.println(" =====WITHDRAW AMOUNT=====");
try{
//Reading deposit value
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Account No : ");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println(" Invalid Account Number ");
valid=false;
}
if (valid==true)
{
System.out.println("Balance is : "+balAmt[acno]);
System.out.print("Enter Amount you want to withdraw : ");
System.out.flush();
str=obj.readLine();
amt=Double.parseDouble(str);
checkamt=balAmt[acno]-amt;
if(checkamt >= min_bal)
{
balAmt[acno]=checkamt;
//Displaying Depsit Details
System.out.println(" After Updation...");
System.out.println("Account Number : "+acno);
System.out.println("Balance Amount : "+balAmt[acno]+" ");
}
else
{
System.out.println(" As per Bank Rule you should maintain minimum balance of Rs 500 ");
}
}
}
catch(Exception e)
{}
}
};
class Bank
{
publicstaticvoid main(String args[])
{
String str;
int choice;
choice=0;
BankWork BW_obj = new BankWork();
do
{
System.out.println("Choose Your Choices ...");
System.out.println("1) New Record Entry ");
System.out.println("2) Display Record Details ");
System.out.println("3) Deposit...");
System.out.println("4) Withdraw...");
System.out.println("5) Exit");
System.out.print("Enter your choice : ");
System.out.flush();
try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
str=obj.readLine();
choice=Integer.parseInt(str);
switch(choice)
{
case 1 : //New Record Entry
BW_obj.newEntry();
break;
case 2 : //Displaying Record Details
BW_obj.display();
break;
case 3 : //Deposit...
BW_obj.deposit();
break;
case 4 : //Withdraw...
BW_obj.withdraw();
break;
case 5 : System.out.println(" .....THANKS FOR VISITING.....");
break;
default : System.out.println(" Invalid Choice ");
}
}
catch(Exception e)
{}
}while(choice!=5);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.