Computer Science A
2021 FRQ 3
- FRQ Question
- Code Runner Challenge
- Part (a) - addMembers
- Scoring Guidelines Part (a)
- Part (b) - removeMembers
- Scoring Guidelines Part (b)
FRQ Question
A high school club maintains information about its members in a MemberInfo object. A MemberInfo object stores a club member’s name, year of graduation, and whether or not the club member is in good standing. A member who is in good standing has fulfilled all the responsibilities of club membership.
A partial declaration of the MemberInfo class is shown below:
Code Runner Challenge
Club Members ArrayList Management
View IPYNB Source
public class MemberInfo {
public MemberInfo(String name, int gradYear, boolean hasGoodStanding) { }
public int getGradYear() { }
public boolean inGoodStanding() { }
}
The ClubMembers class maintains a list of current club members:
public class ClubMembers {
private ArrayList<MemberInfo> memberList;
public void addMembers(String[] names, int gradYear) { }
public ArrayList<MemberInfo> removeMembers(int year) { }
}
// CODE_RUNNER: Club Members ArrayList Management
import java.util.ArrayList;
class MemberInfo {
private String name;
private int gradYear;
private boolean hasGoodStanding;
public MemberInfo(String name, int gradYear, boolean hasGoodStanding) {
this.name = name;
this.gradYear = gradYear;
this.hasGoodStanding = hasGoodStanding;
}
public int getGradYear() { return gradYear; }
public boolean inGoodStanding() { return hasGoodStanding; }
public String toString() { return name + " (" + gradYear + ") - " + (hasGoodStanding ? "Good" : "Bad"); }
}
class ClubMembers {
private ArrayList<MemberInfo> memberList;
public ClubMembers() {
memberList = new ArrayList<>();
}
public void addMembers(String[] names, int gradYear) {
// PART (a): Implement this method
for (String name : names) {
memberList.add(new MemberInfo(name, gradYear, true));
}
}
public ArrayList<MemberInfo> removeMembers(int year) {
// PART (b): Implement this method
ArrayList<MemberInfo> graduated = new ArrayList<>();
for (int i = memberList.size() - 1; i >= 0; i--) {
MemberInfo member = memberList.get(i);
if (member.getGradYear() <= year) {
if (member.inGoodStanding()) {
graduated.add(member);
}
memberList.remove(i);
}
}
return graduated;
}
public void printMembers() {
System.out.println("Current Members:");
for (MemberInfo m : memberList) {
System.out.println(" " + m);
}
}
}
public class Main {
public static void main(String[] args) {
ClubMembers club = new ClubMembers();
// Add members
String[] names1 = {"FOX, STEVE", "XIN, MICHAEL"};
club.addMembers(names1, 2018);
String[] names2 = {"SMITH, JANE", "GARCIA, MARIA"};
club.addMembers(names2, 2019);
System.out.println("Before removeMembers(2018):");
club.printMembers();
ArrayList<MemberInfo> graduated = club.removeMembers(2018);
System.out.println("\nAfter removeMembers(2018):");
club.printMembers();
System.out.println("\nGraduated in good standing:");
for (MemberInfo m : graduated) {
System.out.println(" " + m);
}
}
}
Main.main(null);
Part (a) - addMembers
Write the ClubMembers method addMembers, which takes two parameters:
- A String array containing the names of new club members to be added
- The graduation year of all the new club members
The method adds the new members to the memberList instance variable. The names can be added in any order. All members added are initially in good standing and share the same graduation year.
public void addMembers(String[] names, int gradYear)
Scoring Guidelines Part (a)
| Criterion | Decision Rules | Points |
|---|---|---|
| Accesses all elements of names (no bounds errors) | Responses will not earn the point if they fail to access elements of the array, even if loop bounds are correct | 1 |
| Instantiates a MemberInfo object with name from array, provided year, and good standing | 1 | |
| Adds MemberInfo objects to memberList (in the context of a loop) | Responses can earn the point even if they instantiate MemberInfo objects incorrectly | 1 |
| Total for part (a) | 3 |
Part (b) - removeMembers
Write the ClubMembers method removeMembers, which takes the following actions:
- Returns a list of all students who have graduated and are in good standing
- A member has graduated if their graduation year is less than or equal to the method’s year parameter
- If no members meet these criteria, an empty list is returned
- Removes from memberList all members who have graduated, regardless of whether or not they are in good standing
Example
Given the following memberList before calling removeMembers(2018):
| Name | Year | Good Standing |
|---|---|---|
| SMITH, JANE | 2019 | false |
| FOX, STEVE | 2018 | true |
| XIN, MICHAEL | 2017 | false |
| GARCIA, MARIA | 2020 | true |
After removeMembers(2018):
memberList: | Name | Year | Good Standing | |——|——|—| | SMITH, JANE | 2019 | false | | GARCIA, MARIA | 2020 | true |
Returned ArrayList: | Name | Year | Good Standing | |——|——|—| | FOX, STEVE | 2018 | true |
public ArrayList<MemberInfo> removeMembers(int year)
Scoring Guidelines Part (b)
| Criterion | Decision Rules | Points |
|---|---|---|
| Declares and initializes an ArrayList of MemberInfo objects | Responses will not earn the point if they initialize the variable with a reference to the instance variable | 1 |
| Accesses all elements of memberList for potential removal (no bounds errors) | Responses will not earn the point if they: fail to use get(i), fail to attempt to remove an element, skip an element, or throw an exception due to removing |
1 |
| Calls getGradYear or inGoodStanding | Responses will not earn the point if they ever include parameters in either method call or call either method on an object other than MemberInfo | 1 |
| Distinguishes any three cases, based on graduation status and standing | Responses will not earn the point if they fail to behave differently in all three cases | 1 |
| Identifies graduating members | Responses will not earn the point if they confuse < and <= in the comparison |
1 |
| Removes appropriate members from memberList and adds appropriate members to the ArrayList to be returned | Responses will not earn the point if they fail to declare an ArrayList to return or fail to distinguish the correct three cases (with exception of confusing < and <= in comparison) |
1 |
| Total for part (b) | 6 | |
| Total for question 3 | 9 |