Question: Modify the OrderedList Class: 1. Define a default constructor and a parameterized constructor. Recall that OrderedList is a subclass of ArrayListClass. 2. Provide stubs (see
Modify the OrderedList Class: 1. Define a default constructor and a parameterized constructor. Recall that OrderedList is a subclass of ArrayListClass. 2. Provide stubs (see below) for the abstract methods, insert, search, and remove. This will allow you to compile the class and to develop and test each one individually. public void insert(T insertItem) { } public int search(T searchItem) { return 0; //a return statement is required in order for this to compile } public T remove(T removeItem) { return null; //a return statement is required in order for this to compile } Lab 7 CSC130 The OrderedList Class Page 2 of 3 Modify Lab7App: 3. Define the main method. 4. Create an OrderedList, list1, using the default constructor. Call the toString method to display the contents of the list. 5. Create a second list, list2, using the default constructor. Call the toString method to display the contents of the list. Modify the OrderedList Class: 6. Provide the necessary code for the insert method. Modify Lab7App: 7. In order to test the insert method you will need to create references to Product objects and instantiate them using the parameterized constructor. The data below should be stored in these Product objects. Call the getData method which returns a Product array with the data. 456u78 10 5.0 355d98 7 25.0 243j58 3 10.0 264j45 15 13.50 653o09 9 16.75 8. Insert each of these into list2. You should try inserting one at a time and displaying the resulting list to determine if the insert method is working. If not, make the necessary corrections and test it again until it works as expected. Modify the OrderedList Class: 9. Provide the necessary code for the search method. Modify Lab7App: 10. Write the statement(s) necessary to locate the position of the product whose id is 264j45 (an item found in the middle of the list). If it is found, display the product id and its location; otherwise display a message stating that the item was not found. 11. Write the statement(s) necessary to locate the position of the product whose id is 344d97 (an item that is not in the list). If it is found, display the product id and its location; otherwise display a message stating that the item was not found. 12. You should test your search method with other product ids. Include additional code to search for an item: o that is found in the beginning of the list o that is found at the end of the list o in an empty list (use list1) be sure to display an appropriate message indicating whether or not the product was found. Lab 7 CSC130 The OrderedList Class Page 3 of 3 Modify the OrderedList Class: 13. Provide the necessary code for the remove method. Modify Lab7App: 14. Write the statement(s) necessary to remove the product whose id is 355d98 (an item in the middle of the list). Display the items in the list to ensure it has been deleted. 15. Write the statement(s) necessary to remove the product whose id is 344d97 (an item that is not in the list). Display the items in the list to ensure that the list has not changed. 16. You should test your remove method with other product ids. Include additional code to remove: o an item that is found in the beginning of the list o an item that is found at the end of the list o the last item in the list o an item from an empty list (use list1) o a null value (the list should not contain any null values) be sure to display the list after attempting to remove each of these to ensure that your method is working correctly. 17. Comment out the equals method in the Product class and rebuild it. Run your program again. Do you get an error message? Why or why not? How does your output change (if at all)? You should include your answers to these questions in a comment at the bottom of the main method. 18. Remove the comments from the equal method. Run your program again to ensure that you havent introduced any errors.
//how to make an insert method to compare the product id's to one another ( the product id is a string "456j56") within an ordered list? please comment insert method below
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
