BankAccount.java
public class BankAccount {
String name;
private double balance;
private int depositCount = 0;
private int withdrawCount = 0;
public void deposit(double amount){
balance += amount;
System.out.println(amount + " is successfully Deposited");
depositCount++;
}
public void withdraw(double amount){
if(balance >= amount){
balance -= amount;
System.out.println(amount + " is successfully Withdrawn");
withdrawCount++;
}
else{
System.out.println("Insufficient funds");
}
}
public double getBalance(){
return balance;
}
void transaction(){
System.out.println("Account title: " + name);
System.out.println("Total deposit: " + depositCount);
System.out.println("Total withdraw: " + withdrawCount);
System.out.println("Balance: " + balance);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
BankAccountTest.java
import java.util.Scanner;
public class BankAccountTest{
public static void main(String args[]){
BankAccount account = new BankAccount();
Scanner input = new Scanner(System.in);
account.name = "Maan";
int choice;
do{
System.out.println("Press 1: To Deposit an amount\nPress 2: To Withdraw an amount\nPress 3: To View the current balance\nPress 4: To Close the program");
choice = input.nextInt();
switch(choice){
case 1:
System.out.println("Enter the amount you want to Deposite");
double depositeAmount = input.nextDouble();
account.deposit(depositeAmount);
break;
case 2:
System.out.println("Enter the amount you want to withdraw");
double withdrawAmount = input.nextDouble();
account.withdraw(withdrawAmount);
break;
case 3:
System.out.println("Your current balance is " + account.getBalance());
break;
case 4:
System.out.println("The program is terminated");
account.transaction();
break;
default:
System.out.println("Incorrect choice. Please try again!");
break;
}
}while(choice!=4);
}
}