Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java please, any help is appreciated! I have found another code with this but it does not work for me. In that it won't

In Java please, any help is appreciated! I have found another code with this but it does not work for me. In that it won't compile. I have tried editing it but yeah, I appreciate any help. image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Here are ten examples that can be used for the file, that can be named choco.txt, and the comparable code below it

Examples:

SQUARE 60 7.70 61.35 44.58 4.96 ROUND 97 7.50 25.18 4.70 ROUND 60 6.43 16.21 4.31 ROUND 74 11.77 28.60 2.47 SQUARE 69 6.89 67.75 50.28 3.83 ROUND 64 10.94 25.43 3.35 ROUND 91 9.66 16.25 4.17 SQUARE 82 7.78 61.81 34.68 2.85 ROUND 66 7.13 23.57 3.10 SQUARE 66 10.73 74.92 43.06 4.88

Code;

public interface Comparable { int compareTo(Chocolate c); }

Selectionsort code it asks about which is what I have used but gives me an error.

public static void selectionSort(Comparable[] stuff) { for (int j = 0; j

stuff[minIndex] = stuff[j]; stuff[j] = min; } }

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 x 10-5) * f x V xc 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 round" 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 arah, where r is the cylinders radius and h is the cylinder's height. 0 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) (8 points) 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 accord- ingly Two abstract methods: - getVolume() Returns the volume of the chocolate, in cubic millimeters - getManufacturing Cost) 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. (The Comparable interface should be copied from our in-class code and included with your submission.) 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 unau array of chocolates is backwards, sorted, the most profitable ones will be in front. (b) (6 points) A SquareChocolate concrete subclass of Chocolate. Square Chocolate 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) (6 points) 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 Write a client program that reads the file of chocolates. For each line of the file, the program should instantiate a Square Chocolate or RoundChocolate object with the appropriate dimen- sions 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 Bye, hope the chocolate business survives

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

Step: 3

blur-text-image

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

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions