Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

0.) Create a domain class called Dessert, with the following 2 attributes: private int calories; private String dessertName; Use Netbeans insert code feature to add

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

private int calories; private String dessertName;

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:

createArrayOfDesserts();

computeAndPrintStats();

printArrayOfDesserts(); 2.) In the createArrayOfDesserts() method, use the global static array of Desserts that should be defined at the beginning of the driver class:

Dessert[] myDesserts = new Dessert[10]; Read the attached file of desserts and their caloric value, where each record has the name of a dessert, and a total number of calories. Instantiate a Dessert object for each record, and then move each Dessert object into myDesserts 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 dessert with the highest amount of calories, and add all the calories in all the desserts in the file, so that after the loop the average calorie can be computed.

At the end of the loop, print out the values sum of calories, average calories, and highest calories, with a brief description before them. Also, print out the entire Dessert object with the highest calorie value. 3.) In the method called printArrayOfDesserts()create a loop to iterate through the global array of desserts, and print each Dessert object, indirectly using the Desserts 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

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions