📄 catfish.java
字号:
/**
* @author A JiaYi
* @version 1.0.0
* <p>Date:2005-4-28</P>
* <p>This class is designed to move a catfish to the right, one cell at a time.
* A new catfish starts off with some amount of energy and expends some energy every time it moves.
* If the catfish's energy falls below a certain threshold, it will appear tired.
* Otherwise, it will appear normal.
* Note that the catfish should stay within the boundary of the lake. </P>
*/
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() {
// Student: return the column value
return column;
}
/**
* Swim one cell to the right by incrementing the value stored in column by 1.
*/
public void swimRight() {
// Student: Increment the value stored in column attribute by 1 and
// decrement the value stored in energyLevel by 1 if the
// new value of column is less than or equal to 10.
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() {
// Student: return the image filename that represents the catfish
// The image of a tired catfish (a catfish with energyLevel less than 5)
// is "/CatFish-tired.gif".
// The iamge of a catfish that is not tired is "/CatFish.gif".
String imageFileName;
if (energyLevel < 5)
return imageFileName = "/CatFish-tired.gif";
else
return imageFileName = "/CatFish.gif";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -