Question: How do I find the skeleton code and complete the task in java? Introduction A jagged array is an array of arrays of which the
How do I find the skeleton code and complete the task in java?




Introduction A jagged array is an array of arrays of which the member arrays can be of different lengths, producing rows of jagged edges when visualized as output. In contrast, two-dimensional arrays are always rectangular, so jagged arrays should not be confused with multidimensional arrays. A jagged array is useful when you have data in two dimensions that may not be fully matrixed. When 2D arrays become very large, entries with lots of 0s become very wasteful in terms of space. Representations There are two possible representations of jagged arrays. The default representation is the unpacked one. In this representation (shown on the left in the figure below), the array actually looks jagged. The unpackedValues member holds a bin of objects stored that array index. This example has seven bins holding six elements. Your Task Your task is to implement the JaggedArray class in JaggedArray.java. A skeleton is already given to you. Your implementation must use the member variables unpackedValues, packedValues and offsets. Your representation should use java.util.LinkedList. This is a Java class representing a linked list that you can use without having to write your own. These member variables are declared private, as they should be. However, the testing code uses public accessors to look at the values of your representation, so don't change those accessors. You have to implement these methods: - public JaggedArray(int bins) -- Create a jagged array with the given number of bins. - public int size() -- Return the number of elements stored in the jagged array - public int numberofBins() -- Return the number of bins in the jagged array - public int numberofslots(int bin) -- Return the number of slots stored in the given bin. This needs to work for both packed and unpacked representations. - public T getElement(int bin, int slot) -- Return the element stored at the given bin and slot number. Throw an IndexOutOfBoundsException if the bin or slot is invalid. This needs to work for both packed and unpacked representations. - public boolean addElement(int bin, T element) - Add the element to the given bin. Return true if successful, or false if the representation is packed. Throw an IndexOutOfBoundsException if the bin is invalid. - public boolean removeElement(int bin, int slot) - Remove the element from the given bin and slot. Return true if successful, or false if the representation is packed. Throw an IndexOutOfBoundsException if the bin or slot is invalid. - public boolean unpack() - Unpack the jagged array. Return true if successful, or false if the array is already unpacked. - public boolean pack( ) - Pack the jagged array. Return true if successful, or false if the array is already packed. Testing and Debugging The JaggedArray class has a member function called "print" that prints out the jagged array. It should help you in debugging your code. I suggest writing a main function and exercising your code with a few add and remove, pack and unpack operations, then printing out the array and seeing if it's what you expect. The test code is in the Test directory in TestJaggedArray.java. To test your code, type: make test Java Generics The JaggedArray class uses Java generics to hold elements of generic type T. In order to create a JaggedArray that holds characters, we invoke it with: JaggedArrayCharacterjagged=newJaggedArrayCharacter(10); This creates a jagged array with Character elements and ten bins. Java generics can be tricky to use. This link is useful to study when you're trying to create an array of LinkedLists in Java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
