This site requires JavaScript, please enable it in your browser!
Greenfoot back
bbishal
bbishal wrote ...

2018/3/2

Need help on bacteria wbc4 chapter 5 green foot

bbishal bbishal

2018/3/2

#
2. here are the rules to increase these four instance variables: o when the white blood cell touches a bacteria, increase variable numberOfBacteriaTouched by one o when a bacterial reaches the left edge of the screen without touching the white blood cell, increase variable numberOfBacteriaMissed by one o when the white blood cell touches a virus, increase variable numberOfVirusTouched by one o when a virus reaches the left edge of the screen without touching the white blood cell, increase variable numberOfVirusMissed by one
danpost danpost

2018/3/2

#
Show what you tried.
bbishal bbishal

2018/3/2

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public void setnumberOfBacteriaTouched(int numberOfBacteriaTouched) {
       this.numberOfBacteriaTouched = numberOfBacteriaTouched;
   }
   public int getnumberOfBacteriaTouched(){
       return this.numberOfBacteriaTouched;
   }
   public void numberOfBacteriaMissed(int numberOfBacteriaMissed) {
       this.numberOfBacteriaMissed = numberOfBacteriaMissed;
   }
   public int getnumberOfBacteriaMissed(){
       return this.numberOfBacteriaMissed;
   }
   public void numberOfVirusTouched(int numberOfVirusTouched) {
       this.numberOfVirusTouched = numberOfVirusTouched;
   }
   public int numberOfVirusTouched(){
       return this.numberOfVirusTouched;
   }
   public void numberOfVirusMissed(int numberOfVirusMissed) {
       this.numberOfVirusMissed = numberOfVirusMissed;
   }
   public int numberOfVirusMissed(){
       return this.numberOfVirusMissed;
Note: I just created a getter and setters. So help me to valid the given question please!!! Thank you.
bbishal bbishal

2018/3/2

#
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.
PeterMuller PeterMuller

2018/3/2

#
Greenfoot is trash , it always crash Your tweeter Peter
danpost danpost

2018/3/2

#
I will presume that Bloodstream is your subclass of World. You can use the following line to access it:
1
Bloodstream bloodstream = (Bloodstream)getWorld();
The you can call the methods on 'bloodstream.
You need to login to post a reply.