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

Java Practical 03

Java Practical 03

Uploaded by

Riya Jayswal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Java Practical 03

Java Practical 03

Uploaded by

Riya Jayswal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Input:-

Java Practical 03:-

// Creating an account class within mass deposit() and

// creating a test class to deposit and withdraw amount

public class Account{

int acc_no;

String name;

float amount;

// Method to intalize object

void insert(int a, String n, float amt){

acc_no = a ;

name = n;

amount = amt; }

// Despoit method

void deposit(float amt){

amount = amount+amt;

System.out.println(amt+" Deposited"); }

// withdraw method

void withdraw (float amt){

if(amount< amt){

System.out.println("Insufficient balance"); }

else{

amount = amount-amt;

System.out.println(amt+" withdrawn"); } }

void checkBalance(){

System.out.println("Balance is: "+amount); }

// method to display the values of an object


void display(){

System.out.println(acc_no+" "+name+" "+amount); }

public static void main(String[] args){

Account a1 = new Account();

a1.insert(12345,"Aditi",4000);

a1.display();

a1.checkBalance();

a1.deposit(45000);

a1.checkBalance();

a1.withdraw(25000);

a1.checkBalance(); } }

• Output:-

12345 Aditi 4000.0

Balance is: 4000.0

45000.0 Deposited

Balance is: 49000.0

25000.0 withdrawn

Balance is: 24000.0

You might also like