You will be assigned to a random team of two students for this Lab. You should work with your assigned partner, helping each other with the technical details of this Lab.
First download and import the starting Eclipse Java Project named 601_lab_4.zip.The instructions for doing this will be given in class. You will then use it to develop Java code as requested below.
Each problem asks you to create a Java application (class with main()) with the name given in blue. Do so.
Your deliverables for this Lab 4 are as follows. Rename (Refactor->Rename...) your Eclipse project with your final code to Lab-4-name1-name2, then export it to an archive (zip) file named Lab-4-name1-name2.zip Finally, upload this archived project to the Lab 4 assignment link within the Class 4 module on our Canvas site.
Do as many of the following as you can. We will discuss each in class.
[L4-1] (Trace.java) The starting class contains four different code fragments that work with the int array a[]. Note how you can create a new array outside a declaration using new int[]{...}. Trace each of these by hand - BEFORE you run the code to see if your traces were correct.
[L4-2] (Explain.java) The starting class contains three more code fragments that work with the int array a[]. Write one sentence as a comment before each fragment that describes what it does.
[L4-3] (Weekdays.java) Write a program that reads int daynum from the console (use StdIn.readInt()). (The starting code does this for you.)
Then print out the corresponding day name two different ways: once using if-else if, and a second time by using daynum to index into the given String array DAYS.
Use the correspondence: 1->Sunday, 2->Monday, ...., 7->Saturday. Also note how the empty String "" is stored in DAYS[0], which allows you to directly index DAYS with the input daynum. This approach allows you to eliminate long chained conditionals.
You may assume that N is in the correct range 1..7.
[L4-4] (DieRoll.java) Write a program that reads int N from the console (use StdIn.readInt()), generates N random int values in the range [1,6], and counts their frequencies using a int array counts, with counts[i] as the number of times the value i is obtained. Finally, iterate over counts and print out its values in a table as follows, followed by the value of N/6.0 (which is the expected value of each count[i]):
Roll Count
1 5
2 7
3 6
4 8
5 8
6 2
Expected count: 6.0
Try using StdOut.printf("...%dt%dn",roll,count[roll]) to handle the output.
[L4-5] (DeckPair.java) The starting code is a modification of the Deck.java program found in Section 1.4 on arrays. It introduces methods: callable functions that are easily accessed from within your own code. Don't worry about understanding all of the code, since it uses some Java we haven't covered yet.
We see how to use the Eclipse debugger to understand how this code executes.
Then add code which does the following. Shuffle the deck, then check if the top two cards are a pair: both cards having the same rank. Do this 1000 times, counting the number of times this occurs, and print out this fraction.
Use the provided getRank(String card) helper function to extract the rank of a card. To check if two String values s1 and s2 are equal, use the boolean method: s1.equals(s2).