Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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) x 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 arh, where r is the cylinder's radius and h is the cylinder's height. 1 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 compare to 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 sorted, the most profitable ones will be in front. (b) (6 points) 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) (6 points) A RoundChocolate concrete subclass of Chocolate. RoundChocolate should add the following components to its superclass: Instance variable for radius (in min) A constructor that takes parameters for all instance variables including the inherited ones) and sets thern 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 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) x 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 arh, where r is the cylinder's radius and h is the cylinder's height. 1 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 compare to 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 sorted, the most profitable ones will be in front. (b) (6 points) 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) (6 points) A RoundChocolate concrete subclass of Chocolate. RoundChocolate should add the following components to its superclass: Instance variable for radius (in min) A constructor that takes parameters for all instance variables including the inherited ones) and sets thern 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

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago