Problem aa savings account object holds a nonnegative

Assignment Help JAVA Programming
Reference no: EM13370825

Problem A

A savings account object holds a nonnegative balance, and provides deposit(k ) and withdraw(k ) methods, where deposit(k ) adds k to the balance, and withdraw(k ) subtracts k, if the balance is at least k, and otherwise blocks until the balance becomes k or greater. getbalance() gives the current balance.

1. Implement this savings account using locks and conditions (use any of the Readers-Writers lock from chapter 8). Test by using the 3 functions.

2. Now suppose there are two kinds of withdrawals: ordinary and preferred. Devise an implementation that ensures that no ordinary withdrawal occurs if there is a preferred withdrawal waiting to occur.

3. Now let us add a transfer() method that transfers a sum from one account to another:

1    void transfer(int k, Account reserve) {

2            lock.lock();

3            try {

4                  reserve.withdraw(k);

5                  deposit(k);

6            } finally lock.unlock();

7   }

We are given a set of 10 accounts, whose balances are unknown. At 1:00, each of n threads tries to transfer $100 from another account into its own account. At 2:00, a Boss thread deposits $1000 to each account. Is every transfer method called at 1:00 certain to return?

Problem B

Consider the following conditions: An enqueuer waiting on a full-queue or a dequeuer waiting on an empty queue sleep indefinitely, unless woken up by another thread. A thread must send a signal ONLY when it adds an element to an empty queue or removes an element from a full-queue.

1. Implement a bounded partial queue by using a signaling mechanism (your own scheme) that signals to only one waiting dequeuer or enqueuer, and ensure that the lost-wake-up problem does not happen.

2. Implement the same using a signaling mechanism that signals to all waiting dequeuers.

3. Do a performance comparison using timing analysis. Which works faster?

Reference no: EM13370825

Questions Cloud

Schedulingscheduling is explicitly part of our lives we : schedulingscheduling is explicitly part of our lives. we schedule everything and need to in order to plan our
Snmp securitybullsnmpv1 is the most commonly used version : snmp securitybullsnmpv1 is the most commonly used version of snmp even though it provides little support for security.
Your friend has a small design shop with windows nt 40 : your friend has a small design shop with windows nt 4.0 windows 2000 and windows xp workstations. he has one older
1 what is mm capital structure theory with corporate taxes : 1. what is mm capital structure theory with corporate taxes but no personal taxes and bankruptcy costs?2. what is the
Problem aa savings account object holds a nonnegative : problem aa savings account object holds a nonnegative balance and provides depositk and withdrawk methods where
Assignment problems1 suppose the revenue for a firm is : assignment problems1. suppose the revenue for a firm is 2500000. its cost of goods sold is 85000 and its average
Give an example of a good decision you made that resulted : give an example of a good decision you made that resulted in a bad outcome or an example of a bad decision you made
Requirementspig is a folk jeopardy dice game with simple : requirementspig is a folk jeopardy dice game with simple rules two players race to reach 100 points. each turn a player
A particle moving in a straight line with constant : a particle moving in a straight line with constant accelaration is having initial velocity of 10 ms. after some time

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create java program to describe inheritance and polymorphism

Create a Java program based on the geometric shapes example described at the beginning of this lesson using Classes Square, Triangle, Rectangle, and Circ leto help describe inheritance and polymorphism.

  Class diagram represents the relationship between parents

Draw a class diagram that represents the relationship between parents, children, and grandparents. Take into account that a person can have both a parent and a child. Annotate associations with roles and multiplicities.

  How does a client send a string ti the server using udp

How does a client send a string ti the server using UDP? Show what the client would do to get data from some string, and create a datagram packet destined for a server at "www.google.com", port 12345.

  Rewrite this code in order to ask the user for input

rewrite this code in order to ask the user for input and then coverth it from infex to postfix ,, so i want to put a Scanner and this ask the user for input .. how to do it ?

  Task 1 create a new project in eclipsecreate a package

task 1 create a new project in eclipse.create a package called lsquopeople within this project. download the start up

  Object-oriented gui drawing editor

A simple object-oriented GUI drawing editor that allows a user to create, move and erase rectangles, squares, circles and lines in an interactive graphics. How can I draw move erase rectangles, squares, circles and lines in GUI/java.

  Summary of the case astrazeneca-unitedhealth

What is the summary of the case "AstraZeneca, UnitedHealth, and Others: IT-Asset Management- Do you know what youv've got?"

  Aimthe problem and implementing the design using principles

aimthe problem and implementing the design using principles of correct syntax program structure and

  Write a program using an array that will store

Using java programing : Write a program using an array that will store input data. Prompt the user for and read 6 numbers between 70 and 90. Verify the numbers should be greater than 70 and less than 90. If the number is less than

  Explain a gui interface using advanced java swing classes

Implement a threads and a GUI interface using advanced Java Swing classes. The project will be graded according the criteria for the final project

  User session mgr - socket and thread programs

User Session Mgr - Socket and Thread Programs

  To report the amount of the fine

To report the amount of the fine, which is $25 for the first hour or pan of an hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is illegally parked

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd