Java program to create a class account using the inheritance and static that show all function of the bank (Withdrawal, Deposit).

 

package inheritance;

import java.util.Scanner;

 class account{

    static int acc_no=3451001 ;

    float amt;

    public void display(){

  System.out.println("Ur account no is " + acc_no);   

  System.out.println("Ur current amount in account is " +amt);

  }

  public account(){

      amt=5000;

      System.out.println("Your account No is: "+acc_no);

      acc_no++;

  }

 public void getamt() {

  System.out.println("Current balance :" + amt);

 }

 public void withdraw(float x) {

  if ((amt) == 1000 || (amt <= x)) {

     System.out.println("Sorry u can't withdraw");

  } else {

   amt = amt - x;

   System.out.println("amount withdrawn :" + x);

   System.out.println("After withdrawl");

   getamt();

  }

 }

 public void deposit(float x) {

  if (x == 0.0){

      System.out.println("OOPS 0 can't be deposited");

  }else {

   amt += x;

   System.out.println("After deposition");

   getamt();

  }

 }

}

    public class Inheritance {

    public static void main(String[] args) {

      account a1=new account();

      Scanner sc = new Scanner(System.in);

      System.out.println("Enter your choice");

      System.out.println("1. Deposit");

      System.out.println("2. Withdrawl");

              

       int choice=Integer.parseInt(sc.nextLine());

                   

        switch(choice){

             case 1:

                 a1.display();

                 System.out.println("Enter the amount to Deposit");

                 float t=sc.nextFloat();

                 a1.deposit(t);

                 break;

             case 2:

                 a1.display();

                 System.out.println("Enter the amount to withdraw");

                 float s=sc.nextFloat();

                             

                 a1.withdraw(s);

                 break;

             default:

                 System.out.println("Please select your choice between 1-2");

        }

              System.out.println("\n");

           }

   }

OUTPUT:





No comments:

Post a Comment