Question: CSC205AB MinilabArrayList Before you start this Minilab, you should be familiar with: Our demo on implementing a Stack. This Minilab will not use Stacks, but
CSC205AB MinilabArrayList Before you start this Minilab, you should be familiar with: Our demo on implementing a Stack. This Minilab will not use Stacks, but it will consist of a class that has an ArrayList as its data (just like Stack does) and uses that ArrayList to implement its own methods. What an ArrayList is and how to create one using Generics. The methods and constructors that an ArrayList has available to use. Please NOTE that an ArrayList also has a copy constructor and an equals method. They will be very handy to use to implement your logic. (If you prefer, you can use a Vector instead of an ArrayList. They are very similar and the methods/constructors are very similar.) How to do a perfect shuffle. Information is available online and specifically at this site: https://rosettacode.org/wiki/Perfect_shuffle This site also contains links showing how various languages can implement a perfect shuffle using an array. However, your requirements (see below) are to do it in an Object-Oriented way by writing a class that uses an ArrayList or Vector to hold the data. How to change an instance of a class (whose name is a reference to it in memory) by making a new one, changing the new one, and then assigning the original reference be the same as the new one. You will have to do this to the data when your code executes a perfect shuffle. Here is an example (which doesnt do anything useful): //Suppose you have an ArrayList of size 6 that is filled with ints like this. ArrayList myAL = new ArrayList(); for (int i=4; i<10; i++) myAL.add(i); 4 5 6 7 8 9 //make another ArrayList to make the changes in ArrayList temp = new ArrayList(): 4 5 6 7 8 9 //change temp somehow temp.add(88); temp.add(99); 4 5 6 7 8 9 88 99 myAL myAL myAL temp (no slots) myAL temp //then assign myALs reference to be the same as temp myAL = temp; 88 99 //now myAL has 88 and 99 in it Your program: You should write a class called EvenDeck. It will not accept Generics itself (so it will be defined as public class EvenDeck not public class EvenDeck ) It will have the following: Data: Its data will be an ArrayList (that way, it will hold ints) Parameterized constructor: will receive an integer n telling how big its ArrayList should be when it is filled. If n is negative or 0 or an odd number, the parameterized constructor should throw new IllegalArgumentException(your description here); But if the arguments were not illegal, the parameterized constructor will create the new ArrayList and then use a loop to add 1 through n to it. Default constructor: will create the new instance of ArrayList and fill it with the integers 1-8 (the same as the parameterized constructor would do if it received an 8). A toString() method will receive nothing and return what its ArrayList looks like as a String. So it just returns the ArrayLists toString(). A .equals method will receive an Object and return a boolean which will be whether this EvenDeck equals the one that is received. You should implement it like our previous .equals; when you get to the part where it does the actual comparison, you can tell the ArrayList to see if it is .equal to the one in the EvenDeck that was received. A perfectShuffle() method will do a single perfect shuffle by changing the values of the ArrayList (it can make a temporary ArrayList, put values into it, then reassign the variable name, as shown above). See the documentation on the website listed above. A numShuffles() method will make a copy of the original ArrayList (remember that ArrayList has a copy constructor) and then do perfect shuffles (call its own method) until the ArrayList is the same as the original copy is (remember that ArrayList has a .equals method). The numShuffles() method will also count how many perfectShuffles it took before it was back to the original state and return that number. Comments and formatting: Please put in an opening comment that briefly describes the purpose of your program. Each constructor/method should have a brief descriptive comment. Also, please be sure that your indenting is correct and that your variable names are meaningful. Submitting: Please submit your EvenDeck.java file on HyperGrade. myAL temp
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
