Question
Given the following UML Class Diagram Stock -name: String -Items: Arraylist + Stock (all parameters) + getName(): String + getItems (): ArrayList +addElectronic(E: Electronic) +addGrocery(G:
Given the following UML Class Diagram
Stock |
-name: String -Items: Arraylist |
+ Stock (all parameters) + getName(): String + getItems (): ArrayList +addElectronic(E: Electronic) +addGrocery(G: Grocery) +countElectronic(): int +countGrocery(): int |
StockItem |
# brand: String # price: double # discount: double |
+ StockItem(all parameters) + Setters & Getters + toString() : String |
Grocery |
- expiryYear : int - weight: double |
+ Grocery (all parameters) + Setters & Getters + toString(): String |
Electronic |
- type: String - power: double |
+ Electronic (all parameters) + Setters & Getters + toString(): String |
[15 pts] Implement the class StockItem, which contains:
- A constructor which accepts all required arguments
- Set & get method for each data attribute.
- A toString() method which returns a String containing all attributes of StockItem object as follows.
Assume the object is a Kenwood whose price is $230 and discount= 0.08. The toString() method returns: Kenwood ($230) has discount = 8%
Assume the object is a Kenwood whose price is $230 and discount= 0.0. The toString() method returns:
Kenwood ($230)
[15 pts] Implement the Grocery class as described in the class diagram.
- A constructor which accepts all required arguments (5 parameters)
- Set & get method for each data attribute.
- A toString() method which returns a String containing all attributes of Grocery object as follows:
Nutella ($7.5) has discount = 10%, expiry Year = 2022 (0.75Kg)
Septol ($5) , expiry Year = 2025 (0.45Kg)
[15 pts] Implement the Electronic class as described in the class diagram.
- A constructor which accepts all required arguments (5 parameters)
- Set & get method for each data attribute.
- A toString() method which returns a String containing all attributes of Electronics as follows:
Kenwood ($230) discount = 8% (in Home Appliances) 1800Watt
[15 pts] Implement the class Stock, which contains:
- A constructor which accepts the name and create an array of stock items
- The following methods:
- getName: returns the name of stock
- getItems: returns an array of stock Items
- addElectronic: to add an Electronic item to array
- addGrocery(G: Grocery): to add Grocery item to array
- countElectronic(): gives the number to electronic item
- countGrocery(): gives the number to Grocery item
Part II: Driver Class
Question I [40 points]
Write a test/driver program to:
- [10 pts] Create a stock object named Kadisha.
- [10 pts] Fill the stock with Grocery and Electronics items of your choice.
- [10 pts] Print all expired Grocery items (that have an expiry date less than 2021).
- [10 pts] Get the brands, type and price after discount of Electronics items having discount.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started