1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
import java.util.*;
/**
* Instances of the ReadingList class maintain a set of book titles
* that are recommended for course and a reading record for each
* student on the course.
*
* @author CT
* @version 1.0
**/
public class ReadingList
{
//instance variables
private Set<String> courseBooks;
private Set<String> readBooks;
private Map<String, Set <String>> studentRecords;
/**
* Constructor for objects of class ReadingList
*/
public ReadingList()
{
super();
this.courseBooks = new HashSet<String>();
this.readBooks = new HashSet<String>();
this.studentRecords = new HashMap<String, Set <String>>();
}
//instance methods
/**
* Returns the courseBooks of the receiver
*/
public Set <String> getCourseBooks()
{
return this.courseBooks;
}
/**
* Add course book title to the courseBookSet
*/
public void addCourseBook(String title)
{
Set <String> courseBooksSet = new HashSet<String>();
courseBooks.add(title);
}
/**
* Remove course book title from the courseBookSet
*/
public void removeCourseBook(String title)
{
Set <String> courseBooksSet = new HashSet<String>();
courseBooks.remove(title);
}
/**
* Print book title from the courseBooksSet
*/
public void printBooks(Set <String> courseBooksSet)
{
String newline;
newline = System.getProperty("line.separator");
for (String book : courseBooksSet)
{
System.out.println(book + newline);
}
}
/**
* Enable students to make a list of the books they have read
* whether they are on the course reading list or not
*/
public static Set <String> collectBooksRead()
{
Set <String> readBooksSet = new HashSet<String>();
String dialogString = "Please input a book title or * to finish";
String input = OUDialog.request(dialogString);
while(input != null)
{
readBooksSet.add(input);
input = OUDialog.request(dialogString);
}
return readBooksSet;
}
/**
* Method take a single argument of a set of strings called studentBooks,
* the method delete any elements of the set referenced by studentBooks,
* that do not occur in courseBooks.
*/
public static Set <String> deleteNonCourseBooks(Set <String> studentBooks)
{
Set<String> studentBooksSet = new HashSet<String>();
Set<String> courseBooksSet = new HashSet<String>();
studentBooksSet.retainAll(courseBooksSet);
for (String book : studentBooks)
{
System.out.println(book);
}
return studentBooks;
}
} |