Whitecell: Represents a White Blood Cell That Catches Bacteria

Whitecell: Represents a White Blood Cell That Catches Bacteria

<p>Section 5.1 viruses floating across the screen from right to left. One white blood cell on the screen </p><p>Exercise 5.2: </p><p>WhiteCell: represents a white blood cell that catches bacteria. </p><p>Bacteria: represents bad bacteria in the blood – we want to destroy them</p><p>Lining: the images at the top and bottom edge of the world. Represents cell walls.</p><p>Section 5.2 Exercise 5.4 a) void setLocation(int x, int y) b) int getX() c) int getY()</p><p>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. </p><p>Section 5.3</p><p>You can tell if the virus is at the left edge of the screen if the x coordinate = zero </p><p>The ‘this’ refers to the current object acting or executing at that moment or it refers to the current bacteria </p><p>To chain together method calls you use the ‘dot’ operator. Example: getWorld().removeObject (this) chains together the getWorld() method and the removeObject() method. </p><p>Section 5.4 addObject(new Bacteria(), 779, Greenfoot.getRandomNumber(180) + 180); </p><p>Section 5.5 and code added to Bloodstream act()</p><p>Section 5.6 Exercises: 5.9 to 5.12 New Virus class </p><p>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. </p><p>What class should the score variable be moved to bloodstream </p><p>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());</p><p>Section 5.9 Exercises: 5.21 to 5.24 RedCell class </p><p> add to BloodStream act() </p><p>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);</p><p>In WhiteCell add tocheckKeyPress() </p><p>Section 5.11 Exercises: 5.30 to 5.37 </p><p>In WhiteCell class add : private int score; // instance field and the score code to checkCollision();</p><p>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. </p><p>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.</p><p>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. </p><p>Error received if you try to call an object that has been removed: NullPointerException error </p><p>WhiteCell Code BloodStream code with addScore() and showScore()</p><p>Section 5.13 Exercises: 5.51 – 5.56 Bloodstream code private int time;</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us