Section 5.1 viruses floating across the screen from right to left. One white blood cell on the screen

Exercise 5.2:

WhiteCell: represents a white blood cell that catches bacteria.

Bacteria: represents bad bacteria in the blood – we want to destroy them

Lining: the images at the top and bottom edge of the world. Represents cell walls.

Section 5.2 Exercise 5.4 a) void setLocation(int x, int y) b) int getX() c) int getY()

Difference between public and private: Private access is usually reserved for internal data and methods. That is those methods you don’t want users to have direct access to. Public access allows users to access the functionality of the class. The functionality of the class basically is the methods you have public access to. So public access is what makes the methods usable in many implementations. See page 83.

Section 5.3

You can tell if the virus is at the left edge of the screen if the x coordinate = zero

The ‘this’ refers to the current object acting or executing at that moment or it refers to the current bacteria

To chain together method calls you use the ‘dot’ operator. Example: getWorld().removeObject (this) chains together the getWorld() method and the removeObject() method.

Section 5.4 addObject(new Bacteria(), 779, Greenfoot.getRandomNumber(180) + 180);

Section 5.5 and code added to Bloodstream act()

Section 5.6 Exercises: 5.9 to 5.12 New Virus class

Scoring in the WhiteCell class is not ideal for what reason(s): it decreases its functionality. You can only add a score or use a score if it is a WhiteCell.

What class should the score variable be moved to bloodstream

Section 5.7 Exercises: 5.13 to 5. 17. CheckCollison removes bacteria and viruses Section 5.8 Exercises: 5.18 – 5.20 Added or changed Bacteria private int speed; public Bacteria() { speed = Greenfoot.getRandomNumber(3) + 1; } setLocation(getX()-speed, getY());

Section 5.9 Exercises: 5.21 to 5.24 RedCell class

add to BloodStream act()

Section 5.10 Exercises: 5.25 – 5.29 In BloodStream’s prepare() add… Border border = new Border(); addObject(border, 0, 180); Border border2 = new Border(); addObject(border2, 770, 180);

In WhiteCell add tocheckKeyPress()

Section 5.11 Exercises: 5.30 to 5.37

In WhiteCell class add : private int score; // instance field and the score code to checkCollision();

5.37: adds variety by speeding up bacteria between 1 and 5, whiteCell speed 4 for left right, 8 for up down, Viruses speed 8, etc…. Students will be creative.

Section 5.12 Exercises: 5.38 – 5.41 Score should be moved to the BloodStream class private int score; // instance field added to Bloodstream score = 0; // initialize score to zero in the constructor add the following addScore() method to Bloodstream class including comments.

Section 5.13 Exercises 5.42 – 5. 50 Explain how rewriting the addScore() method to include a parameter makes it better. Modularity makes code RRAD is a mneumonic for remembering why we modularize code; We modularize to make code reusable, more reliable, abstract (able to apply to a variety of applications) and the ability to Divide and Conquer(break up the work between team members) Using a parameter to the addScore method makes it more useable in a variety of contexts and thus is an ideal example of abstraction. It also makes the code more versatile and reusable.

Error received if you try to call an object that has been removed: NullPointerException error

WhiteCell Code BloodStream code with addScore() and showScore()

Section 5.13 Exercises: 5.51 – 5.56 Bloodstream code private int time;