This action might not be possible to undo. Are you sure you want to continue?

Practical 4 2012

Complete the following questions from the Exercises section in the textbook, Introduction to Programming in Java. Resources for certain questions, such as code libraries you are asked to use and example input and output ﬁles which can be used for development of your programs can be found on the course website. You have to hand in your answers to these questions. In order to keep all the ﬁles in one place you have to tar your ﬁles. A quick tutorial on tar is given below.

Tar how-to

We use tar to archive multiple ﬁles in one ﬁle for convenience. For more information on tar see the man pages: man tar To create a tar archive: tar cvf archive.tar file1 file2 file3 To extract the ﬁles contained in a tar archive: tar xvf archive.tar You must use the format <student#> prac<prac#>.tar for your tar ﬁle name. Hand-in date: 23:59 Sunday 4 March 2012.

1

2.2.24 [20]

Voting machines. Suppose that in a population of 100 million voters, 51% vote for candidate A and 49% vote for candidate B. However, the voting machines are prone to make mistakes, and 5% of the time they produce the wrong answer. Write a program VotingMachines to simulate the election. Assuming that the errors are made independently and at random, is a 5% error rate enough to invalidate the results of a close election? Use your simulation program to determine what error can be tolerated.

2

2.2.25 [20]

Poker analysis. Write a program PokerAnalysis which uses the given libraries StdRandom and StdStats to estimate the probability of getting one pair, two pair, three of a kind, a full house, a ﬂush, and a straight ﬂush, in a ﬁve-card poker hand via simulation1 . Your program should take a command line argument N which is the

1 The

probabilities given have been made up. They are not the correct answer!

1

number of players playing in a game and a command line argument M which is the number of games which should be played. Each time a new game is played the deck needs to be shufﬂed. Divide your program into appropriate static methods and defend your design decisions by commenting your methods properly. An example of what your output should look like is given below. Using tabs will help for readability, but is not necessary.

$ java PokerAnalysis 4 10000 One pair: 0.31239 Two pair: 0.27453 Three of a kind: 0.18623 Full house: 0.07342 Flush: 0.02862 Straight flush: 0.00001

In this example there are four players who are playing 10000 games.

3

Barnsley fern [20]

Write a program Barnsley that takes a command line argument N and plots a sequence of N points according to the following rules. Set (x, y) = (0.5, 0). Then update (x, y) to one of the following four quantities according to the probabilities given. PROBABILITY 2% 15% 13% 70% NEW X 0.5 −0.139x + 0.263y + 0.57 0.170x − 0.215y + 0.408 0.781x + 0.034y + 0.1075 NEW Y 0.27y 0.246x + 0.224y − 0.036 0.222x + 0.176y + 0.0893 −0.032x + 0.739y + 0.27

4

2.3.17 [Optional]

Permutations. Write a program Permutations that takes a command line parameter n and prints out all n! permutations of the n letters starting at “a” (assume that n is no greater than 26). A permutation of n elements is one of the n! possible orderings of the elements. As an example, when n = 3 you should get the output given below. Don’t worry about the order in which you enumerate them.

$ java Permutations 3 bca cba cab acb bac abc

5

The Erlang loss formula [40]

The Erlang loss formula otherwise known as the Erlang B-formula is very well-known in the telecommunications literature B(N, ρ) = ρN /N !

N n=0

ρn /n!

(1)

2

where ρ = λ/µ where λ is the arrival rate of telephone calls (measured in calls per second) to a switch that can carry maximally N calls, and 1/µ is the average duration (measured in seconds) of a call. B(N, ρ) is the probability that a call is lost because all N circuits are busy. In telephony jargon, λ is called the offered trafﬁc per unit time and ρ the offered load. The load ρ is measured in units of “Erlangs”. Eqn. (1) looks easy to evaluate, but think of the situation where ρ = 100 and N = 200. Then there is a term of the form (100)200 /200! that needs to be evaluated, and this is difﬁcult to do exactly, even for a computer. To get around this we use a recursive formulation for B(N, ρ) which calculates B(N, ρ) in terms of B(N − 1, ρ) B(N, ρ) = where B(0, ρ) = 1. 1. Write a recursive program Erlang which takes two command line arguments N and ρ and computes the blocking probability B(N, ρ) using Eqn. (2). 2. Estimate the number of recursive calls that are used by the code. 3. Develop a non-recursive implementation to compute B(N, ρ). ρ B(N − 1, ρ) N + ρB(N − 1, ρ) (2)

3

(a) 500 iterations

(b) 1000 iterations

(c) 10000 iterations

Figure 1: The pictures show the results after 500, 1000, and 10,000 iterations.

4

- Environmental Engineering 442 Group Project (1)
- CS214 ALGORITHMS AND D ATA STRUCTURES
- Introduction to Spice for Electronics 315
- CS214_Tut3_2011_mocktest
- CS214_Tut3_2011_mocktest
- rwe214_prac6
- rwe214_prac5
- rwe214_prac3
- rwe214_prac2
- C-Refcard
- PCMag 18-09-2007
- Waves Principles of Light Electricity and Magnetism Secrets of the Universe
- Basic Electronics

Sign up to vote on this title

UsefulNot useful- Install AR8151 Driver Di ProxmoxVE1.9
- Teor_Traf
- Erlang Table B
- intro-unixlinux-11-4285
- 18 Tar Command Examples in Linux
- Over Sim Install
- Basic Unix Commands
- crux.pdf
- Cisco ME 3400 Ethernet Access Switch Command Reference IOS 12-2-40 SE
- SQL SERVER COMMANDS USED FOR SQL SERVER EASY TO LEARN AND EASY TO UNDERSTAND
- Mysql 5
- Thelinuxstuff.blogspot.in 2011 11 Interview Linux Question Answers Part 2.HTML
- UNIX_part+3(2)
- Movation Circuit
- Math Academy Mall
- Shell Scripting
- WAS Over
- Mangoosh GRE E-Book.pdf
- Objects in Windows Server 2003
- Loading Metadata Using the Outline Load Utility
- Hands on Obiee 11g
- Legacy CLI Quick Reference Guide
- HP StoreEasy firmware Downgrade
- PowerGUI_3.5_UserGuide
- Montecarlo Simulation Technical Analysis
- Notes
- Cross Reference; What is It, How Does It Work, Why Would I Need It
- Basic AutoLISP Commands
- Baisc Autolisp Commands
- CUCM Cli Reference
- rwe214_prac4

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.