0% found this document useful (0 votes)
6 views2 pages

Worksheet Template OBJECT ORIENGTED USING JAVA

The document outlines an experiment for a Computer Science and Engineering course, focusing on creating a Java class named BankAccount. The class includes methods for depositing, withdrawing, and checking the account balance, with sample code provided. The aim is to implement basic banking functionalities in Java, demonstrated through a main method that showcases the class in action.

Uploaded by

testmail31102003
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)
6 views2 pages

Worksheet Template OBJECT ORIENGTED USING JAVA

The document outlines an experiment for a Computer Science and Engineering course, focusing on creating a Java class named BankAccount. The class includes methods for depositing, withdrawing, and checking the account balance, with sample code provided. The aim is to implement basic banking functionalities in Java, demonstrated through a main method that showcases the class in action.

Uploaded by

testmail31102003
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/ 2

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1.1
Student Name: Neelketu UID: 23BCS12594
Branch: BE.CSE Section/Group: 604-A
Semester: 4th Date of Performance:26-01-25
Subject Name: JAVA Subject Code: 23CSP-202

1. Aim: Create a class with methods for deposit, withdrawal, and checking
the balance, and instantiate it.

2. Objective:

To design and implement a BankAccount class with methods for handling


deposits, withdrawals, and balance inquiries. This will include:
• A deposit() method to add funds to the account.
• A withdraw() method to subtract funds from the account, ensuring that
withdrawals do not exceed the available balance.
• A get_balance() method to retrieve and display the current account
balance.

3. Java Code:

class BankAccount {
private double balance;

public BankAccount(double initialBalance) {


this.balance = initialBalance;
}

public void deposit(double amount) {


if (amount > 0) {
balance += amount;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

}
}

public void withdraw(double amount) {


if (amount > 0 && amount <= balance) {
balance -= amount;
}
}

public double getBalance() {


return balance;
}

public static void main(String[] args) {


BankAccount account = new BankAccount(1000.0);
account.deposit(500.0);
account.withdraw(200.0);
System.out.println("Current balance: " + account.getBalance());
}
}

4. Output:

You might also like