CS230 Lab: Linked Lists - Student Organizations

Lab: Linked Lists - Student Organizations

Goals:

In this lab you will work with and practice with:

  • java's LinkedList class and several of its methods
  • generics vs specific type of Objects
  • practice with IO and relevant Exceptions
  • Interfaces, and
  • the concept of Inheritance
 

Solutions

 

Student Organizations at Wellesley College

Student Organizations at Wellesley College are clubs, created and managed entirely by students, with the purpose of enhancing the Wellesley Community. Students are encouraged to participate in these clubs as well as to create new Organizations if they feel they are needed to cover some interest. There are currently over 200 student organizations at Wellesley College.

A Student Organization has a President, may have a vice-president, as well as regular members. All Organization members need to be current Wellesley students. Once a student has graduated, they cannot be an organization member or officer any more.

For this cs230 lab, we will use java's Linked Lists to represent Student Organizations. Each Student Organization will contain a list of members. Every item in that List will be an object of type ClubStudent (which we will also define for the purpose of this assignment). Do you think that this is a suitable data structure for this application? Why?

[START PRELAB]

 

Task 0: Set up

Download lab7 and, in BlueJ start a new project, named Lab7Project. Add the following classes to it (from the downloaded folder):

  • Student.java,
  • RegStudent.java

Notice that in the downloaded folder there is also a file named snackMembers.txt

 

Task 1: ClubStudent.java

In BlueJ's editor, open the two java classes in your project. Study the code. How do they relate to each other?

Add one more class, named ClubStudent, to represent a student for the purposes of the lab today, i.e Student Clubs. What would be useful information to keep track of? Include the year the student joined the student organization. What methods would you add to this class? Make sure to define the equals() method: two students are considered equal, if their user names are equal. In which class would you define this method?

Add a main() method and do some basic testing.

[END PRELAB]

 

Task 2: StudentOrganization.java

Your task is to write the definition of a new class, named StudentOrganization. An instance of a StudentOrganization will store a collection of ClubStudent objects: the students who belong to that organization.

You will to use java's LinkedList implementation in your code. Which package do you need to import?

Your class should contain:

  • INSTANCE VARIABLES

    • an instance variable of type LinkedList to hold objects of type ClubStudent
    • instance variables to hold the name of the Organization, its president and Vice President.
  • CONSTRUCTOR(s)
    • a constructor that takes the name of the Organization as its only input. It is used to create an organization with no members.
  • OTHER METHODS
    • toString() to provide for a reasonable string representation of a Student Organization
    • a method to add a member to the Organization
    • a membership method, to examine whether a given student is a member of the Organization
    • a method to remove all graduating students upon their graduation
    • a method to figure out the common members between two organizations
    • any other methods you think are appropriate

You can add your testing code in the StudentOrganization.java file, or you can create a driver program.

Below is some sample testing. (This is just a sample! Your testing should be more exhaustive than what is shown below.)


Organization Name: Knitting Club
   President:       Stella Kakavouli (skakavou) 2020 member since 2017
   Vice President:  null

   There are 6 total members in the Org:
   Sohie Lee (slee) 2021 member since 2018
   Stella Kakavouli (skakavou) 2020 member since 2017
   Teresa Li (tli) 2022 member since 2015
   Anna Pfoertsch (apfoerts) 2022 member since 2019
   Olivia Salomon (osalomon) 2023 member since 2019
   Jackie Young (jyoung) 2021 member since 2019

*** Testing isMember() ***
Is Maria a member of knitters? (false): false
Is Stella a member of knitters? (true): true

*** Testing addMember() ***
Testing addMember with the CS Club, adding members one by one:

