We have studied how an ArrayList is implemented by creating an underlying array (e.g., []) and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
We have studied how an ArrayList<E> is implemented by creating an underlying array (e.g., []) and storing the data in that array. The set, get, add, remove, etc. methods were implemented by manipulating the data in the underlying array. Note that the ArrayList<E> is a generic class. The type of data stored in the array can be any kind of Object. The type-parameter E is a placeholder for the actual type of data placed in the data structure (e.g., String, or Car, or Student). For this assignment, you must complete the given LucasArrayList<E> class so that it implements the ListIterator<E> interface that is defined in the java.util package in the Java lilbraries. You will need to complete the code of the given CurrentPosition class that is inside the LucasArrayList<E> class. The purpose of this class is to be a kind of "bookmark" into the list. This "bookmark" object will need to remember where it currently is located inside the list, and to update that information appropriately every time the user moves the bookmark to the right (the .next() method) or to the left (the previous() method) in the list. You will need to define several instance fields for the CurrentPosition class, and to develop all the methods specified in the ListIterator<E> interface. The "shell" or "stub" of the CurrentPosition class is provided to you, as shown below: private class CurrentPosition implements ListIterator<E> ( } // you must write all of the code to implement this class This code will show a compiler error, since this class must contain all the methods specified in the ListIterator, and the given code does not. To fix this error you can hover your mouse over CurrentPosition and select "Add unimplemented methods" to have a stub of each of the required methods inserted. This is one example of how we like using a powerful IDE, instead of having to type everything ourself. You must implement the code for each method in CurrentPosition directly yourself, without using inheritance to "reach in" and use code already available in the Java libraries. The code is fairly simple, but you do need to do a couple of things. You can consult the Java API to see the functionality of a ListIterator<E>. You should be sure to do appropriate error-checking in your CurrentPosition. For example, the next() method should throw a NoSuchElementException if the user attempts to move past the right end of the list. Also, the ListIterator must have moved either left or right at least once before altering an element in the List using set(). Therefore the set() method should throw an IllegalStateException if this is not the case. Similarly for the remove() method. You are given the Prog02_Tester class. If you have completed the methods in the CurrentPosition class correctly, then the main method in Prog02_Tester should execute without any errors. Your code must work for the given Tester. You can add extra code to the Tester, if you wish, to do more through error checking, but you must not alter the given Tester code in any way. To submit your work, upload a zipfile containing your LucasArrayList.java file to the Program 2 Assignment drop box in UNM Learn. Yes, you only need to submit one file, but you must still "zip up" that file and submit the zipfile. You should be sure to include YOUR NAME in a comment at the top of your source code file. Your source code must use proper style, i.e., variables should be well named (name is not too short, not too long, and is meaningful), and bodies of loops, if's, etc. should be properly indented. We have studied how an ArrayList<E> is implemented by creating an underlying array (e.g., []) and storing the data in that array. The set, get, add, remove, etc. methods were implemented by manipulating the data in the underlying array. Note that the ArrayList<E> is a generic class. The type of data stored in the array can be any kind of Object. The type-parameter E is a placeholder for the actual type of data placed in the data structure (e.g., String, or Car, or Student). For this assignment, you must complete the given LucasArrayList<E> class so that it implements the ListIterator<E> interface that is defined in the java.util package in the Java lilbraries. You will need to complete the code of the given CurrentPosition class that is inside the LucasArrayList<E> class. The purpose of this class is to be a kind of "bookmark" into the list. This "bookmark" object will need to remember where it currently is located inside the list, and to update that information appropriately every time the user moves the bookmark to the right (the .next() method) or to the left (the previous() method) in the list. You will need to define several instance fields for the CurrentPosition class, and to develop all the methods specified in the ListIterator<E> interface. The "shell" or "stub" of the CurrentPosition class is provided to you, as shown below: private class CurrentPosition implements ListIterator<E> ( } // you must write all of the code to implement this class This code will show a compiler error, since this class must contain all the methods specified in the ListIterator, and the given code does not. To fix this error you can hover your mouse over CurrentPosition and select "Add unimplemented methods" to have a stub of each of the required methods inserted. This is one example of how we like using a powerful IDE, instead of having to type everything ourself. You must implement the code for each method in CurrentPosition directly yourself, without using inheritance to "reach in" and use code already available in the Java libraries. The code is fairly simple, but you do need to do a couple of things. You can consult the Java API to see the functionality of a ListIterator<E>. You should be sure to do appropriate error-checking in your CurrentPosition. For example, the next() method should throw a NoSuchElementException if the user attempts to move past the right end of the list. Also, the ListIterator must have moved either left or right at least once before altering an element in the List using set(). Therefore the set() method should throw an IllegalStateException if this is not the case. Similarly for the remove() method. You are given the Prog02_Tester class. If you have completed the methods in the CurrentPosition class correctly, then the main method in Prog02_Tester should execute without any errors. Your code must work for the given Tester. You can add extra code to the Tester, if you wish, to do more through error checking, but you must not alter the given Tester code in any way. To submit your work, upload a zipfile containing your LucasArrayList.java file to the Program 2 Assignment drop box in UNM Learn. Yes, you only need to submit one file, but you must still "zip up" that file and submit the zipfile. You should be sure to include YOUR NAME in a comment at the top of your source code file. Your source code must use proper style, i.e., variables should be well named (name is not too short, not too long, and is meaningful), and bodies of loops, if's, etc. should be properly indented.
Expert Answer:
Answer rating: 100% (QA)
It seems like you need to implement a CurrentPosition class that implements the ListIterator interfa... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
A rectangular parking lot with a perimeter of 440 feet is to have an area of at least 8000 square feet. Within what bounds must the length of the rectangle lie?
-
Explain the three types of social entrepreneurship and give examples of each type. When does each type of social entrepreneurship create lasting social value?
-
The following transactions for Juan More Taco Inc. (JMT) occurred in the month of May. Prepare journal entries for each transaction. May Owners invest $12,000 cash in exchange for common shares of...
-
An elevator operated by an electric motor rises at a constant speed. What is the work done on the elevator as it rises a distance \(b\) ?
-
Now, assume that you work in the internal audit function at a company that is considering a software package to help automate the process of complying with the requirements of the Sarbanes-Oxley Act...
-
Design test cases to achieve loop coverage on the function "computeTax" (list the loops covered by each test case). If it is not feasible, explain the reason. Try your best to use the minimum number...
-
Your company's balance sheet has the followinYour company's balance sheet has the following items (not listed in the correct order): Item Amount Accounts receivable 1,312 Short-term debt 100 Cash 83...
-
Does financial literacy play a role in retirement planning? What do current levels of financial literacy look like and what characteristics increase the probability of being more financially...
-
If we replaced the proton with an electron (mass me=5.4410-4mp) while leaving the rest of the experiment the same (i.e., same initial velocity, same magnetic fields, same starting point, etc.), how...
-
Joice, a 70 year old widowed retiree wants to apply for a Centrelink payment. Over the past 12 months, she has gifted $80,000 of her savings to her grandchildren. She has an investment apartment,...
-
Two objects, one with no kinetic energy and the other with 180 J of kinetic energy, collide. After the collision, the first object has a velocity of 12.0 m/s [E]. What other information would you...
-
Mr Jones, married, 66 Children: Son Daughter spouse's NIFTP (earned) $ spouse's age 30,000 63 2021 Gross salary $ 59,000 CPP contributions $ 3,025 El premiums $ 1,079 Employee RPP contributions $...
-
A car travelling west at 60.0 km/h decelerates at 6.50 m/s. The car's tires have a radius of 0.310 m. Question 1 (a) What is the magnitude of the tires' angular acceleration?
-
Calculate the energies in MeV of each fusion product for the following reactions (a) D+T>4He + n + 17.6MEV { 3 He + n + 3.27MEV (50%) T +p+ 4.03MeV (50%) (b) D+D (c) D+3He>4He + p + 18.3MEV
-
D Which of the following is considered part of the Controlling activity of managerial accounting? O Choosing to purchase raw materials from one supplier versus another O Choosing the allocation base...
-
A six-year-old computer numerical control (CNC) machine that originally cost $8,000 has been fully depreciated, and its current market value is $1,500. If the machine is kept in service for the next...
-
If you borrowed $20,000 for 60 months at 18% with an add-on loan, what would be your monthly payment and the total amount you paid on interest?
-
Jennifer Ozman is a sales engineer at Montana Chemical Engineering Company. Jennifer owns two vehicles, and one of them is entirely dedicated to business use. Her business car is a used, small pickup...
-
Test for heteroskedasticity using a Goldfeld-Quandt test applied to (a) two subsamples with potentially different variances and (b) a model where the variance is hypothesized to depend on an...
-
Compute generalized least squares estimates for heteroskedastic models where (a) the variance is known except for the proportionality constant \(\sigma^{2}\), (b) the variance is a function of...
-
Describe how to transform a model to eliminate heteroskedasticity.
Study smarter with the SolutionInn App