Java program of ZeeZee Bank example

Question:-

ZeeZee bank maintains the account details for each customer. The account details are:

a.       Account number

b.      Type of account

c.       Balance amount

Consider the below class:

ZeeZee Bank
ZeeZee Bank

In the Account class include the given attributes methods and constructor with the access specifiers as specified in the class diagram.

The constructors are used to set the value and the getter methods are used to retrieve the value.

The withdraw method takes the amount to be withdrawn as argument. This method should check the balance and detect the withdrawn amount from the balance amount and return 1. If there is insufficient balance then return -1.

The deposit method takes the amount to be deposited as argument and adds the deposited amount to the balance amount.

 In the Main class, Get the details as shown in the sample input and create an object for the Account class; invoke the deposit method to deposit the amount and withdraw method to withdraw the amount from the account.

Sample Input1 & Output1:

Enter the account number:

1234567890

Enter the available amount in the account:

15000

Enter the amount to be deposited:

1500

Available balance is:16500.00

Enter the amount to be withdrawn:

500

Available balance is:16000.00

Sample Input2 & Output2:

Enter the account number:

1234567890

Enter the available amount in the account:

15000

Enter the amount to be deposited:

1500

Available balance is:16500.00

Enter the amount to be withdrawn:

18500

Insufficient balance

Available balance is:16500.00

Code:-

Main.java

import java.util.Scanner;
import java.text.DecimalFormat;
public class Main{
    public static void main (String[] args) {
        Scanner sc=new Scanner(System.in);
        DecimalFormat df=new DecimalFormat("########0.00");
        System.out.println("Enter the account number:");
        long acc_num=sc.nextLong();
        
        System.out.println("Enter the available amount in the account:");
        double bal_amt=sc.nextDouble();
        
        System.out.println("Enter the amount to be deposited:");
        double dep_amt=sc.nextDouble();
        
        Account obj= new Account(acc_num, bal_amt);
        
        obj.deposit(dep_amt);
        System.out.println("Available balance is:"+df.format(obj.getBalanceAmount()));
        
        System.out.println("Enter the amount to be withdrawn:");
        double wdw_amt=sc.nextDouble();
        
        if(obj.withdraw(wdw_amt)==-1)
        {
            System.out.println("Insufficient balance");
        }
        
        System.out.println("Available balance is:"+df.format(obj.getBalanceAmount()));
    }
    
}

Account.java

public class Account{
    private long accountNumber;
    private double balanceAmount;
    
    public Account(long accountNumber, double balanceAmount)
    {
        this.accountNumber=accountNumber;
        this.balanceAmount=balanceAmount;
    }
    
    public int withdraw(double amount)
    {
        if((this.balanceAmount-amount)>0)
        {   
            this.balanceAmount-=amount;
            return 1;
        }
        else
        {
            return -1;
        }
    }
    
    public void deposit(double amount)
    {
        this.balanceAmount+=amount;
    }
    
    public double getBalanceAmount()
    {
        return this.balanceAmount;
    }
    
}

Recommended:-

Leave a Comment

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

x