Lab3 java

mail@pastecode.io avatar
unknown
plain_text
16 days ago
3.2 kB
3
Indexable
Never
//CSE 2200
//Advanced Programming
//Batch: 2K21
//Lab Task 02: Group 1
//We all know that java is an object-oriented programming language. Suppose you are
//assigned to develop a banking system using the basic concepts of OOP in java. The
//system consists of a class named BankAccount which has the following private
//attributes (depositorName, typeOfAccount, AccountNumber and Balance) and
//public methods (constructor, depositAmmount, withdrawAmmount,
//displayNameAndBalance). There will be two types of account for 3 banks (Agrani,
//Sonali, Janata) in consideration: Savings and FixedDeposit. The interest rate for
//savings is 1% for all banks. Whereas, the interest rate for Fixed Deposit account is 3%
//for Agrani Bank, 2.5% for Janata Bank and 2% for Sonali Bank


class BankAccount{
    private String name;
    private String type;
    private String accountNum;
    private double Balance;

    //constructor
    public BankAccount(String name, String type,String accountNum, double Balance) {
        this.name= name;
        this.type=type;
        this.accountNum=accountNum;
        this.Balance=Balance;
    }

    //deposit ammount
    public void depositAmmount(double ammount){
        if(ammount<0){
            System.out.println("Your ammount is Invalid!!!!");
        }
        else{
            Balance+=ammount;
            System.out.println("Deposit ammount = "+ammount+" is successful");
        }
    }

    //withdrawAmmount
    public void withdrawAmmount(double ammount){
        if(Balance>=ammount && ammount>0){
            Balance-=ammount;
            System.out.println("Successfully withdraw "+ammount+" taka. Now your current balance is: "+Balance);
        }
        else if(ammount<0){
            System.out.println("You are trying to withdraw invalid ammount");
        }
        else{
            System.out.println("You do not have sufficient Balance");
        }
    }

    //displayNameAndBalance
    public void displayNameAndBalance(){
        System.out.println("Account Holder: "+name);
        System.out.println("Account Number is: "+accountNum);
        System.out.println("Current Balance = "+Balance);
    }

    public double getInterest(){
        return 0;
    }
}


class SavingsAccount extends BankAccount{

    private static final double ir = 0.01;

    public  SavingsAccount(String name, String accountNum, double balance){
        super(name,"saving",accountNum,balance);
    }

}


/*class FixedDeposit extends BankAccount{

}*/



public class lab2 {
    public static void main(String[] args) {
        SavingsAccount savings = new SavingsAccount("abul", "2107000", 0);
        savings.displayNameAndBalance();
        savings.depositAmmount(500);
        savings.withdrawAmmount(200);
        System.out.println("Interest earned on Savings: " + savings.getInterest());
        savings.displayNameAndBalance();
     }
}























































































Leave a Comment