Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A game app involves players modeled as creatures by the Creature class: public c

ID: 647917 • Letter: A

Question

A game app involves players modeled as creatures by the Creature class:


public class Creature{
    private String name;
    private int lifeLevel;

  public Creature(String name, int level){
    this.name=name;
    lifeLevel=level;
  }
  public String getName(){
    return name;
  }
  public int getLifeLevel(){
    return lifeLevel;
  }
  public void changeLifeLevel(int amt){
     lifeLevel+=amt;
  }
  public String toString(){
    return(name + " " + lifeLevel);
  }
}


Write a method for the Creature class called showTheDead, which takes an array ofCreature objects as a parameter, and which does not return a value but prints to the screen the names of all creatures that are dead. A Creature is dead if its life level is less than or equal to zero.

Enter your code for the showTheDead method below.

Explanation / Answer


public void showTheDead(Creature[] creatures)
{
   for(int i=0;i<creatures.length;i++)
   {
       if(creatures[i].lifeLevel<=0)
       {
           System.out.println(creatures[i].getName());
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote