Question

BankAccount and SavingsAccount Classes (JAVA)

Must be in GUI interface

Design an abstract class namedBankAccountto hold the following data for a bankaccount:

* Balance
* Number of deposits this month
* Number of withdrawals (this month)
* Annual interest rate
* Monthly service charges

The class should have the following methods:

Constructor: The constructor should accept arguments for the balance and annual interest rate.

deposit: A method that accepts an argument for the amount of the deposit. The methods should add the argument to the account balance. It should also increment thevariable holding the number of deposits.

withdraw: A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also incrementthe variable holding the number of withdrawals.

calcInterest: A methodthat updates the balance by calculating the monthly interest earned by the account ,and adding this interest to the balance. This isperformed according to the following formulas: Monthly InterestRate = (Annual Interest Rate / 12) Monthly Interest = Balance *Monthly Interest Rate Balance =Balance + MonthlyInterest

monthlyProcess: A method that subtracts the monthly service charge from the balance, calls the calc Interest method, and then sets the variables that hold thenumber of withdrawals, number of deposits, and monthly service charges to zero.

Next, design a SavingsAccount class that extends the BankAccount class.The SavingsAccount class should have a status field to represent an active or inactiveaccount. If the balance of a savings account falls below $25, it becomes inactive. (The status field could be a boolean variable.) No more withdrawals may be madeuntil the balance is raised above $25, at which time the account becomes active again. The savingsaccount class should have the following methods:

withdraw: A method that determines whether the account is inactive before a withdrawal is made. ) No withdrawal will be allowed if the account is not active.) Awithdrawal is then made by calling the superclassversion of the method (assuming it is allowed).

deposit: A method thatdetermines whether the account is inactive before a deposit ismade. If the account is inactive and the deposit brings the balanceabove $25,the account becomes active again. A deposit is then madeby calling the superclass version of the method.

monthlyProcess: Beforethe superclass method is called, this method checks the number of withdrawals. If the number of withdrawals for the month is more than 4, aservice charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly service charges.(Don’t forget to check the account balanceafter the servicecharge is taken. If the balance falls below $25, the accountbecomes inactive.

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1
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;imax_limit)
               {
                    System.out.println("\n\n\nSorry we cannot admit you in our bank...\n\n\n");
                    permit=false;
               }               if(permit = true)   //Allows to create new entry
               {
               totRec++;         // Incrementing Total Record               
               System.out.println("\n\n\n=====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]totRec)   //To check whether accNo is valid or Not
                     {
                          System.out.println("\n\n\nInvalid Account Number \n\n");
                          valid=false;
                     }                    if (valid==true)
                      {     
                        System.out.println("\n\nAccount Number : "+accNo[acno]);
                        System.out.println("Name : "+name[acno]);
                        System.out.println("Account Type : "+accType[acno]);
                        System.out.println("Balance Amount : "+balAmt[acno]+"\n\n\n");
                      }
                 }            catch(Exception e)
            {}
        }          //TO DEPOSIT AN AMOUNTpublicvoid deposit()
        {
              String str;              double amt;              int acno;
              boolean valid=true;
              System.out.println("\n\n\n=====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 (acnototRec)   //To check whether accNo is valid or Not
                         {
                              System.out.println("\n\n\nInvalid Account Number \n\n");
                              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("\nAfter Updation...");
                            System.out.println("Account Number :  "+acno);
                            System.out.println("Balance Amount :  "+balAmt[acno]+"\n\n\n");
                        }
                 }            catch(Exception e)
            {}
       }     //TO WITHDRAW BALANCEpublicvoid withdraw()
        {
              String str;              double amt,checkamt;              int acno;
              boolean valid=true;
              System.out.println("\n\n\n=====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 (acnototRec)   //To check whether accNo is valid or Not
                             {
                                System.out.println("\n\n\nInvalid Account Number \n\n");
                                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("\nAfter Updation...");
                                    System.out.println("Account Number :  "+acno);
                                    System.out.println("Balance Amount :  "+balAmt[acno]+"\n\n\n");
                                }                                else
                                 {
                                    System.out.println("\n\nAs per Bank Rule you should maintain minimum balance of Rs 500\n\n\n");
                                }
                        }
                 }            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("\n\n.....THANKS FOR VISITING.....");                                            break;                            default : System.out.println("\nInvalid Choice \n\n");
                          }
                    }                catch(Exception e)
                {}
            }while(choice!=5);
    }
}


answered by: captain
Add a comment
Answer #1

public abstract class Account
{
private double bal;
private int accnum;
public Account(int a)
{
bal=0.0;
accnum=a;
}

public void deposit(double sum)
{
if (sum>0)
bal+=sum;
else
System.err.println("Account.deposit(...): "
+"cannot deposit negative amount.");
}
public void withdraw(double sum)
{
if (sum>0)
bal-=sum;
else
System.err.println("Account.withdraw(...): "
+"cannot withdraw negative amount.");
}
public double getBalance()
{
return bal;
}
public double getAccountNumber()
{
return accnum;
}
public String toString()
{
return "Acc " + accnum + ": " + "balance = " + bal;
}
public final void print()
{
System.out.println( toString() );
}
}
public class SavingsAccount extends Account
{
private double interest;
public SavingsAccount(int accnum, double interest)
{
super(accnum);
this.interest=interest;
}
public double getInterest()
{
double x=super.getBalance()*interest;
return x;
}

public void setInterest(double interest){
this.interest=interest;
}

public void AddInterest (double interest){
double x=super.getBalance()*interest;
super.deposit(x);
}

public String toString(){
return super.toString()+" Interest : "+interest;
}



}

public class CurrentAccount extends Account
{
private double limit;
public CurrentAccount(int accnum, double limit){
super(accnum);
this.limit=limit;
}
public double getLimit()
{
return this.limit;
}
public void setLimit(double limit)
{
this.limit=limit;
public void withdraw( double limit)
{
if(limit<=this.limit)
super.withdraw(limit);
else
{
System.out.println(" Sorry, Limit Exceeded" );
}
}
public String toString()
{
return super.toString()+" Limit : "+limit;
}
}

public class Bank
{
public static void main (String[] args)
{
Account[] acc=new Account[2];
acc[0]=new SavingsAccount(263010,0.25);
acc[1]=new CurrentAccount(253010,5000);
for(int i=0; i {
if(acc[i]equals(SavingsAccount))
System.out.println(acc[0].getInterest());
}
}

Add a comment
Know the answer?
Add Answer to:
BankAccount and SavingsAccount Classes (JAVA)
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design and implement the following 3 classes with the exact fields and methods (these names and c...

    Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly): 1. An abstract class named BankAccount (java file called BankAccount.java) Description Filed/Method Balance NumberDeposits NumberWithdrawals AnnualInterestRate MonthlyServiceCharge BankAccount SetHonthlyServiceCharges A method that accepts the monthly service charges as an argument and set the field value GetBalance GetNum berDeposits GetNum berWithdrawals GetAnnualinterestRate GetMonthlyServiceCharge A method that returns the monthly service charge Deposit field for the bank account balance A field for the number...

  • pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank...

    pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank account and 1 for savings accounts due in 12 hours Lab Assignment 4a Due: June 13th by 9:00 pm Complete the following Programming Assignment. Use good programming style and all the concepts previously covered. Submit the java files electronically through Canvas by the above due date in 1 Zip file Lab4.Zip. (This is from the chapter on Inheritance.) 9. BankAccount and SavingsAccount Classes Design...

  • the programing language is C++ TIC PEO. Design a generic class to hold the following information...

    the programing language is C++ TIC PEO. Design a generic class to hold the following information about a bank account! Balance Number of deposits this month Number of withdrawals Annual interest rate Monthly service charges The class should have the following member functions: Constructor: Accepts arguments for the balance and annual interest rate. deposit: A virtual function that accepts an argument for the amount of the deposit. The function should add the argument to the account balance. It should also...

  • please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank...

    please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much! public abstract class BankAccount {    //declare the required class variables    private double balance;    private int num_deposits;    private int num_withdraws;    private double annualInterest;    private double serviceCharges;       //constructor that takes two arguments    // one is to initialize the balance and other    // to initialize the annual interest rate       public BankAccount(double balance,...

  • Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement...

    Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement a constructor that takes the balance (float). –Provide abstract methods deposit(amount) and withdraw(amount) •Design a class called SavingsAccount which extends BankAccount. –Implement a constructor that takes the balance as input. –It should store a boolean flag active. If the balance at any point falls below $25, it sets the active flag to false. It should NOT allow the balance to fall below $0. –If...

  • solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...

    solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT