AP CSA 2021 Q3 - ClubMembers Class


<-- Back to Solution of Q2 (CombinedTable) - FRQ - 2021 Next to Solution of Q4 (ArrayResizer) - FRQ - 2021 -->





Solution of Q3 (ClubMembers) - Free Response Question - 2021


The original question can be found at: https://apcentral.collegeboard.org/media/pdf/ap21-frq-computer-science-a.pdf


Part (a)- public void addMembers(String[] names, int gradYear)


    public void addMembers(String[] names, int gradYear)
    {
        memberList= new ArrayList();
        for (int i=0; i< names.length; i++)
        {
            memberList.add(new MemberInfo(names[i], gradYear, true));
        }
    }



Part (b)- public ArrayList removeMembers(int year)


    public ArrayList removeMembers(int year)
    {
        ArrayList newList = new ArrayList();
        MemberInfo member;
        for (int i=memberList.size() -1; i >=0 ; i--)
        {
            member = memberList.get(i);
            if ((member.getGradYear() <= year))
            {
                // add to the newList
                if (member.inGoodStanding()) newList.add(member);
                
                //remove from the memberList
                memberList.remove(i);
            }

        }
        
        return newList;
    }

Java project files (with Runner code):


<-- Back to Solution of Q2 (CombinedTable) - FRQ - 2021 Next to Solution of Q4 (ArrayResizer) - FRQ - 2021 -->