Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are two types of threads: student (s) and clerk (s) students deposit or wi

ID: 3756191 • Letter: T

Question

There are two types of threads: student (s) and clerk (s) students deposit or withdraw money into or from a shared fund. The clerk (s) assist the student when necessary Each student may withdraw or deposit an arbitrary amount of money. Amount is randomly generated before each deposit or withdrawn transaction. If a student needs to withdraw more than $500.00, (s) he will ask an available clerk for assistance. The clerk will withdraw the amount on behalf of the student, and let know the (appropriate) student when done. Default values: Number students10 Number clerks3 Develop a monitor implementation to synchronize clerks' and students' actions. You can use two methods named: deposit(amount) and withdraw(amount) and besides these, if necessary, you can use other service methods as well. (draw the monitor picture, give the thread execution code, give service methods' pseudo-code, initialization, condition variables....). Use the concept of monitors: condition variables have names, are implemented as queues with FIFO policy. Don't use notify All. You can use any of the two signal policies but specify which one you use. You should minimize the possibility of starvation or deadlock; also try to make your implementation as efficient as possible. Submit one monitor solution for the entire group (together with the other handouts). The group-monitor solution must have the names of all members.

Explanation / Answer

Program:
//SavingsAccount.java - Jimmy Kurian
public class SavingsAccount
{
private double balance;
private double interest;
public SavingsAccount()
{
balance = 0;
interest = 0;
}
public SavingsAccount(double initialBalance, double initialInterest)
{
balance = initialBalance;
interest = initialInterest;
}
public void deposit(double amount)
{
balance = balance + amount;
}
public void withdraw(double amount)
{
balance = balance - amount;
}
public void addInterest()
{
balance = balance + balance * interest;
}
public double getBalance()
{
return balance;
}
}
//SavingsAccountTester.java - Jimmy Kurian
public class SavingsAccountTester
{
public static void main(String[] args)
{
SavingsAccount jimmysSavings = new SavingsAccount(1000, 0.10);
jimmysSavings.withdraw(250);
jimmysSavings.deposit(400);
jimmysSavings.addInterest();
System.out.println(jimmysSavings.getBalance());
System.out.println("Expected: 1265.0");
//1000-250=750 => 750+400=1150 => 1150+1150*0.10=1265.0
}
}

end

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote