Question: Please use java to answer this question, also try to use inheritance and polymorphism if you can. Desktop Class: State: 1. double price represents how
Please use java to answer this question, also try to use inheritance and polymorphism if you can.
Desktop Class:
State:
1. double price represents how much the desktop costs
2. int quantity represents how many units of this desktop there are in stock
3. double cpuSpeed the CPU speed, in Ghz
4. int ram the amount of RAM in GB
5. boolean sdd whether the hard-drive is an SSD (true) or HDD (false)
6. int storage the size of the hard-drive in GB
7. String profile a string describing the size of the desktop case
Behaviour:
1. Desktop(double price, int quantity, double cpuSpeed, int ram, boolean ssd, int storage, String profile) constructor for the class
2. double sellUnits(int amount) simulates selling amount units. If there are enough units in stock to meet the request, the quantity in stock must be updated appropriately and the total revenue for selling (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 0.0 should be returned.
3. String toString() returns a string representing the desktop. This should summarize the state of the desktop, including each attribute. See the example output included at the bottom for examples.
ElectronicStore Class:
State:
1. final int MAX_PRODUCTS = 10 the maximum number of products that this store can store. This value should be set to 10 and never changed.
2. int curProducts the current number of products in the store. This variable can be used to indicate how many products are stored in the stock array, as well as where the next product to be added should go.
3. String name the name of the electronics store
4. double revenue the total revenue the store has made through sales. This should initially be 0 but should be updated as products are sold.
5. Scanner in a scanner to be used to read user input for the sellProducts() method.
6. Product[ ] stock an array to store product objects that are in the store. This array should have size equal to MAX_PRODUCTS. In case you are working on this before we discuss polymorphism in class, all you need to know is that you can store any class that is below Product in the class hierarchy within this array. So if you have additional classes that extend Product (or in general, are further down the hierarchy), you can store them in this array without any problems.
Behaviour:
1. ElectronicStore(String name) constructor for the class.
2. String getName() returns the name of the store
3. boolean addProduct(Product p) if there is space remaining in the stock array, this method should add p to the stock array at the next available array slot and return true. If there is no space remaining in the stock array, this method should just return false.
4. void sellProducts() this method should print out the stock of the store (see example output below for an idea of how it should look), read an integer fromthe user representing the product to sell (i.e., what index in the stock array), read an integer from the user representing how many units of the product to sell. If the values supplied by the user are valid, the specified number of units of the specified product should be sold, if possible. All appropriate variables must be updated in all instances (e.g., revenue, number of units, etc.). If any of the input is invalid, no sales should take place.
5. void sellProducts(int item, int amount) should sell amount units of the product stored at index item in the stock array, if possible. All appropriate variables must be updated in all instances (e.g., revenue, number of units, etc.). If any of the input is invalid, no sales should take place.
6. double getRevenue() returns the total revenue the store has made through sales.
7. void printStock() should print out the stock of the store. See the example output at the bottom of the document for examples.
Fridge Class:
State:
1. double price represents how much the fridge costs
2. int quantity represents how many units of this fridge there are in stock
3. int wattage the wattage rating of the fridge
4. String color the color of the fridge
5. String brand the brand name of the fridge
6. double cubicFeet The volume of the fridge in cubic feet
7. boolean hasFreezer Whether the fridge has a freezer or not
Behaviour:
1. Fridge(double price, int quantity, int wattage, String color, String brand, int cubicFeet, boolean freezer) constructor for the class
2. double sellUnits(int amount) simulates selling amount units. If there are enough units in stock to meet the request, the quantity in stock must be updated appropriately and the total revenue for selling (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 0.0 should be returned.
3. String toString() returns a string representing the fridge. This should summarize the state of the fridge, including each attribute. See the example output included at the bottom for examples.
Laptop Class:
State:
1. double price represents how much the laptop costs
2. int quantity represents how many units of this laptop there are in stock
3. double cpuSpeed the CPU speed, in Ghz
4. int ram the amount of RAM in GB
5. boolean sdd whether the hard-drive is an SSD (true) or HDD (false)
6. int storage the size of the hard-drive in GB
7. double screenSize the size of the screen in inches
Behaviour:
1. Laptop(double price, int quantity, double cpuSpeed, int ram, boolean ssd, int storage, double screenSize) constructor for the class
2. double sellUnits(int amount) simulates selling amount units. If there are enough units in stock to meet the request, the quantity in stock must be updated appropriately and the total revenue for selling (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 0.0 should be returned.
3. String toString() returns a string representing the laptop. This should summarize the state of the laptop, including each attribute. See the example output included at the bottom for examples.
Product Class:
State:
1. double price represents how much the product costs
2. int quantity represents how many units of this product there are in stock
Behaviour:
1. Product(double price, int quantity) constructor for the class
2. double sellUnits(int amount) simulates selling amount units. If there are enough units in stock to meet the request, the quantity in stock must be updated appropriately and the total revenue for selling (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 0.0 should be returned.
ToasterOven Class:
State:
1. double price represents how much the toaster oven costs
2. int quantity represents how many units of this toaster there are in stock
3. int wattage the wattage rating of the toaster oven
4. String color the color of the toaster oven
5. String brand the brand name of the toaster oven
6. int width the width of the toaster oven
7. boolean convection whether the toaster has convection heating or not
Behaviour:
1. ToasterOven(double price, int quantity, int wattage, String color, String brand, int width, boolean convection) constructor for the class
2. double sellUnits(int amount) simulates selling amount units. If there are enough units in stock to meet the request, the quantity in stock must be updated appropriately and the total revenue for selling (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 0.0 should be returned.
3. String toString() returns a string representing the toaster oven. This should summarize the state of the toaster oven, including each attribute. See the example output included at the bottom for examples.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
