Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you will write several classes to simulate an online Market place. Make sure to follow the instructions below very closely. Note that

image text in transcribedimage text in transcribed

For this assignment you will write several classes to simulate an online Market place. Make sure to follow the instructions below very closely. Note that in addition to the required methods, you are free to add as many other private methods as you want (no other additional method is allowed) [10 points] Write an abstract class MarketProduct which has the following private field: A String name The class must also have the following public methods . A constructor that takes a String as input indicating the name of product and uses it to initialize the corresponding attribute. . A final getName) method to retrieve the name of this MarketProduct An abstract method getCost) which takes no input and returns an int. This method should be abstract (thus, not implemented) because how to determine the cost depends on the type of product. An abstract method equals) which takes an Object as an input and returns a g on the type of product boolean. This method should be abstract as well, since d different conditions should be met in order for two products to be considered equal [25 points All of the followings must be subclasses of the MarketProduct Write a class Egg derived from the MarketProduct class. The Egg class has the following private fields - An int indicating the number of eggs An int indicating the price per dozen of these eggs. Note that the all the prices (throughout the assignment) are indicated in cents. For instance, 450 represents the amount $4.50. The Egg class has also the following public methods: A constructor that takes as input a String with the name of the product, an int indicating the number required, and an int indicating the price of such product by the dozen. The constructor uses the inputs to create a MarketProduct and initialize the corresponding fields - A getCost ) method that takes no input and returns the cost of the product in cents. The cost is computed base on the number required and the cost per dozen For instance, 4 large brown eggs at 380 cents/dozen cost 126 cents (the cost should be rounded down to the nearest cent). You may assume that cost of all MarketProducts fits within an int and therefore doesn't cause overflow An equals method which takes as input an Object and return true if input matches this in type, name, cost and number of eggs. Otherwise the method returns false

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions