Welcome to lab 10!
If you have checkpoints from the last lab to show your instructor or TA, do so immediately. No credit will be given if you have not already completed the work, nor will credit be given after the first 10 minutes of this lab.
In this lab you will create our own custom data types. We will model objects’ state and behaviors using classes in Java.
Person A types.
Solve the following problems on Practice-It!:
Person B types.
Write a class
RoundRobinList that can be used to repeatedly and fairly cycle through a list of people or things. For example, if you create a list and add to it
"carbonite", you’ll generate the following sequence when you call
get 8 times:
carbonite banana apple carbonite banana apple carbonite banana
Include the following:
Strings to hold the cycleable elements.
sizemethod that returns the number of elements in the list.
addmethod that accepts a
Stringto add to the list. When added, the name should be inserted such that it will be the next name chosen. For example:
list.add("Florence"); list.add("Bologna"); list.add("Turin"); System.out.println(list.get()); // prints Turin
getmethod that returns as a
Stringthe next element to cycle through. The element after the one returned is now the next to be drawn, and the element returned won’t be retrieved again until all the remaining elements in the list have been retrieved. In other words, make sure the list visits all elements in a “round robin” fashion.
RoundRobinTest, write a
main method that constructs an instance of
RoundRobinList, adds some elements, and cycles through it a few times. Print each element as you retrieve it.