Sunday 22 October 2017

Create Java Program for credit balance and withdraw balance fron bank account

Create an Account Class with an instance variable “balance” of type double, use set and get methods to access its value, write  two functions for “credit” and “withdraw” of money from account. Use a test class to create Account class object and use it.

Account Class:




Test Class:


Output:


CODE TEXT:

Account Class:

/**
 *
 * @author syedumarfarooq.blogspot.com
 */
public class Account {
    private double balance;
    public Account(double intialbalance){
        if (intialbalance>0.00){
            balance=intialbalance;
        }
       
    }
     public void setcredit(double amount){
            balance=balance+amount;
        }
     public double getBalance(){
         return balance;
     }
}



Test Class:


import java.util.Scanner;

/**
 *
 * @author syedumarfarooq.blogspot.com
 */
public class TestClass {
 public static void main(String[] args){
        Scanner input=new Scanner(System.in);
    Account a1=new Account(100.00);
    Account a2=new Account(200.00);
    System.out.printf("Account1 balance: %.2f \n",a1.getBalance());
     System.out.printf("Account2 balance: %.2f \n ",a2.getBalance());
    
     System.out.println("Deposit balance in Account1: ");
      double credit=input.nextDouble();
      a1.setcredit(credit);
       System.out.println("Deposit balance in Account2: ");
      double credit2=input.nextDouble();
      a2.setcredit(credit2);
     System.out.printf("Account1 balance: %.2f \n",a1.getBalance());
     System.out.printf("Account2 balance: %.2f \n",a2.getBalance());
    
 }
    
}



No comments:

Post a Comment