Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that you have a class IceCreamMachine which describes a machine that can make ice cream. The machine needs cream and sugar to make ice

Assume that you have a class IceCreamMachine which describes a machine that can make ice cream. The machine needs cream and sugar to make ice cream. The class has private variables to tell how much cream, sugar and ice cream the machine contains. There are also private variables to tell the amount of cream and sugar needed to make one liter ice cream. The class

has a constructor IceCreamMachine(double creamComsumption, double sugarComsumption) the parameters tell the amount of cream and sugar used to make one liter ice cream. The class also has the following methods

addMaterial(double cream, double sugar) adds cream and sugar to the machine. The amounts added are given as parameters.

howMuch() calculates how much ice cream the machine can make before it runs out of either cream or sugar. The calculated amount is returned.

make(double amount) makes ice cream. The amount to be made is given as a parameter. If there are not enough cream and sugar for this amount, the machine makes as much ice cream as it can. The method returns the amount of ice cream made (in liters). The method decreases the amount of cream and sugar in the machine.

pack() packs the ice cream in the machine to one liter packages. The method returns the amount of packages made.

toString() returns a string containing information about the amount of ice cream, cream and sugar in the machine.

Chocolate ice cream is made like ordinary ice cream, but in the beginning cocoa is poured into the ice cream (in the program, this is described by decreasing the amount of cocoa in the machine). Write a class ChokoIceCreamMachine which is subclass of the class IceCreamMachine. The class should contain variables for the amount of cocoa in the machine and for the amount of cocoa needed to make one liter chocolate ice cream. Write a constructor, which is given as parameters the amount of cream, sugar and cocoa needed to make one liter ice cream in this machine. Write also the following methods:

addMaterial(double cream, double sugar, double cocoa) adds cream, sugar and cocoa to the machine. The amounts to be added are given as parameters.

make(double amount) makes chocolate ice cream. The amount made is given as a parameter. If there is not enough cocoa, cream or sugar for the given amount, the machine makes as much ice cream as it can. The method returns the amount of ice cream made (in liters).

toString() returns a string containing information about the amount of ice cream, cream, sugar and cocoa in the machine.

In addition, write a main program that creates one chocolate ice cream machine, adds cream, sugar and cocoa to it, makes a certain amount of ice cream and packs it. In the end, the program should output the amount of chocolate ice cream packages it made.

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

Define and discuss affirmative action.

Answered: 1 week ago