Organization Name: CS Club
   President:    Jenny Wang (jwang) 2017 member since 2015
   Vice President:    Tiffany Ang (tang) 2017 member since 2015

   There are 12 total members in the Org:
   Meher Vohra (mvohra) 2019 member since 2016
   Olivia Salomon (osalomon) 2019 member since 2015
   Jackie Young (jyoung) 2019 member since 2015
   Teresa Li (tli) 2019 member since 2015
   Evelyn Chen (echen) 2019 member since 2015
   Jesslyn Tannady (jtannady) 2019 member since 2015
   Adrianna Tan (atan) 2019 member since 2015
   Andrea Jackson (ajackson) 2018 member since 2014
   Anna Pfoertsch (apfoerts) 2017 member since 2015
   Alice Zhou (azhou) 2019 member since 2015
   Jenny Wang (jwang) 2017 member since 2015
   Tiffany Ang (tang) 2017 member since 2015

   Try to add Teresa to the Knitting Club:
   Teresa is already a member of the Knitting Club.

Testing removeYearMembers: cs.removeYearMembers(2017)

Organization Name: CS Club
   President: null
   Vice President: null
   There are 9 total members in the Org:
   Meher Vohra (mvohra) 2019 member since 2016
   Olivia Salomon (osalomon) 2019 member since 2015
   Jackie Young (jyoung) 2019 member since 2015
   Teresa Li (tli) 2019 member since 2015
   Evelyn Chen (echen) 2019 member since 2015
   Jesslyn Tannady (jtannady) 2019 member since 2015
   Adrianna Tan (atan) 2019 member since 2015
   Andrea Jackson (ajackson) 2018 member since 2014
   Alice Zhou (azhou) 2019 member since 2015

Is Alice a member of knitters club? (false): false
Adding Alice to the knitters club
Is Alice a member of knitters club? (true): true

Testing common members in knitters and cs clubs:
[
Olivia Salomon (osalomon) 2019 member since 2015, Jackie Young (jyoung) 2019 member since 2015, Teresa Li (tli) 2019 member since 2015, Alice Zhou (azhou) 2019 member since 2015
]

Below are some sample ClubStudents that you can copy and paste to speed up your testing, if you like. You can also create your own ClubStudent objects.


     ClubStudent c1 = new ClubStudent("Jenny Wang", "jwang",2017, 2015);
     ClubStudent c2 = new ClubStudent("Meher Vohra", "mvohra",2019, 2016);  
     ClubStudent c3 = new ClubStudent("Tiffany Ang", "tang",2017, 2015);
     ClubStudent c4 = new ClubStudent("Olivia Salomon", "osalomon",2019, 2015);
     ClubStudent c5 = new ClubStudent("Jackie Young", "jyoung",2019, 2015);
     ClubStudent c6 = new ClubStudent("Teresa Li", "tli",2019, 2015);
     ClubStudent c7 = new ClubStudent("Evelyn Chen", "echen",2019, 2015);
     ClubStudent c8 = new ClubStudent("Jesslyn Tannady", "jtannady",2019, 2015);
     ClubStudent c9 = new ClubStudent("Adrianna Tan", "atan",2019, 2015);
     ClubStudent c10 = new ClubStudent("Andrea Jackson", "ajackson",2018, 2014);
     ClubStudent c11 = new ClubStudent("Anna Pfoertsch", "apfoerts",2017, 2015);
     ClubStudent c12 = new ClubStudent("Alice Zhou", "azhou",2019, 2015);
     ClubStudent c13 = new ClubStudent("Maria Ang", "mang",2019, 2015);

     ClubStudent c14 = new ClubStudent("Sohie Lee", "slee", 2021, 2018);
     ClubStudent c15 = new ClubStudent("Stella Kakavouli", "skakavou", 2020, 2017);
 

Task 3: Read members from a file

It's a bit cumbersome to add members one at a time. It would be great to read in the members from a file, and then create a new Student Organization using that data. In your download folder, there is a text file called snackMembers.txt which contains several students.

Your task is to write a new constructor that takes two parameters: the name of the club to be created and the file with the information about its members. Here is a snippet of snackMembers.txt:

Each line of the text file contains information about one student.A sample invocation of your constructor in your main method might look like this:
StudentOrganization snackClub = new StudentOrganization("Snack Club", "snackMembers.txt");

 

Task 4: All Organizations

If you have any time left, think about how you can keep track of all the Student Organizations in a certain institution, like Wellesley. What kind of structure would you use? Set up a java class to do so. Then, write a method to produce the Presidents of all the Organizations.