Search code examples
javaumladt

java hw Need Help to understand


I'll write down the whole problem first.

A ring is a collection of items that has a reference to a current item. An operation -- let's call it advance--moves the reference to the next item in the collection. When the reference reaches the last item, the next advance operation will move the reference back to the first item. A ring also has operations to get the current item, add an item, and remove an item. The details of where an item is added and which one is removed are up to you.

Design an ADT(Abstract Data Type) to represent a ring of objects. Specify each operation by stating its purpose, by describing its parameters, and by writing a pseudocode version of its header. Then write a Java interface for a ring's methods. Include javadoc-style comments in your code.

So is it saying the Ring is like a class with operation that can move items by using a reference variable like T = items? And Advance would change T to represent a different item each time it's being called? Something like in UML format....

ADT: Ring

+advance(): T // move T to next item in collection and if T reaches last item, move T back to the first item.

+getCurrItem(): T // return item that T reference.

+addItem(item T): void // add an item in for T, No return.

+removeItem(Item: T): boolean // remove item that T reference and return true | false if it succeed or not.

Am I on the right track or am I supposed to do something else?


Solution

  • That looks like a good start to me. Now you have to work on designing the ADT and how you suppose you will store items and reference the end to the beginning. This is a data abstractions problem, and you can approach the implementation in several ways, but it's up to you to design it in an efficient way.