Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment you will demonstrate a simple use for synchronization in Java. Please zip & submit your code via Sakai. Create a bank account
For this assignment you will demonstrate a simple use for synchronization in Java. Please zip \& submit your code via Sakai. Create a bank account class called Account using Java with methods deposit \& withdraw. The deposit method should accept attribute amount \& update balance to the sum of amount \& balance. Similarly, the withdraw method should accept the attribute amount \& update the balance 'balance - amount' if balance >= amount or print an error otherwise. Below is the stub. public class Account \{ private double balance =0; public Account(double balance) \{ this. balance = balance; \} public void deposit(double amount) \{ //Implementation here \} public void withdraw(double amount) \{ //Implementation here \}) Create 2 thread classes ( 1 for withdrawal and 1 for deposit). The stub is below: public class WithdrawThread implements Runnable \{ private Account account; private double amount; public WithdrawThread(Account account, double amount) \{ //Set the account \& balance \} public void run() \{ //make a withdrawal \} \} //end WithdrawThread class public class DepositThread implements Runnable \{ private Account account; private double amount; public DepositThread(Account account, double amount) \{ //Set the account \& balance \} public void run() \{ //make a deposit \}\} //end DepositThread class Create a main class below and run it. Provide output by printing out the balance to the screen at each step. public class InternetBankingSystem \{ public static void main(String [] args ) \{ Account accountObject = new Account (100); new Thread(new DepositThread(accountObject,30)).start(); new Thread(new WithdrawThread(accountObject,30)).start(); y// end main() \}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started