第二次实验Java:Task4

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;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DoorBreaker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值