Complete the ZombiePlant practice problem before reviewing the solution.
Review the ZombiePlant
solution with AP CS Tutor Brandon Horn.
public class ZombiePlant
{
private final int maxPotency;
private int treatmentsNeeded;
public ZombiePlant(int max, int needed)
{
maxPotency = max;
treatmentsNeeded = needed;
}
public int treatmentsNeeded()
{
return treatmentsNeeded;
}
public void treat(int potency)
{
if(potency > maxPotency)
{
treatmentsNeeded++;
}
else
{
if(treatmentsNeeded > 0)
treatmentsNeeded--;
}
}
public boolean isDangerous()
{
return treatmentsNeeded > 0;
}
}
Additional classes & objects resources
- Constructing objects
- Class writing order
- Primitive types vs references exercises
- Primitive types vs references exercises with calls
Help & comments
Get help from AP CS Tutor Brandon Horn