Hack 1

How do we access the even numbers in arrayOne from above?

import java.util.Arrays;
int[] arrayOne = {1, 3, 5, 7, 9};
for (int i = 0; i<arrayOne.length;i++)
{
    if (arrayOne[i] % 2 == 0)
    {
        System.out.println(arrayOne[i] + " ");
    }
}

Hack 2

Which of the following is FALSE about arrays

  • A. A java array is an object
  • B. Length of array can be changed after creation of array
  • C. Numerical data types of arrays are initialized to 0 to start

B

APCSA 2021 Question 3

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.

    • public class MemberInfo { / Constructs a MemberInfo object for the club member with name name, graduation year gradYear, and standing hasGoodStanding. / public MemberInfo(String name, int gradYear, boolean hasGoodStanding) { / implementation not shown */ } / Returns the graduation year of the club member. / public int getGradYear() { / implementation not shown / } /** Returns true if the member is in good standing and false otherwise. / public boolean inGoodStanding() { / implementation not shown / } // There may be instance variables, constructors, and methods that are not shown. }
  • The ClubMembers class maintains a list of current club members. The declaration of the ClubMembers class is shown below.

    • public class ClubMembers { private ArrayList memberList; / Adds new club members to memberList, as described in part (a). Precondition: names is a non-empty array. / public void addMembers(String[] names, int gradYear) { / to be implemented in part (a) */ } / Removes members who have graduated and returns a list of members who have graduated and are in good standing, as described in part (b). / public ArrayList removeMembers(int year) { /</em> to be implemented in part (b) */ } // There may be instance variables, constructors, and methods that are not shown. } </li> </ul> </li> </ul> </div> </div> </div>

      (A)

      Write the ClubMembers method addMembers, which takes two parameters. The first parameter is a String array containing the names of new club members to be added. The second parameter is 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, gradYear.

      Complete the addMembers method.

      /* Adds new club members to memberList, as described in part (a). Precondition: names is a non-empty array./

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

      public void addMembers(String[] names, int gradYear)
      {
          for (String n : names)
          {
              MemberInfo newM = new MemberInfo (n, gradYear, true);
              memberList.add(newM);
          }
      }
      
      </div>