Java Program of Inheritance-Account

Question:

Atlas Bank is providing services for various accounts like Savings, Current,Loan for Education ,Vehicle, Home, Personal. As a first step they wanted to automate Savings Account. As a java developer, design the classes as per the given specifications

Create a Account class with the following private attributes:

accntNo – int

accntHolderName – String

accntBalance – double

Provide the appropriate getters/setters

Create another class SavingsAccount which is of type Account with the additional private attributes:

float minBalance

Provide appropriate getters/setters

Override the toString() method in the SavingsAccount class to display the details in the below format

AccountNo:<<accntNum>>-AccountHolderName:<<accntHolderName>>-AccountBalance<<accntBalance>>-MinimumBalance:<<minBalance>>

Example: AccountNo:1000-AccountHolderName:Peter-AccountBalance:80000-MinimumBalance:1000

In the TestMain class ,  get the details of Savings Account set the details and print the reference of SavingsAccount

Sample Input/Output:

Enter the AccountNumber: 4000

Enter the Account Holder Name: Rose

Enter the Account Balance: 4000

Enter the Minimum Balance: 500

AccountNo:4000-AccountHolderName:Rose-AccountBalance:4000.0-MinimumBalance:500.0

Code:

TestMain.java

import java.util.*;
public class TestMain
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the AccountNumber: ");
        int an=sc.nextInt();
        System.out.println("Enter the Account Holder Name: ");
        String hn=sc.next();
        System.out.println("Enter the Account Balance: ");
        double ab=sc.nextDouble();
        System.out.println("Enter the Minimum Balance: ");
        float mb=sc.nextFloat();
        SavingsAccount sa=new SavingsAccount();
        sa.setAccntNo(an);
        sa.setAccntHolderName(hn);
        sa.setAccntBalance(ab);
        sa.setMinBalance(mb);
        System.out.println(sa.toString());
    }
}

Account.java

public class Account
{
    private int accntNo;
    private String accntHolderName;
    private double accntBalance;
    public void setAccntNo(int accntNo)
    {
        this.accntNo=accntNo;
    }
    public int getAccntNo()
    {
        return accntNo;
    }
    public void setAccntHolderName(String accntHolderName)
    {
        this.accntHolderName=accntHolderName;
    }
    public String getAccntHolderName()
    {
        return accntHolderName;
    }
    public void setAccntBalance(double accntBalance)
    {
        this.accntBalance=accntBalance;
    }
    public double getAccntBalance()
    {
        return accntBalance;
    }
}

SavingAccount.java

public class SavingsAccount extends Account
{
    private float minBalance;
    public void setMinBalance(float minBalance)
    {
        this.minBalance=minBalance;
    }
    public float getMinBalance()
    {
        return minBalance;
    }
    @Override
    public String toString()
    {
        String str="AccountNo:"+String.valueOf(getAccntNo())+"-AccountHolderName:"+getAccntHolderName()+"-AccountBalance:"
        +String.valueOf(getAccntBalance())+"-MinimumBalance:"+String.valueOf(getMinBalance());
        return str;
    }
}

Recommended:

  1. Interest Calculator – Interface Concept
  2. Bank – Abstract concept
  3. Inheritance – Account
  4. Contact Details of Hosteller
  5. PF and Salary Calculation
  6. Check for Existence of Customer – equals method
  7. Account Manipulation – Abstract class
  8. Employee Loan Eligibility – Polymorphism

1 thought on “Java Program of Inheritance-Account”

  1. Thanks for your submission. I also believe laptop computers are getting to be more and more popular these days, and now are often the only sort of computer utilised in a household. It is because at the same time actually becoming more and more reasonably priced, their processing power is growing to the point where they may be as effective as desktop out of just a few in years past.

Leave a Comment

Your email address will not be published. Required fields are marked *

x