2ws
COSC 1P03 Assignment 3 Linked Structures and Generics Refer to Sakai for due date. Objective: To implement a simple ADT that supports dynamic storage of arbitrary types, and to write a program that demonstrates it through an interactive text interface. Background: Let's define a Pouch ADT: • It could hold pretty much anything ◦ It doesn't hold mixed types; it can simply be declared/instantiated to hold anything • It can hold (nearly) any number of those things ◦ I'd go so far as to say, “it grows and shrinks with the amount of data it holds” • You can add an item to the pouch ◦ (If you want to add multiple items, do it multiple times) • You can retrieve a single item from the pouch ◦ There is no expectation of which item you will receive ◦ If you try to retrieve from an empty pouch, that's an underflow • You can check if the bag isEmpty • You can shake the bag, to rearrange its contents somehow ◦ There's no specific expectation of how to do this, but it should be reasonably expected to be at least somewhat different in its internal sequence after this • You can iterate over the pouch ◦ Through conventional means A suitable client program would have the ability to test all of these features, as much as desired, until he or she wished to exit. Requirements: The ADT and the client must be in different packages. • You must design your solution, in Dr. Java, to include both packages ◦ If you try writing it elsewhere and then dropping it in, don't be surprised if you get a zero • The ADT is in the bagofholding package, and the client is in the client package ◦ Make sure your project is configured to have client.Client as the 'main class' ▪ (Don't forget you can ask me about these things?) You need a Pouch interface, and a separate LnkPouch implementation. • I trust you know why it's called LnkPouch • Also in the same package will be an UnderflowException (you can just borrow from the class example) • Clearly you'll also need to write your own iterator for this The shaking really doesn't have to be any single specific implementation; it just needs to be obvious to the marker that its sequence is changing each time (unfortunately, simply reversing the list wouldn't accomplish this). You are advised to check out the sample execution at the end. That's what the marker will be using as a 'reasonable example' of a client program. You need to include a (brief) writeup, explaining how you 'shook' your pouch. Include a diagram. Tips: I know I always say, “don't cheat”, but just to be clear: in spite of the name, this 'pouch' is not the same thing as the more common 'bag'. So if you try googling how to write a bag, please don't complain when you receive a zero for doing the entirely wrong assignment. K? It should be obvious from the description above that this needs to be generic. If it isn't, again, don't be surprised by a zero. Also, the 'shaking' method is probably the hardest part of the whole assignment, but since it's just reorganizing you could (hypothetically) save that one for last. There'll probably be quite a few completely different implementations for this. • It would not be reasonable to expect the markers to fix your indentation for you • It would not be reasonable to expect the markers to pull apart indecipherable code • You will make it easy to tell what you're doing, or someone will be sad If there is a single System.out.println anywhere in your bagofholding package, or a single mention of String, you're doing it wrong. Lastly, my interface is about 7 lines of code, my implementation around 50, and my client is ~60. The mechanisms themselves are not the difficult part here. Your goals are: • To get experience making linked structures that don't fit a specific existing model • To carefully follow instructions • To document your work Submission: Submission is electronic only. Bundle up your solution, which must include: • All of your source files (obviously) • Your Dr. Java project • A sample execution demonstrating how your program works • Your writeup, in .pdf format • All files you used to create your writeup Put all of the above (and whatever else the marker needs to easily grade your work) into a .zip file, and submit it through Sakai. Important: you're writing this, from start to end, in Dr. Java. Sample execution: What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit show What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit add Type in each term. Enter an empty line when finished. Hello class! This is neat? What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit show neat? is This class! Hello What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit retrieve Removing: neat? What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit add Type in each term. Enter an empty line when finished. I had fun with this What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit show this with fun had I is This class! Hello What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit shake (shake shake) What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit show Hello had with I This fun class! is this What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit shake (shake shake) What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit show this is class! fun This I with had Hello What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit empty Removing: this Removing: is Removing: class! Removing: fun Removing: This Removing: I Removing: with Removing: had Removing: Hello What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit show What would you like to do? [add]: Add to pouch [retrieve]: Retrieve a single entry [show]: Display pouch [shake]: Shake pouch [empty]: Empty pouch [exit]: Exit exit Bye!