Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, you will apply the OOP principles of encapsulation and inheritance to the redesign of the electronic store classes from Assignment #1. A

For this assignment, you will apply the OOP principles of encapsulation and inheritance to the redesign of the electronic store classes from Assignment #1. A list of the classes that must be contained in your program are given below, along with a summary of their states and behaviours. It is up to you to decide on and implement the appropriate class hierarchy. You will likely need to add more classes to define the best class hierarchy look for shared state/behaviour between different classes and define a parent class if you need to. Note that you will not need to define/implement all these methods/attributes in each class if you make proper use of inheritance. Additionally, you must use proper encapsulation in designing these classes. All your instance variables should be private, unless you can justify them being protected/public. You should be able to complete the assignment without creating any public/protected variables. If you include a protected/public variable, also include a comment with your justification. You can add additional methods (e.g., getter/setter methods) to the classes as you see fit. A large portion of your mark will come from the quality of your class design and proper use of encapsulation, inheritance, and polymorphism. Three classes are included on the assignment page for testing. Your code should work with these test case classes. When you run the test case classes, the output should be very similar to the output included at the end of this document. The only difference may be in the formatting of the objects, though your toString() methods should closely mirror the formatting included here. You should test your code with your own additional test cases as well. The supplied test classes only provide a minimal amount of testing. Desktop Class: State: 1. double price represents how much the desktop costs 2. int stockQuantity represents how many units of this desktop are in stock 3. int soldQuantity represents how many units of this desktop have been sold 4. double cpuSpeed the CPU speed in Ghz 5. int ram the amount of RAM in GB 6. boolean ssd whether the hard-drive is an SSD (true) or HDD (false) 7. int storage the size of the hard-drive in GB 8. String profile a string describing the size of the desktop caseAssignment # 2 Due: March 3rd 11:59 PM Page 5 of 12 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 attributes must be updated appropriately and the total revenue (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 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 different product instances that this store can contain. This value should be set to 10 and never changed. The code throughout your class should refer to this variable so that the maximum number of products can be changed by changing the value assigned to the variable. 2. String name the name of the electronics store 3. double revenue the total revenue the store has made through sales. This should initially be 0 but must be updated as products are sold. 4. The class must also store an array of electronic store products that is of size MAX_PRODUCTS. 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 products array, this method should add p to the products array at the next available array slot and return true. If there is no space remaining in the products array, this method should just return false. 4. boolean sellProducts() this method should print out the stores products (see example output below for an idea of how it should look), read an integer from the user representing the product to sell (i.e., what index in the products array), and read an integer from the user representing how many units of the product to sell. You may assume the user will only enter integer numbers but must verify that the values are valid (e.g., a valid item index, an amount greater than 0, etc.). 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 in stock, etc.). If any of the input is invalid,Assignment # 2 Due: March 3rd 11:59 PM Page 6 of 12 no sale should take place. This method should return true to indicate the sale was successfully processed and false if the sale could not be made for any reason. 5. boolean sellProducts(int item, int amount) should sell amount units of the product stored at index item in the products array, if possible. All appropriate variables must be updated in all instances (e.g., revenue, number of units in stock, etc.). If any of the input is invalid, no sales should take place. This method should return true to indicate the sale was successfully processed and false if the sale could not be made for any reason. 6. double getRevenue() returns the total revenue the store has made through sales. 7. void printStock() should print out the products 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 stockQuantity represents how many units of this fridge there are in stock 3. int soldQuantity represents how many units of this fridge have been sold 4. int wattage the wattage rating of the fridge 5. String color the color of the fridge 6. String brand the brand name of the fridge 7. boolean hasFreezer Whether the fridge has a freezer or not Behaviour: 1. Fridge(double price, int quantity, int wattage, String color, String brand, 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 attributes must be updated appropriately and the total revenue (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 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 stockQuantity represents how many units of this laptop there are in stock 3. int soldQuantity represents how many units of this laptop have been sold 4. double cpuSpeed the CPU speed, in Ghz 5. int ram the amount of RAM in GB 6. boolean ssd whether the hard-drive is an SSD (true) or HDD (false)Assignment # 2 Due: March 3rd 11:59 PM Page 7 of 12 7. int storage the size of the hard-drive in GB 8. 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 attributes must be updated appropriately and the total revenue (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 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. Oven Class: State: 1. double price represents how much the oven costs 2. int stockQuantity represents how many units of this oven are in stock 3. int soldQuantity represents how many units of this oven have been sold 4. int wattage the wattage rating of the oven 5. String color the color of the oven 6. String brand the brand name of the oven 7. boolean convection whether the oven has convection heating or not Behaviour: 1. Oven(double price, int quantity, int wattage, String color, String brand, 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 attributes must be updated appropriately and the total revenue (revenue = units * price) should be returned. If there are not enough units in stock, no sale should take place and 0 should be returned. 3. String toString() returns a string representing the oven. This should summarize the state of the oven, including each attribute. See the example output included at the bottom for example

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What ethical issues are present in international product marketing?

Answered: 1 week ago