Question: FOR JAVA CODES: Download the attached files Turkey and Thanksgiving.java. Then make the following updates to Thanksgiving.java (see comments in code for code placement) Add

FOR JAVA CODES:

Download the attached files Turkey and Thanksgiving.java. Then make the following updates to Thanksgiving.java (see comments in code for code placement)

Add a sorting method to sort th ArrayList of Turkey objects by weight (lowest to highest), using any one of these sorting algorithms: Selection sort, Insertion sort, Quick sort, or Mergesort. Also in the comments above the method, describe why you chose this sorting algorithm over the others. [20 points]

Add a binary search method to search an ArrayList of Turkey objects, and return the index of the Turkey by a specified weight [20 points]

Add a recursive method called eatTurkey(Turkey t) that will recursively eat a turkey, by subtracting 1 lb of turkey for each recursive call. Use 0 lbs as the base case and print out "Done" if the turkey weight is 0. For each recursive case, print out "Gobble Gobble, there are N lbs. or turkey remaining" [30 points]

In the main method, you will make the following method calls

Call your sorting method to sort the ArrayList of Turkey objects [10 points]

Call the binary search method to find a Turkey that weighs 32 lbs, and get the index of that Turkey [10 points]

Call the recursive method by passing the Turkey object at the specified index found by the binary search method [10 points]

Write good comments throughout your program, and also your name at the top of both Java files.

--------------------------------------------------------------------------------------------------------------------------------------------

public class Turkey { private String type; private int weight; //weight rounded up, in lbs. public Turkey(String type, int weight) { super(); this.type = type; this.weight = weight; } /** * @return the type */ public String getType() { return type; } /** * @param type the type to set */ public void setType(String type) { this.type = type; } /** * @return the weight */ public int getWeight() { return weight; } /** * @param weight the weight to set */ public void setWeight(int weight) { this.weight = weight; } } 

------------------------------------------------------------------------------------------------------------------------------------

import java.util.ArrayList; public class Thanksgiving { public static void main(String[] args) { ArrayList turkeys = new ArrayList(); turkeys.add(new Turkey("Butterball", 20)); turkeys.add(new Turkey("Jenni-O", 12)); turkeys.add(new Turkey("Foster Farms", 24)); turkeys.add(new Turkey("Honeysuckle", 17)); turkeys.add(new Turkey("Trader Joes", 32)); turkeys.add(new Turkey("Norbest", 10)); turkeys.add(new Turkey("Vons O Organics", 38)); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!