catfish.java

来自「ssd1 exercise4 以前做的 希望有帮助」· Java 代码 · 共 44 行

JAVA
44
字号
public class Catfish {

    /** 
     * Location of the catfish - which column.
     */
    private int column = 1;

    /** 
     * Energy level of catfish
     */
    private int energyLevel = 10;

    /**
     * Location of catfish - the column
     * 
     * @return - an integer representing the column location of catfish.
     */
    public int getColumn() {
        return column;
    }

    /**
     * Swim one cell to the right by incrementing the value stored in column by 1.
     */
    public void swimRight() {
        if (column + 1 <= 10) {
          column = column + 1;
          energyLevel = energyLevel - 1;
        }
    }

    /**
     * get the image of catfish
     *
     * @return a String indicating the filename of catfish image
     */
    public String getImage() {
      if (energyLevel < 5) {
        return "/CatFish-tired.gif";
      }
      return "/CatFish.gif";
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?