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

JavaLabassign8

The document contains a Java source code for a banking application that allows two customers to deposit and withdraw money simultaneously using threads. The Bank class has synchronized methods to ensure thread safety during deposit and withdrawal operations. The main method initiates two customer threads that interact with the Bank instance to perform transactions.

Uploaded by

NIKLAUS
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)
1 views

JavaLabassign8

The document contains a Java source code for a banking application that allows two customers to deposit and withdraw money simultaneously using threads. The Bank class has synchronized methods to ensure thread safety during deposit and withdrawal operations. The main method initiates two customer threads that interact with the Bank instance to perform transactions.

Uploaded by

NIKLAUS
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

Name: B.

Latha Sagar

RegNo: 12204652

Roll No: 42

Section: D2212

Course Code: CAP680

Assignment-8

source code:

package assignment;

import java.util.*;

public class Bank

synchronized void deposit()

System.out.println("Enter the amount to deposit :");

Scanner sc=new Scanner(System.in);

int deposit=sc.nextInt();

System.out.println("Amount Successfully Deposited "+deposit);

System.out.println("Enter amount for withdraw :");

int withdraw=sc.nextInt();

System.out.println("Amount Successfully withdrawn "+withdraw);

int totalBalance=deposit-withdraw;

System.out.println("Total current balance : "+totalBalance);

try {
Thread.sleep( 1000);

catch(Exception e)

public static void main(String[]args)

Bank s=new Bank();

Customer1 f=new Customer1(s);

Customer2 a=new Customer2(s);

f.start();

a.start();

class Customer1 extends Thread

Bank s1;

Customer1( Bank s1)

this.s1=s1;

public void run()

s1.deposit();

class Customer2 extends Thread

{
Bank s2;

Customer2( Bank s2)

this.s2=s2;

public void run()

s2.deposit();

Output:

You might also like