Question
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
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) 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started