Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Scoops Ahoy wants a program to analyze their ice cream flavors. Write a program called IceCreamAnalysis.java that will contain several methods. Your program will
Scoops Ahoy wants a program to analyze their ice cream flavors. Write a program called IceCreamAnalysis.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 ice cream flavor Vanilla has a favorability of 0.78, which means that 78 out of 100 Scoops Ahoy's customers like Vanilla. Below are the arrays that you will need. I also attached them in a text file. Please note that these are sample arrays. When we test your program, we will be using different arrays. String array of ice cream flavors: Vanilla Chocolate Mint Cookies Strawberry Cookie Chocolate N' Cream Dough Chip Double array of favorability: 0.78 0.62 0.59 0.33 Double array of calories per serving: 137.6 143.5 151.3 2.23 162.8 Double array of production cost per gallon: 1.98 2.14 2.17 Your program will contain several methods: 0.45 126.6 2.09 0.67 168.4 2.12 Salted Caramel 0.72 139.1 2.07 Moose Tracks 0.49 158.2 2.34 Double array of production cost per gallon: 1.98 2.14 2.17 2.23 2.09 2.12 2.07 2.34 Your program will contain several methods: The first method, calcMean(), calculates the average of all the values in the double array passed into the method. This method passes in a double array and returns the average as double. The method header is: public static double calcMean (double [] values) The second method, findGreatest(), searches the double array passed in to find the greatest value from the array This method passes in a double array and returns the greatest double value found in the array. The method header is: public static double findGreatest (double [] values) The third method, findSmallest(), searches the double array passed in to find the smallest value from the array This method passes in a double array and returns the smallest double value found in the array. The method header is: public static double findSmallest (double[] values) The fourth method, findBestValue(), passes in a String array of ice cream flavors, a double array of favorability and a double array of cost per gallon. It will walk through the double arrays to compute a value rating. This will need to be stored in a new array. The calculation for the value rating is: favorability * (5 cost per gallon). It will then search through the value ratings to find the ice cream flavor with the highest value rating. It will return a String that contains the ice cream flavor associated with the highest value rating in the new array. The method header is: public static String findBestValue (String [] flavors, double [] favorability, double [] cost) The fifth method, findSmallestTwo(), passes in a String array of ice cream flavors 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 ice cream flavors associated with the smallest two double values in the double array, with the flavor with the smallest value listed first. The method header is: public static String[] findSmallestTwo (String[] flavors, double [] values) The sixth method, findFlavor(), will verify if a given String is a valid ice cream flavor within the String array of ice cream flavors. This method passes in the String array of ice cream flavors and the flavor being searched for. The method returns a boolean value of true or false based on whether the flavor was found within the ice cream flavors array. If the ice cream flavor is in the array, the method will return a value of true, and, if the ice cream flavor is not in the array, the method will return false. Note, the ice cream flavors must match exactly for the method to return true. The method header is: The main method will contain the arrays needed for the program. This method will also do the following: public static boolean findFlavor (String[] flavors, String flavor) Call the calcMean() method, passing it the double array of calories per serving and print out the results. Call the calcMean() method, passing it the double array of cost per gallon and print out the results. Call the findGreatest() method, passing it the double array of favorability and print the results do the following: Call the calcMean() method, passing it the double array of calories per serving and print out the results. Call the calcMean() method, passing it the double array of cost per gallon and print out the results. Call the findGreatest() method, passing it the double array of favorability and print the results. Call the findSmallest() method, passing it the double array of cost per gallon and print the results. Call the findBestValue() method, passing it the String array of ice cream flavors, the double array of favorability and the double array of cost per gallon and print the results. Call the findSmallestTwo () method, passing it the String array of ice cream flavors and the double array of calories and print the results. (Note: You will need to use an enhanced for loop to print out the values from the array.) Ask the user for an ice cream flavor. Call the findFlavor(), passing it the String array of ice cream flavors and the given flavor and print the results. All outputs should be rounded to three decimal spaces using printf().
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