0% found this document useful (0 votes)
4 views

exp3java

The document outlines a Java program for a bank account class, including data members such as depositor name, account number, account type, and balance. It features methods for initializing values, depositing and withdrawing amounts with balance checks, and displaying account details. The main method demonstrates the functionality of the class with an example account.

Uploaded by

akshatpawar2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

exp3java

The document outlines a Java program for a bank account class, including data members such as depositor name, account number, account type, and balance. It features methods for initializing values, depositing and withdrawing amounts with balance checks, and displaying account details. The main method demonstrates the functionality of the class with an example account.

Uploaded by

akshatpawar2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy