Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ITSC 1213 - Working with ArrayLists Part 2 Introduction The goal of this lab is to practice working with algorithms to search and sort

image text in transcribedimage text in transcribedimage text in transcribed

ITSC 1213 - Working with ArrayLists Part 2 Introduction The goal of this lab is to practice working with algorithms to search and sort an ArrayList of objects. Concepts covered in this lab: Using search algorithms to find a specific element in an ArrayList Using sort algorithms to rearrange elements in an ArrayList Required files or links This lab assumes you have successfully completed the Working with ArrayLists Part 1 lab. Consult with the instructional team if you need guidance This lab assumes you have successfully completed sections 7.5 and 7.6 in the CS Awesome textbook Part A: Implement a method that uses sequential search to find a specific order in a list of burger orders. 1. Open the NetBeans Project you called Fast Food kitchen created in the previous lab. 2. Open the Fast FoodKitchen class file and add the following method. The bullet points under the method signature tell you what the method must do. public int findorderSeq(int orderID) Using the value of the parameter orderID, find the position of this order in the list using sequential search algorithm (refer to section 7.5 if you need a refresher) Return the position of the order If an order does not exist in the list that matches order ID, return -1 3. Time to test your new method. Rather than using the main class we used in the previous lab let's create a new class with a main method and give it a unique name (e.g., Module3 Test). Now add the following code to the main method to test your new findOrderSeq method: public static void main(String[] args) { FastFoodKitchen Kitchen new FastfoodKitchen(); int orderPosition kitchen. findrderse (211 System.out.println("Using sequential search order position is + orderPosition; 4. Now, run your program to test the newly added method. Verify that the list of order is now sorted based on the order size not on how/when orders were added to the list. 5. When your program works and you are satisfied with the result, show your work to the instructional team and proceed to Part C. Part C: Implement a method that uses insertion sort to rearrange the elements in an array In this part we will add a method to our Fast FoodKitchen class that implements insertion sort to rearrange the orders in the list of burger orders based on the total number of burgers. 1. Add the following method. The bullet points under the method signature tell you what the method must do: public void insertionsort() Sorts orderList using insertion sort algorithm. The algorithm should perform the sorting based on the total number of burgers in each order, regardless of their type (e.g. if on order has 2 cheeseburgers and 1 veggieburger the total would be 3) 2. Switch over to the main method to test your new method. Comment the line from Part C that calls the selectionsort method and add a statement to call your new insertionsort method // Part C kitchen.insertionSort(); 3. Now, run your program and verify that the list of order is now sorted based on the order size not on how/when orders were added to the list. 4. When your program works and you are satisfied with the result, show your work to the instructional team and proceed to Part D. Part D: Implement a method that uses binary search to find a specific order in a list of burger orders. 1. Now that we can ensure we have a sorted list we can try another search algorithm that works only with sorted arrays/lists. 2. Let's add a new method to our Fast FoodKitchen class that performs a binary search on our order list. The bullet points under the method signature tell you what the method must do. public int findorderBin(int orderID) Using the value of the parameter orderID, find the position of this order in the list using binary search algorithm Return the position of the order If an order does not exist in the list that matches order ID, return -1 3. To test your new method. Switch over to the class you used in Part A to test the search method and add the following code to the main method to test your new findOrderBin method (if you comment any code make sure to keep the call one of the sort methods before you test your new method): // Part D orderPosition = kitchen. findOrderBin (2); System.out.println("Using binary search order position is " + orderPosition); 4. Now, run your program to test the newly added method. Remember to test your code with different values. If you encounter any issues use the debugger tool to inspect your code during execution. This is a great way to reinforce your learning and can help you fix any bugs you might encounter. 5. When your program works and you are satisfied with the result and JavaDoc, show your work to the instructional team to be checked off for this lab.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial Accounting

Authors: Karen W. Braun, Wendy M. Tietz

4th edition

978-0133428469, 013342846X, 133428370, 978-0133428377

More Books

Students also viewed these Programming questions