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
}
}