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

Im having trouble implementing this method: public class PouchCreature implement

ID: 3575539 • Letter: I

Question

Im having trouble implementing this method:

public class PouchCreature implements Battleable {
  
   private String name;
   private int strength;
   private int levelUps;
   private int victoriesSinceLevelUp;

/**
   * Getter for skill level of the PouchCreature, which is based on the
   * first character of its name and the number of levelUps it has.
   * Specifically, the UNICODE value of the first character in its name
   * taken %10 plus the levelUps.

   *
   * @return skill level of the PouchCreature
   */
   public int getLevel() {
       throw new RuntimeException("You must implement this!");
      
   }

Im not sure how to get the value of the first character in the creatures name.

Thank you.

Explanation / Answer

PROGRAM CODE:

public class PouchCreature implements Battleable {
  
   private String name;
   private int strength;
   private int levelUps;
   private int victoriesSinceLevelUp;

/**
   * Getter for skill level of the PouchCreature, which is based on the
   * first character of its name and the number of levelUps it has.
   * Specifically, the UNICODE value of the first character in its name
   * taken %10 plus the levelUps.

   *
   * @return skill level of the PouchCreature
   */
    public int getLevel() {
       char firstChar = name.charAt(0);
return firstChar%10 + levelUps;
//Suppose if you give the names as kevin and levelUps as 2, this code will return 9.
   }

}