Question: Assume the following abstract data types: Stack and Bag You are required to: a) Implement these abstract data types as two separate classes without inheritance
Assume the following abstract data types: Stack and Bag
You are required to: a) Implement these abstract data types as two separate classes without inheritance between them
b) Create a client class, MyClientTest1, and provide methods to test each one of the methods implemented by Stack and Bag
c) Now, re-factor your program to use inheritance. Decide what class, e.g., Stack or Bag, should be the super-class. Provide a rationale of your design decision
d) Create a client class, MyClientTest2, and provide methods to test each one of the methods implemented by Stack and Bag
the Stack class State: a sequence of Objects s
isEmpty() : boolean Precondition: true Postcondition: returns true if and only if s is empty
take() : Object Precondition: ! isEmpty() Postcondition: result is the first item of s. The final value of s is the initial value with the first item removed.
put( ob : Object ) Precondition: true Postcondition: The final value of s is its initial value with ob prepended. the Bag class State: a bag (i.e. multiset) of Objects b
isEmpty() : boolean Precondition: true Postcondition: Returns true if and only if b is empty.
take() : Object Precondition: ! isEmpty() Postcondition: result is an arbitrary member of b. The final value of b is the initial value with the result removed. put( ob : Object ) Precondition: true Postcondition: The final value of b is its initial value with ob added.
i need to know how to do this.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
