EXP3: Classes and Objects DATE:28/01/25
Aim: To implement the following Java Program.
Design a class to represent a bank account. Include the following members:
Data members:
Name of depositor
Account number
Type of account
Balance amount in the account
Methods
to assign initial values (Constructor)
to deposit an amount
to withdraw an amount after checking balance
to display name and balance
INPUT
package test;
public class BankAccount{
private String name;
private String accountNumber;
private String accountType;
private double balance;
public BankAccount(String name,String accountNumber,String accountType,double
balance)
{
this.name=name;
this.accountNumber=accountNumber;
this.accountType=accountType;
this.balance=balance;
public void deposit(double amount){
if(amount>0){
balance+=amount;
System.out.println("Deposited "+amount+". Current balance: "+balance);
else{
System.out.println("Deposit amount must be positive.");
public void withdraw(double amount){
if(amount>0){
if(balance>=amount){
balance-=amount;
System.out.println("Withdrew "+amount+". Current balance: "+balance);
}else{
System.out.println("Insufficient funds.");
}else{
System.out.println("Withdrawal amount must be positive.");
}
}
public void displayAccount(){
System.out.println("Account holder: "+name);
System.out.println("Account number: "+accountNumber);
System.out.println("Account type: "+accountType);
System.out.println("Current balance: "+balance);
public static void main(String[] args){
BankAccount account1=new BankAccount("Akshat","98765","Savings",10000);
account1.displayAccount();
account1.deposit(1500);
account1.withdraw(2100);
account1.withdraw(12000);
account1.displayAccount();
OUTPUT