Bank – Abstract concept Program in java

Question:

Banks are supposed to implement their own method that returns back the rate of interest for personal loans. To implement this scenario in SBI and PNB banks they are supposed to extend the Bank class provided by the RBI that has a single abstract method called getRateOfInterest() that returns back an integer.

Develop an automated module wherein the banks SBI and PNB that have their own classes as SBI and PNB that extend from the BANK class and implements the abstract method.

The current rate of interest provided by SBI is 7% and that of PNB is 8 %

Implement the above scenario.

Sample Input and Output

Rate of Interest in SBI is: 7 %

Rate of Interest in PNB is : 8 %

CODE:

public class TestBank{
    public static void main (String[] args) {
    Bank s=new SBI();
    Bank p=new PNB();
    System.out.println("Rate of Interest in SBI is: "+s.getRateOfInterest()+" %");
    System.out.println("Rate of Interest in PNB is: "+p.getRateOfInterest()+" %");
  }
}
public class Student 
{
    private int id;
    private String name;
    private int[] marks;
    private float average;
    private char grade;
    
    public void setId(int id)
    {
        this.id=id;
    }
    
    public int getId()
    {
        return this.id;
    }
    
    public void setName(String name)
    {
        this.name=name;
    }
    
    public String getName()
    {
        return this.name;
    }
    
    public void setMarks(int[] marks)
    {
        this.marks=marks;
    }
    
    public int[] getMarks()
    {
        return this.marks;
    }
    
    public void calculateAvg()
    {   float sum=0;
        
        for(int i=0;i<this.marks.length;i++)
        {
            sum+=this.marks[i];
        }
        
        average=(float)(sum/(this.marks.length));
        setAverage(average);
    }
    
    public void findGrade()
    {int flag=0;
        for(int i=0;i<this.marks.length;i++)
        {
            if(this.marks[i]<50)
            {
                flag++;
            }
        }
        if(flag>0)
        {
            grade='F';
        }
        else
        {
            if(this.average>=80 && this.average<=100)
            {
                grade='O';
            }
            else if(this.average>=50 && this.average<=79)
            {
                grade='A';
            }
            else
            {
                grade='F';
            }
        }
        setGrade(grade);
        
    }
    
    public void setAverage(float average)
    {
        this.average=average;
    }
    
    public void setGrade(char grade)
    {
        this.grade=grade;
    }
    
    public float getAverage()
    {
        return this.average;
    }
    
    public char getGrade()
    {
        return this.grade;
    }
}
  1. Inheritance – Account
  2. Contact Details of Hosteller
  3. PF and Salary Calculation

Leave a Comment

Scroll to Top