Question
Suppose you own a gourmet dark chocolate company. Years of painstaking research from your business analysts has determined that the cost (in dollars) to manufacture
Suppose you own a gourmet dark chocolate company. Years of painstaking research from your business analysts has determined that the cost (in dollars) to manufacture one piece of chocolate is (1 * 10-5) * f * V * c where f is an empirically determined cost factor, V is the chocolate's volume (in cubic millimeters), and c is its cacao percentage expressed to the nearest integer (e.g., 85 for an 85% cacao product). The company manufactures two types of products: \square" chocolate and ound" chocolate. Square chocolate has a cost factor of 0.42. The shape of square chocolate can be approximated as a rectangular prism, so the volume is computed as the product of its length, width, and height. Round chocolate has a cost factor of 0.77. The shape of round chocolate can be approximated as a cylinder, so the volume is computed as r2h, where r is the cylinder's radius and h is the cylinder's height. Note that the cost to manufacture a piece of chocolate isn't always directly related to the product's retail price { i.e., the price at which you sell it to customers. The retail price is determined by other factors that we won't consider here. 1. Write the following classes: (a) An abstract class Chocolate that represents one piece of chocolate. This class should contain the following: Instance variables for cacao content, height (in mm), and retail price (in dollars) A constructor that takes parameters for each instance variable and sets them accordingly Two abstract methods: - getVolume() Returns the volume of the chocolate, in cubic millimeters -getManufacturingCost() Returns the cost to manufacture the chocolate, in dollars A non-abstract method getProfit(), which returns the chocolate's profit. The profit is the difference between the retail price and the manufacturing cost. Note that it's possible for this number to be zero or negative. Chocolate should implement the Comparable interface that we wrote in lecture, by defining the compareTo method. Chocolate should be compared by profit, with more profitable chocolates being considered \less than" less profitable chocolates. This seems backwards, but it's so that when an array of chocolates is sorted, the most profitable ones will be in front. (b) A SquareChocolate concrete subclass of Chocolate. SquareChocolate should add the following components to its superclass: Instance variables for length and width (both in mm) A constructor that takes parameters for all instance variables (including the inherited ones) and sets them accordingly. Call super as needed. Implement all abstract methods A toString method that returns a string containing the type of chocolate (square), cacao content, dimensions, manufacturing cost, retail price, and profit (c)A RoundChocolate concrete subclass of Chocolate. RoundChocolate should add the following components to its superclass: Instance variable for radius (in mm) A constructor that takes parameters for all instance variables (including the inherited ones) and sets them accordingly. Call super as needed. Implement all abstract methods A toString method that returns a string containing the type of chocolate (round), cacao content, dimensions, manufacturing cost, retail price, and profit d. Write a client program that reads the file of chocolates. For each line of the file, the program should instantiate a SquareChocolate or RoundChocolate object with the appropriate dimensions and store it into an array of Chocolate objects. The program should then sort this array from greatest to least profit; use the sort method for Comparable objects that we discussed in lecture. (You can copy and paste the sort method we wrote into the same file as your main method.) Note that there should be one array containing all of the chocolates, not two arrays with the square chocolates and round chocolates separately. Once your program has read the file, get user input for a minimum profit amount. The program should then show all the chocolates from the file that have a profit of at least that amount, sorted by profit in descending order. You should be seeing the return values of toString for each chocolate in the array that meets the criteria. Allow the user to repeat this process as many times as needed until they enter X (case-insensitive) to exit. The program should show an appropriate error message if the user tries to enter something besides a minimum profit or an X. The program should work for an input file of any length, as long as it's in the same format as the one your monkey army provided. Test this out by making a few different input files of varying lengths!
Example program run (underlined parts indicate what the user enters) Enter minimum profit (in dollars) per chocolate, X to exit: 10.80 Round (76%) 11.71 x 2.08 cost $ 0.52, retail $11.77, profit $11.25 Round (74%) 11.63 x 3.33 cost $ 0.81, retail $11.94, profit $11.13 Round (63%) 10.23 x 3.02 cost $ 0.48, retail $11.50, profit $11.02 Round (67%) 10.41 x 2.35 cost $ 0.41, retail $11.42, profit $11.01 Round (80%) 12.71 x 2.44 cost $ 0.76, retail $11.76, profit $11.00 Square (75%) 51.72 x 20.19 x 2.70 cost $ 0.89, retail $11.84, profit $10.95 Square (75%) 40.08 x 25.51 x 3.09 cost $ 1.00, retail $11.86, profit $10.86 Square (66%) 48.12 x 20.24 x 3.97 cost $ 1.07, retail $11.89, profit $10.82 Enter minimum profit (in dollars) per chocolate, X to exit: all of it That's not a number! Enter minimum profit (in dollars) per chocolate, X to exit: x
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