Question: FOR JAVA CODES: Create a Java class called Food with the following: (10 points) 2 fields: name ( String ), and calories ( int )

FOR JAVA CODES:

Create a Java class called Food with the following: (10 points)

  • 2 fields: name (String), and calories (int)
  • A constructor that takes both fields as parameters
  • Override the toString method to display in a single line of text both the food name and calories

Create your own implementation of a Hash Table by creating class called HolidayHash. Another option is to do this assignment using BST, or a HashMap, but explains why you chose this other options instead in the comments. (10 points)

Create the following methods for the HolidayHash class. Use chaining to handle any table collisions for all 3 methods.

  • insert(Food) - will insert a Food object into the hash table (10 points)
  • search(Food) - will search for a Food object in the hash table, and return the bucket if found (10 points)
  • remove(Food) - will remove a Food object from the hash table (10 points)
  • display() - will display all items found in the hash table to the screen (10 points)

Create another class with your main method in it called HolidayDinner.

  • Create 10 Food items, all with different calories (between 1 and 1000) (5 points)

ex) Bagel: 200

Sandwich: 350

Cheeseburger: 500

ice cream: 800

Cake: 800

Cupcake: 800

....

  • Make 3 of these Food items have the same number of calories (5 points)
  • Create a hash table object to hold the 10 Food objects, and use the insert method to populate it with all the Food objects (10 points)
  • Call the remove method to remove any one of the 3 Food object from the hash table that have the same number of calories (10 points)
  • Call the search method to find any one of the 2 remaining Food objects that have the same number of calories (10 points)
  • Call the display method to print out all items in your hash table

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!