Help Please - exam question
I'm having difficulty with the following question for an OU exam:
You will now create a method to enable students to make a list of the books they have read, whether they are on the courses reading list or not.
Add an instance method to the class, with the header: public Set<String> collectBooksRead()
The method should first declare a local variable of type Set called readBooks capable of holding a set of strings.
The method should then assign to that variable an appropriate set object.
The method should then use a dialogue box to collect the book titles one at a time from the user.
The dialogue box should have the prompt "Please input a book title or * to finish", and should have an empty string as its default reply.
Each entered book title should be added to the set referenced by the local variable readBooks. Finally the method should return readBooks as the message answer.
Here's my code so far but it endlessly loops and I'm unsure how to make it stop.
public Set<String> collectBooksRead()
{
Set<String> readBooks = new HashSet<String>();
String title;
{
do
{
title = OUDialog.request("Please input a book title or * to finish",""); //OUDialog.request displays an input dialogue box as specified by a superclass
readBooks.add(title);
}
while
(title != "*");
}

