Question: JAVA 0.) Create a domain class called Food, with the following 2 attributes: private String foodName; private int calories; Use Netbeans insert code feature to

JAVA

0.) Create a domain class called Food, with the following 2 attributes:

private String foodName;

private int calories;

Use Netbeans insert code feature to add the constructor, getters, setters, and toString methods.

1.) Create a driver class called FinalProgram that will have a main method that looks like this:

createArrayOfFoods();

computeAndPrintStats();

printArrayOfFoods();

2.) In the createArrayOfFoods() method, use the global static array of Foods that should be defined at the beginning of the driver class:

Food[] myFoods = new Food[15]; Read the attached file of foods and their caloric value, where each record has the name of a food, and a total number of calories. Instantiate a Food object for each record, and then move each Food object into myFoods array at the appropriate index location. Use the following code to define the file:

File aFile = new File("inputFile.txt"); Scanner myFile = new Scanner(aFile);

Remember to create a loop to read each record in the file using the .hasNext() condition, && the length of the array as part of the loop. Remember to define an index as an int variable, and initialize it to 0 before the loop. Within the loop, remember to increment the index.

2.) Next, in the computeAndPrintStats() method, write a loop (sequential search) to find the food with the lowest amount of calories, and add all the calories in all the foods in the file, so that after the loop the average calorie can be computed.

At the end of the loop, print out the values of sum of calories, average calories, and lowest calorie value. Also, print out the entire Food object with the lowest calorie value.

3.) In the method called printArrayOfFoods()create a loop to iterate through the global array of foods, and print each Food object, indirectly using the Foods toString() method.

4.) Make sure to document the functionality of the program by putting in comments at the beginning of the class, and before each method.

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!