EXERCISE4要求
1. 解压ex4(解压后放到tomcat文件夹下webapps).zip到webapps文件夹下,改名为ex4;
2. 按步骤启动tomcat,并打开CreateFish.html(http://localhost:8080/ex4/CreateFish.html),观察具体功能,如图:
显示如下内容:
不断点击上方的向右箭头,鱼儿会向右移动,并且当运动到一定次数,鱼儿的图片会变化。
3. work目录下有一个Catfish.java文件,这个是我们要完成的文件
4. 按照Catfish.java文件中的提示,完成相应的内容
5. 进行编译,生成Catfish.class文件(cmd命令:Javac Catfish.java)
6. 将你编译好的Catfish.class文件导入到tomcat下的class目录下,替代原来的Catfish.class,重启tomcat,运行CreateFish.html,观察功能是否相同。
7. 本实验只需要提交Catfish.java源码
public class Catfish {
private int column = 1;//Location of the catfish - which column.
private int energyLevel = 10;//Energy level of catfish
private String fileName;
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(){
//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<=10){
column +=1;
energyLevel -=1;
}else{
return;
}
}
/**get the image of catfish
* @return a String indicating the filename of catfish image
*/
// Student: return the image filename that represents the catfish
public String getImage() {
//The image of a tired catfish (a catfish with energyLevel less than 5)
if(energyLevel<5){
//is "CatFish-tired.gif".
fileName = "CatFish-tired.gif";
return fileName;
}else{
// The image of a catfish that is not tired is "CatFish.gif".
fileName = "CatFish.gif";
return fileName;
}
}
}