Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

CONCURRENT PROGRAMMING TASK YDETAILS

Many banking systems allow multiple cardholders access a single account (e.g. a business account). The consequence of this is that is possible for more than one person to attempt to withdraw or deposit money from a single account simultaneously. If the access to the account is implemented nai¨vely (ignoring the principles of concurrent programming), this can lead to race conditions, and the potential for the following fraud to be successful:

Multiple cardholders may collude and attempt to carry out a timing attack. In such an attack, multiple cardholders withdraw money from the account simultaneously, with the aim of only one deduction to the account balance being made.

Your task is to write a program (detailed specifications below) that will simulate the operation of an ATMYenabled bank account with multiple linked cards. In other words, there will be several individuals who can access an account, each with his/her own card (). You program should demonstrate the principles of concurrent programming, making it impossible for the above fraud to be successful.

DETAILED SPECIFICATIONS Your program should implement each access card as a separate thread, and the account as a monitor.

You program should take two command line arguments: the first is the number of access cards, and the second should be the starting balance. If the user does not supply these two arguments, your program should exit and give an error message. Do not use default values for these variables, or prompt the user for these values once the program has started.

Within each thread, you should use the following code to simulate a series of accesses to the account:

for (inti = 0; i< 20; i++) { if (Math.random() > 0.5) {

account.withdraw((int)(Math.random()*10)); } else {

account.deposit((int)(Math.random()*10)); sleep(200);

} System.out.println("THREAD "+ getId() + " " + localBalance);

(This code is the basis for each thread. You are expected to build upon it in you program, but should maintain the same random generation of withdrawals and deposits. If you choose to implement a runnable instead of extending the Thread class, change the line saying sleep(200); to Thread.sleep(200);.)

Only one card may access the account balance at any time. Furthermore, the account must always have a positive balance; if a thread attempts to withdraw and there are insufficient funds, it must block until sufficient funds become available. Note that this means there is a

}

6G5Z1005 CN&OS - Term 1 Handbook

9

6G5Z1005 CN&OS - Term 1 Handbook

Possibility of deadlock: if the account balance is 0 (or close to 0) and all cards request a withdrawal at this point, they may all enter the blocking state. You do not have to implement deadlock prevention, avoidance, detection or recovery; you should just accept that this may happen. (It can be avoided by starting with a small number of cards, such as 5, and a sufficiently high account balance, such as 1000.)

PROGRAM EXECUTION Your program should initialise the account (based on the balance specified on the command line), create and start the n threads (where n is the number of access cards, specified on the command line), keep a record of transactions, and when all threads are finished, print (to standard output) "Complete," followed by a statement of the transactions, in the format described below.

In addition, each thread, just before it terminates, should print out its net balance of transactions. (This is indicated by the System.out.println("THREAD "+ getId() + " " + localBalance); line of code overleaf.) The balance is the sum of all withdrawals, minus the sum of all deposits. Note that it acceptable for this to be negative; holders may deposit more than they withdraw.

STATEMENT FORMATThe statement should be in the following format:

Transaction Withdrawal Deposit Balance

 1000

  • 960

60                           1020

20                           1040

950

The number appearing in parentheses after the transaction number shows the ID of the thread responsible for the transaction.

Hint: you may wish to use String.format to achieve neatly formatted output.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91956885

Have any Question? 


Related Questions in Programming Language

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As