Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. A constructor which accepts all required arguments
  2. Set & get method for each data attribute.
  3. 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.

  1. A constructor which accepts all required arguments (5 parameters)
  2. Set & get method for each data attribute.
  3. 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.

  1. A constructor which accepts all required arguments (5 parameters)
  2. Set & get method for each data attribute.
  3. 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:

  1. A constructor which accepts the name and create an array of stock items
  2. The following methods:
    1. getName: returns the name of stock
    2. getItems: returns an array of stock Items
    3. addElectronic: to add an Electronic item to array
    4. addGrocery(G: Grocery): to add Grocery item to array
    5. countElectronic(): gives the number to electronic item
    6. countGrocery(): gives the number to Grocery item

Part II: Driver Class

Question I [40 points]

Write a test/driver program to:

  1. [10 pts] Create a stock object named Kadisha.
  2. [10 pts] Fill the stock with Grocery and Electronics items of your choice.
  3. [10 pts] Print all expired Grocery items (that have an expiry date less than 2021).
  4. [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

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions