Write program that simulate the operation of bank account

Assignment Help Programming Languages
Reference no: EM131200841

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.

Reference no: EM131200841

Questions Cloud

Obtain information about the firms strength : List at least four sources you will use to obtain information about the firms strength, weakness, opportunities, and threats. Discuss what categories of the SWOT elements of information are readily available on the internet. What categories of dat..
Discuss what hr did during that time : Discuss how the use of technology (such as an HRIS) has helped to facilitate the evolution of HR from an administrative function to one that is more strategic. Provide examples from a managerial perspective. Select an era and discuss what HR did d..
Improving workers and patients safety in a healthcare setup : Identify the legal and ethical issues that may affect the outcome of your project, and briefly describe the potential impact (for example, copyright issues that must be resolved).
How individuals accomplishments have inspired your career : Include in your paper why you selected the individual and how this individual's accomplishments have inspired your career goals. Be prepared to discuss your selected Engineer during class.
Write program that simulate the operation of bank account : 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/..
Professionalism play in team development : What role does professionalism play in team development? Why is professionalism important? How can the leader of a team ensure honest and fair dealings with all team stakeholders?
Determining the employment contract : 1. What type of information should be included in an employment contract? 2. How will you advise relevant staff of a new employee's appointment, start date, and administrative arrangements for pay and employee record keeping?
What environmental problems do open dumps cause : Describe an open dump. What environmental problems do open dumps cause?  Describe an early landfill, and how these differ from open dumps. What problems are associated with early landfills?
What plan might you propose to reduce or eliminate their use : What plan might you propose to reduce or eliminate their use? Discuss the economic impacts of implementing your plan versus the financial impacts of making no change in our current use.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a program that will take a string

Write a program that will take a string, parse it, and then calculate the value in post-fix (reverse polish) notation.

  Create a three-page website that displays text and links

Create a three-page website that displays text and links, demonstrating effective use of the basic code from chapter 2. You will build three (3) new HTML documents, and must use http://www.lipsum.com to generate placeholder text for the written co..

  Write program to calculate tips for services rendered

Write program to calculate tips for services rendered. The program must request person's occupation, amount of the bill and the percentage tip as input

  Assume the filling process is so slow that the tank air

a large compressed air storage tank with a volume of 100 m3is initially at 200 kpa and 288 k. the supply line valve is

  Write a program to input a purchase amount

Write a program to input a purchase amount and calculate the sales tax and total do. The SalesTax depends on the county identifying code

  Write program to enter number of packages purchased

Write a program that asks the user to enter the number of packages purchased.The program should then display the amount of the discount.

  Rewrite the extract.pl using bioperl

Rewrite the "extract.pl" using BioPerl, including the use of Bio::SeqIO to read the genome FASTA file ("mystery_seq1.fas") and the use of Bio::Seq for obtaining coding sequences and translating sequences.

  Write pseudocode-read in data file containing student name

Write a pseudocode to do the following Read in data file containing student names, ID number, and gender into an array.

  Assignment program on crawler game

Update the Crawler game attached to allow a user to traverse the Cave. They should be prompted in each room to pick an exit or quit

  Write subclass for constructor accepting a double

Write a (non-abstract) subclass, ApartmentHouse, containing: a constructor accepting a double, passed to the superclass constructor, and an int used to initialize numberOfApartments

  Program to calculate volume flow rate in cubic feet

Write a program to calculate the volume flow rate in cubic feet per second of water flowing through a pipe of diameter d in inches and a velocity of v feet per second.

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