Question: Project 4 - Comparing Nutrition Note: When you turn in an assignment to be graded in this class, you are making the claim that you
Project Comparing Nutrition
Note: When you turn in an assignment to be graded in this class, you are making the claim that you neither gave nor received assistance on the work you turned in except of course, assistance from the instructor or teaching assistants
Virtuous Crisis Undertakings VCU is a disaster relief organization that collects and distributes supplies to areas affected by disaster. Food supplies in particular need to be well planned to meet a variety of nutritional needs. VCU would like a program that can help them determine the nutritional viability of rations provided by various companies. Write a program called NutritionComparison.java that will contain several methods.
Your program will have several parallel arrays in the main method which you will use in the program. The data in each array is related to the other arrays by its position in the array; thus, for example, the rations produced by ReadyWise have a protein content of grams per serving. Below are the arrays that you will need. These sample arrays are also in a text file in the assignment on Canvas. Please note that when we test your program, we will also be using different arrays. You can use these sample arrays in your main method.
String of Ration Companies:
ReadyWise
My Patriot Supply
Patriots
TWC
ERCC
Survival Frog
Be Prepared
Smithfield
Double array of protein gramsserving:
Double array of carbohydrates gramsserving:
Double array of fat gramsserving:
Your program will contain several methods:
The first method, calcAvg calculates the average from all the values in the double array passed into the method. This method is passed a double array and returns the average as double. The method header is:
public static double calcAvgdouble values
The second method, findHighValue searches the double array passed in to find the largest value from the array This method is passed a double array and returns the double largest value found in the array. The method header is:
public static double findHighValuedouble values
The third method, findLeastValue searches the double array passed in to find the smallest value from the array This method is passed a double array and returns the double smallest value found in the array. The method header is:
public static double findLeastValuedouble values
The fourth method, findHighestTwo is passed a String array of ration companies and a double array of values. It will search through the double array to find the two largest values in the double array. It will return a String array that contains the ration company associated with the largest two double values in the double array, with the ration company with the highest value listed first. The method header is:
public static String findHighestTwoString names, double values
The fifth method, findLeastTwo is passed a String array of ration companies and a double array of values. It will search through the double array to find the two smallest values in the double array. It will return a String array that contains the ration company associated with the smallest two double values in the double array, with the company with the smallest value listed first. The method header is:
public static String findLeastTwoString names, double values
The sixth method, findCompany will verify if a given String is a valid company within the String array of ration companies. This method is passed the String array of ration companies and the ration company being searched for. The method returns a boolean value of true or false based on whether the ration company was found within the ration company array. If the ration company is in the array, the method will return a value of true, and, if the ration company is not in the array, the method will return false. Note, the ration company name must match exactly for the method to return true. The method header is:
public static boolean findCompanyString names, String company
The main method will contain the arrays needed for the program use the sample arrays above This method will also do the following:
Call the calcAvg method, passing it the double array of protein values and print out the results.
Call the calcAvg method, passing it the double array of carbohydrate values and print out the results.
Call the findHighValue method, passing it the double array of protein values and print the results.
Call the findLeastValue method, passing it the double array of fat values and print the results.
Call the findHighestTwo method, passing it the String array of ration company names and the double array of protein and print the results. Note: You will need to use an foreach loop to print out the values from the
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
