Question
Based on the existing Greenfoot scenario WBC-4, you need to make the following changes: in class Bloodstream, add the definition of four private instance variables,
Based on the existing Greenfoot scenario WBC-4, you need to make the following changes:
in class Bloodstream, add the definition of four private instance variables, and their names are: numberOfBacteriaTouched, numberOfBacteriaMissed, numberOfVirusTouched , numberOfVirusMissed, respectively. Provide a public getter and setter for each variable.
here are the rules to increase these four instance variables:
when the white blood cell touches a bacteria, increase variable numberOfBacteriaTouched by one
when a bacterial reaches the left edge of the screen without touching the white blood cell, increase variable numberOfBacteriaMissed by one
when the white blood cell touches a virus, increase variable numberOfVirusTouched by one
when a virus reaches the left edge of the screen without touching the white blood cell, increase variable numberOfVirusMissed by one
How to increase any of the above variables by one?
Hint: first, you can use the public getter to obtain the current value of the variable, and then increase this value by one, and then use the public setter to set this increased value back to the variable. And that is why we provide each variable with a public setter and getter in step 1 above. In order to call the public getter and setter, you need to first obtain an instance (handler) of the class Bloodstream.
show the name and the values of the above four variables at the lower left corner of the screen using four lines of text. The sequence of the text follows the sequence shown in the requirement above.
change the way how score is calculated, and here is how to calculate the score under 4 conditions:
when the white blood cell touches a bacteria, increase the score by 1.
when a bacterial reaches the left edge of the screen without touching the white blood cell, decrease the score by 1.
when a white blood cell touches a virus, decrease the score by 2
when a virus reaches the left edge of the screen without touching the white blood cell, increase the score by 2
You should still invoke the addScore method to change score, and the actual parameter plugged in for the addScore method must follow the rules defined above on how to calculate the score. For example, you can plug in 1, or -1, or -2, or 2 as the actual parameters for the four conditions defined above, respectively. You cannot modify the signature of addScore method, which means that the addScore method can only take one formal parameter.
The places that you need to invoke the addScore method are:
in class WhiteCell, when the white blood cell touches a bacteria
in class Bacterial, when a bacterial reaches the left edge of the screen without touching the white blood cell
in class WhiteCell, when the white blood cell touches a virus
in class Virus, when a virus reaches the left edge of the screen without touching the white blood cell
in class Bloodstream, inside the implementation of the addScore method, the game stops when score is less than zero, and the code for this requirement is already in scenario WBC-4, thus no need for any code change. When the timer times out, you also need to show the final score, and the code for this requirement is already in scenario WBC-4, thus no need for any code change.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started