Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Exp.3 Program

The document contains a Java program defining an 'Account' class with methods for initializing account details, depositing, withdrawing, checking balance, and displaying account information. It also includes a test class 'Exp3_1' that demonstrates the functionality of the 'Account' class by creating an account, performing deposits and withdrawals, and checking the balance. The code has been corrected for syntax and logical errors to ensure proper functionality.

Uploaded by

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

Exp.3 Program

The document contains a Java program defining an 'Account' class with methods for initializing account details, depositing, withdrawing, checking balance, and displaying account information. It also includes a test class 'Exp3_1' that demonstrates the functionality of the 'Account' class by creating an account, performing deposits and withdrawals, and checking the balance. The code has been corrected for syntax and logical errors to ensure proper functionality.

Uploaded by

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

Program :

import java.io.*;

class Account {
int acc_no; // Corrected variable name
String name;
float amount;

// Method to initialize object


void insert(int a, String n, float amt) { // Corrected method signature
acc_no = a; // Corrected variable name
name = n; // Corrected assignment
amount = amt; // Corrected assignment
}

// Deposit method
void deposit(float amt) { // Corrected method signature
amount += amt; // Corrected assignment
System.out.println(amt + " deposited");
}

// Withdraw method
void withdraw(float amt) { // Corrected method signature
if (amount < amt) { // Added opening brace for if statement
System.out.println("Insufficient Balance");
} else {
amount -= amt; // Corrected assignment
System.out.println(amt + " withdrawn");
}
}

// Method to check the balance of the account


void checkBalance() { // Removed space in method name
System.out.println("Balance is: " + amount);
}

// Method to display the values of an object


void display() { // Corrected method signature
System.out.println(acc_no + " " + name + " " + amount); // Fixed output formatting
}
}

// Creating a test class to deposit and withdraw amounts


class Exp3_1 { // Corrected class declaration with curly braces

public static void main(String[] args) {


Account a1 = new Account(); // Fixed object creation syntax
a1.insert(832345, "Ankit", 1000); // Fixed method call syntax

a1.display(); // Fixed method call syntax

a1.checkBalance(); // Fixed method call syntax

a1.deposit(40000); // Fixed method call syntax

a1.checkBalance(); // Fixed method call syntax

a1.withdraw(15000); // Fixed method call syntax

a1.checkBalance(); // Fixed method call syntax

}
}

You might also like