您的位置:首页 > 其它

新年到了,祝大家新年快乐,礼物就送SSD1的部分答案哦

2007-12-31 19:57 761 查看
把SSD1的答案贴上来(SSDx 的答案将会后续连载)作为给各位学弟学妹的新年礼物,新年快乐咯
先来一篇exercise4的答案
(声明:不许转载)

Catfish.java
/**
* Author:
* Date: 2007/04/25
* Description: Practical Quiz 5
*
*/
public class Catfish {

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

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

/**
* Image of the catfish - is really a filename.
*/
private String imageFileName;

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

return column; // return the column value
}

/**
* 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; // Increment the value stored in column attribute by 1 and
energyLevel = energyLevel - 1;// decrement the value stored in energyLevel by 1 if the
// new value of column is less than or equal to 10.
}

}

/**
* get the image of catfish
*
* @return a String indicating the filename of catfish image
*/
public String getImage() {

if (energyLevel >= 5)
{
imageFileName = "/Catfish.gif"; // The iamge of a catfish that is not tired is "/CatFish.gif".
}
else
{
imageFileName = "/Catfish-tired.gif"; // The image of a tired catfish (a catfish with energyLevel less than 5)
// is "/CatFish-tired.gif".
}
return imageFileName; // return the image filename that represents the catfish
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: