Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎

2018-10-19

posted Oct 18, 2018, 4:47 PM by Konstantinovich Samuel   [ updated Oct 22, 2018, 5:40 AM ]
1. Quiz on Objects Tuesday.

2. PTC!
If you would like to be part of the longstanding tradition of parent-teacher conference volunteers (goons) then please email me. We can suffer the long hours together! You can hang out with other volunteers, and hear my ridiculous comments on a variety of things!
 Thursday: 5:15-8pm 
 Friday: 12:45pm - 3pm
    -Subject:  (without the comment)
    PTC Volunteer 2018 FALL (TF)    //If you can come either/both days
    PTC Volunteer 2018 FALL (T)     //if you can come thurs
    PTC Volunteer 2018 FALL (F)     //if you can come friday
    -Body:
     Can you bring a laptop?  yes/no

3. CS College Programs:
If you are interested in learning about the Hunter College Honors CS  program: Daedalus, then fill out a google form

4. You can view all previously assigned coding bat problems here: (so you know what


5. Homework:
a. Coding Bat Problems!  [don't work on them in class]
[My Mistake] Due to the late posting, the deadline is Wednesday, and I have shortened the problem set:


b.UPDATE LABEL ON CODING BAT
    Verify your period and that the format of the label in coding bat is:
    X.LastName.FirstName
    e.g.
        5.Puccini.Giacomo
        9.Nobunaga.Oda
        3.Naguib.Muhammad


Several takeaways from yesterday:

1. Abstract classes cannot be instantiated.

2. Abstract methods are placeholders for future implementation.

3. Abstract methods require that the class is abstract.

4. Method calls always use the most recently overidden method.  (This isn't specific to abstract!)
 e.g.
 toString() calls info(), and shows the subclass description.

5. Concrete methods can call abstract methods. This means that the concrete method must be in an abstract class.
 e.g.
 getName() calls the abstract title() method.


abstract class Player{
  private int health;
  private String name;

  /**constructor*/
  public Player(int hp, String n){
   health = hp;
   name = n;
  }

  public int getHealth(){
   return health;
  }

  public String getName(){
   return title() + name;
  }

  public abstract String title();

  public String toString(){
    return getName() +" ("+ getHealth()+ ")\n" + info();
  }

  public abstract void attack(Player other);

  public String info(){
    return "Error - lazy programmer detected (write a proper description)";
  }
}




public class Mage extends Player{
    //You automatically inherit the accessors yay free methods.
    /**constructor*/
    public Mage(int hp, String n){
     super(hp,n);
    }
    //You MUST implement attack in order for this class to compile.
    public void attack(Player other){
      //Do something
    }

    //You MAY choose to override title + info
    public String title(){
      return "Grand Sage ";

    }

    public String info(){
     return "A manipulator of the cosmos and creator of explosions.";
    }
}
 
public class Barbarian extends Player{
    //You automatically inherit the accessors yay free methods.
    /**constructor*/
    public Barbarian(int hp, String n){
     super(hp,n);
    }
    //You MUST implement attack in order for this class to compile.
    public void attack(Player other){
      //Do something
    }
    //You MAY choose to override title + info
    public String title(){
      return "Destroyer ";
    }

    public String info(){
     return "A warrior that fights with brute strength and pure rage.";
    }
}

public class Driver{
  public static void main(String[] args){
    Barbarian x = new Barbarian(24,"Gronk");
    Mage y = new Mage(24,"Tim");
    Player a = new Barbarian(20,"Conan");
    Player b = new Mage(15,"Merlin");

    System.out.println(x.getName());
    System.out.println(y.getName());
    System.out.println(a.getName());
    System.out.println(b.getName());
    System.out.println("--------------");
    System.out.println(x);
    System.out.println(y);
    System.out.println(a);
    System.out.println(b);

  }

}

Output:
Destroyer Gronk (24)
A warrior that fights with brute strength and pure rage.
Grand Sage Tim (24)
A manipulator of the cosmos and creator of explosions.
Destroyer Conan (20)
A warrior that fights with brute strength and pure rage.
Grand Sage Merlin (15)
A manipulator of the cosmos and creator of explosions.
--------------
Destroyer Gronk
Grand Sage Tim
Destroyer Conan
Grand Sage Merlin




Complete the following publicly available AP question.
I omitted part C because it contains a class you haven't seen yet!
You must get used to the idea that you can use classes without knowing all of the details.

Complete this on paper without discussion. (14 min)
Discuss with neighbors afterwards(5 min)

After we are all done we will go over this.



 



Comments