Solved programming problem

Use Normal Bank Account work in Java.

Source code

Main Method: 

 

package bank;

import java.util.Scanner;

/**

 *

 * @author Sabit

 */

public class BankAccountTest {

    public static void main(String[] args) {

        String name;

        int id;

        double balance, temp;

        BankAccount A;

        Scanner S = new Scanner(System.in);

        System.out.println("Name: ");

        name = S.nextLine();

        System.out.println("Account Id: ");

        id = S.nextInt();

        System.out.println("Balance: ");

        balance = S.nextDouble();

        A = new BankAccount(name, id, balance);

        ///use all method 

        System.out.println("Balance: " + A.getBalane());

        ///deposit

        System.out.printf("Please Enter the Value You Want to Deposit: ");

        temp = S.nextDouble();

        A.deposit(temp);

        System.out.println("After deposit total Balance: " + A.getBalane());

        ///withdraw

        System.out.printf("Please Enter the Value You Want to withdraw: ");

        temp = S.nextDouble();

        A.deposit(temp);

        System.out.println("After withdraw total Balance: " + A.getBalane());

        ///display 

        System.out.println("Totla info: ");

        A.display();

    }

}

 

 

 

BankAccount Class:

 

package bank;

/**

 *

 * @author Sabit

 */

public class BankAccount 

{     

    private String name;

    private int accId;

    private Double balance;

    

    ///constructor

    public BankAccount(String name,int id,double balance )

    {

        this.name = name;

        this.accId = id;

        this.balance = balance;

    }

    

    public  double getBalane()

    {

         return balance;       

    }

    

    public void deposit(double amount) 

    {

        balance += amount;

       

    }

    

    public void withdraw(double amount) 

    {

        balance -= amount;

        

    }    

    

    public void display() ///display all info

    {    

         System.out.println("Your Name: "+name);

         System.out.println("Your Id: "+accId);

         System.out.println("Your Total Balance: "+balance);

    }

        

}

Output

Name:

Sabit

Account ID:

123

Banalance:

500.30

Banalance: 500.30

Please enter the value you want to deposit: 50.50

After deposit total balance is: 550.8

Please enter the value you want to withdraw: 40.5

After withdraw total balance is: 510.3

Total info:

Your name: Sabit

Your ID: 123

Your total balance: 510.3

Join the discussion

Add your comment