Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming Project 7 - Ice Cream Analysis 2 Note: When you turn in an assignment to be graded in this class you are making
Programming Project 7 - Ice Cream Analysis 2 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). Program Name: IceCreamAnalysis2.java Scoops Ahoy wants a program to analyze their ice cream flavors. Write a program called IceCreamAnalysis2.java that will reexamine a text file of the ice cream data that we looked at in Project 4. You will write a program that will accept at the command line two filenames: one is a text file containing the ice cream data and the other is an output filename. If these files are not provided by the user at the command line, then the program will ask the user for them. The data in the first text file consists of information about the ice cream flavors that the Scoops Ahoy is analyzing. The file contains many lines of data, one for each ice cream flavor. Each line of data contains information about the ice cream flavor: The ice cream flavor's name, a String The ice cream flavor's favorability, a double The ice cream flavor's calories per serving, a double The ice cream flavor's production cost per gallon, a double A sample text file is below: Vanilla Chocolate Mint Chocolate Chip Cookies N' Cream Strawberry Cookie Dough Salted Caramel Moose Tracks 0.78 0.62 0.59 0.33 0.45 0.67 0.72 0.49 137.6 143.5 151.3 162.8 126.6 168.4 139.1 158.2 1.98 2.14 2.23 2.17 2.09 2.12 2.07 2.34 Before implementing IceCreamAnalysis2.java, we will create an object to encapsulate the data values associated with an ice cream. Here are the specifications for the IceCream.java class: You will have 4 instance variables: name: String, favorability: double, calories: double, production Cost: double You will have a default constructor that sets all string values to an empty string and numeric values to 0.0. You will have a parameterized constructor that passes in a name, favorability, calories, and production Cost to set to the instance variables You will have getters and setters for each instance variable You will have a toString() method that will return the name, favorability, calories, and production Cost separated by a space. Each double value will be rounded to one decimal place using String.format(). name: String favorability: double calories: double - production Cost: double + IceCream() + IceCream(name: String, favorability: double, calories: double, productionCost: double) + setName(name: String): void Ice Cream + setFavorability(favorability: double): void + setCalories(calories: double): void + setProduction Cost(production Cost: double): void + getName(): name: String + getFavorability(): favorability: double + getCalories(): calories: double + getProductionCost(): production Cost: double + toString(): String IceCreamAnalysis2.java will contain several methods. The first method is readData(), which takes in a File object and will loop to read the data from the file, line by line. Each line will contain data for an IceCream object as shown above. The lines of data read will be stored in an ArrayList of Strings. Here is the method header: public static ArrayList readData(File inputFile) throws FileNotFoundException } //Your code here The second method is buildObjects(), which will parse the data from each element of the ArrayList into an ArrayList containing IceCream objects. Within each row of string data, the data is separated by tabs. You can use the String.split("\t") method to split the data and temporarily store it in a String array. Once the data is in this new String array, you can use this data to create a new IceCream object. The first element is the name, the second is the favorability, the third is the calories, and the fourth is the production Cost. You will need to use the Double parseDouble() method to convert your String input into the double value you need for the three double values for each of the numeric data attributes for the IceCream objects. You will want to make sure that your numeric data actually is numeric for each of the double values in the data. You will handle this possible conversion error by catching the exception that is thrown, the NumberFormatException. If the file has incorrect data or negative values for any of the numeric inputs, you will simply just place a 0.0 into the numeric instance variable instead of the incorrect value. However, you will keep all the good data for each IceCream object, so only place 0.0 into the attributes that have bad data. Here is the method header: public static ArrayList } The third method is the calcAvg() method which calculates the average for the given numeric attribute of the given IceCream objects. This method will return the mean/average of the IceCream objects' given attribute as a double variable. The possible String attribute values are: "favorability", "calories", and "production Cost". Here is the method header: } //Your code here public static double calcAvg (ArrayList iceCreamFlavors, String attribute) { //Your code here buildobjects (ArrayList lines) { The fourth method is the calcLargestValue() method which calculates the highest value for any of the numeric attributes within the IceCream objects. This method will return the highest of the IceCream objects' given attribute as a double variable. The possible String attribute values are: "favorability", "calories", and "production Cost". Here is the method header: } public static double calcLargestValue (ArrayList iceCreamFlavors, String attribute) { //Your code here The fifth method is the findAvglceCreamFlavor() method which finds the ice cream flavor whose value for the given attribute within the IceCream objects is closest to the avg value of the data for that given attribute. This method will return the IceCream object which's value of the IceCream objects' given attribute is closest to the average. The method will pass in the ArrayList of Ice Cream objects, the String attribute value ("favorability", "calories", or "production Cost") that is being searched, and the average value that is being searched. Here is the method header: } public static IceCream findAvgIceCreamFlavor (ArrayList iceCreamFlavors, String attribute, double avgValue) { //Your code here The sixth method is the findHighestIceCreamFlavors() method which finds the ice cream flavors above the value passed in for the given attribute. It will take in an ArrayList, a value, and an attribute. It will return an ArrayList containing the IceCream objects that are higher than or equal to the value passed in for a given attribute. The possible String attribute values are: "favorability", "calories", and "production Cost". Here is the method header: public static ArrayList findHighestIceCreamFlavors (ArrayList iceCreamFlavors, double value, String attribute) { //Your code here } The next three methods are the display() methods. There are three display methods, one for each type of data you need to write to a file. They will all take in a String of text to describe the output and a PrintWriter object to print to. Each output will be on a new line, and each output will be separated by a blank line. To print an ArrayList of values: public static void display (String output Message, } ArrayList iceCreamFlavors, PrintWriter out) throws FileNotFoundException { //Your code here To print one IceCream object: public static void display (String outputMessage, Ice Cream iceCreamFlavor, PrintWriter out) throws FileNotFoundException { //Your code here Note: You will call the IceCream toString() for both methods above. To print a double value: public static void display (String outputMessage, double value, PrintWriter out) throws FileNotFoundException { //Your code here Note: You will need to round the double output to one decimal place when you output it. The tenth and final method is a main method. This main method will first read in the two command line arguments and use them to create File objects. The first command line argument is the input file, the second is the output file. The main method will then call the method readData(). You will wrap the call to the readData() method in a try catch block, so that if there is a problem with the opening of the text file, you will catch it in main. If there is a problem, you will print to the console "Incorrect input filename". If there is not a problem, then you will print to the console "Input file correct". The main method will then pass the ArrayList of Strings returned from readData() to the buildObjects() method. The return value of buildObjects() can then be used as an argument when calling the calcAvg(), calcLargestValue(), findAvgIceCreamFlavor(), and find HighesticeCreamFlavors() methods. The main method will then write the values for each output produced in the program to the given outputFile parameter by calling a display method. You will wrap the call to this method in a try catch block, so that if there is a problem with the writing to the text file, you will catch it in the main method. If there is a problem, you will print to the console "Incorrect output filename. If there is not a problem, then you will print to the console "Output file corrrect". Regardless, you *must* close the PrintWriter file when you are done so that the file successfully written to. Sample output for the IceCreamGoodData.txt file is: At the console line: Incorrect input filename or Input file correct Incorrect output filename or Output file correct To the output file from IceCreamGoodData.txt: The average favorability is: 0.6 The highest calories value is: 168.4 The ice cream flavor closest to the average is: Chocolate Chip 0.6 151.3 2.2 The flavors above the average value for favorability are: Vanilla 0.8 137.6 2.0 Chocolate Mint 0.6 143.5 2.1 Chocolate Chip 0.6 151.3 2.2 Cookie Dough 0.7 168.4 2.1 Salted Caramel 0.7 139.1 2.1 (This output is using the Strings shown above as the String input to the display() method along with the return value from each method call for the methods listed for this project in the order they are listed above, starting with the method calcAvg(). The value passed into the find HighestIceCreamFlavors() was the average favorability.) Sample output for the IceCreamBad Data.txt file is: To the output file from IceCreamBadData.txt: The average favorability is: 0.5 The highest calories value is: 168.4 The ice cream flavor closest to the average is: Strawberry 0.5 0.0 2.1 The flavors above the average value for favorability are: Vanilla 0.8 137.6 2.0 Chocolate Mint 0.6 0.0 2.1 Chocolate Chip 0.6 151.3 2.2 Cookie Dough 0.7 168.4 2.1 Salted Caramel 0.7 139.1 0.0 (This output is using the Strings shown above as the String input to the display() method along with the return value from the method calls for the methods listed for this project in the order they are listed above, starting with the method calcAvg(). The value passed into the find HighestIce Cream Flavors() was the average favorability.) Before beginning this project, you will document your algorithm as a list of steps to take you from your inputs to your outputs. This algorithm will be due one week before the project is due. This will be graded and returned to you. It will be your responsibility to understand and correct any errors you might have with your algorithm. Each step will be added as a comment block within your IceCreamAnalysis2.java code. You will have the comment block right above the code that performs the actions specified. For example, before your lines of code that ask the user for inputs, you would have a comment block that states what inputs you are requesting from the user. You will document the IceCream.java file using Javadoc comments as we did in Project 6. This and all program files in this course must include a comment block at the beginning (top) of the source code file that contains: * The comment block for the header as well as all the comment blocks should look like this: 1* * Java program name * the Java program name project description your name the date created the course number and section * Project description Your name * The date created * The course number and section */ You will test your code using the provided JUnit tests. You should use these tests within IntelliJ to make sure that your code is running correctly. You will take a screenshot of your code passing all JUnit tests. Make sure that the screenshot has your header comment block in it so that we know it is your code running. Once it is, then you will submit your code to Gradescope. You will only have 4 submissions to Gradescope, so please make sure your code is running correctly in IntelliJ before submitting to Gradescope. You will also take a screenshot of your IceCreamAnalysis2.java code running within IntelliJ showing the output from running the methods requested above. You will submit your Java source code files (IceCreamAnalysis2.java and IceCream.java) to Gradescope. You will upload your three screenshots, two showing the JUnit tests passing and one of the IceCreamAnalysis.java code running, by uploading the files to the Assignment link in Canvas. Please do not submit your files in a zipped folder. Ask questions about any part of the programming project that is not clear!
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