Classes

  • classes are "blueprints" that we use to instantiate objects
  • classes are an essential aspect of OOP

Anatomy

Object

  • state, attributes, behavior
  • intance of a class
  • represented by an instance in the program

Class

  • defines an abstract data type
  • object references: string variable
  • instance variables : attributes, behaviors, data for objects

Functions

  • methods : the action or behavior of an object
  • constructor : special method for object instantiation, sets the initial values for variables, default constructors have no arguments
  • main : tests the class
  • accesor : allows you to access the values of varaibles, returns a copy of the variable
  • mutator : allows you to change to values of variables

Writing Methods

  • method_definition(Modifiers, Return Type)
  • method_signature(Name, Parameters)
  • method_body(Code)
  • "Object.method()"

Homework : 2021 FRQ 1A, 3a

1a)

public int scoreGuess (String guess)
{
    int count = 0;
    for (int i = 0; i <= secret.length() - guess.length(); i++)
    {
        if (secret.substring(i, i + guess.length()).equals (guess))
        {
            count++;
        }
    }
    return count * guess.length() * guess.length();
}

3a)

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