国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Java程序設(shè)計(jì)上機(jī)實(shí)驗(yàn)

2022-10-26 19:51 作者:沐笙--ms  | 我要投稿


編寫(xiě)一個(gè)Java應(yīng)用程序,該程序中有兩個(gè)類(lèi):Tank (用于刻畫(huà)坦克)和Fight(主類(lèi))。要求如下。

(1) Tank 類(lèi)有一個(gè) double 類(lèi)型的變量 speed,用于刻畫(huà)坦克的速度,一個(gè) int 型bulletAmount,用于刻畫(huà)坦克的炮彈數(shù)量。在Tank類(lèi)中定義speedUp()和speedDown()方法體現(xiàn)坦克有加速、減速行為,定義setBulleAmount(int p)方法,用于設(shè)置坦克炮彈的數(shù)量,fire()方法,體現(xiàn)坦克有開(kāi)炮行為。

(2) 在主類(lèi)Fight的main方法中用Tank 類(lèi)創(chuàng)建兩輛坦克,并讓坦克調(diào)用方法設(shè)置炮彈的數(shù)量,顯示坦克的加速、減速和開(kāi)炮行為。新增(速度不能超過(guò)220,還有剎車(chē))自己的理解。


import?java.util.Random;

?

public?class?Fight {

?

public?static?void?main(String[] args) {

Tank tank1,tank2;

tank1=new?Tank();

tank2=new?Tank();

Random rd=new?Random();

int?s=rd.nextInt(220)+1; ?//定義tank1最大速度220

int?d=rd.nextInt(220)+1; ?//定義tank2最大速度220

tank1.setBulletAmount(10);

tank2.setBulletAmount(10);

System.out.println("tank1的炮彈數(shù)量:"+tank1.getBulletAmount());

System.out.println("tank2的炮彈數(shù)量:"+tank2.getBulletAmount());

tank1.speedUp(s);

tank2.speedUp(d);

System.out.println("tank1的目前速度:"+tank1.getSpeed());

System.out.println("tank2的目前速度:"+tank2.getSpeed());

tank1.speedDown(10);

tank2.speedDown(15);

System.out.println("tank1減速目前速度:"+tank1.getSpeed());

System.out.println("tank2減速目前速度:"+tank2.getSpeed());

System.out.println("tank1開(kāi)火:");

tank1.fire();

System.out.println("tank2開(kāi)火:");

tank2.fire();

tank2.fire();

tank1.speedDown(220); ?//讓tank1速度為0

tank2.speedDown(220); ?//讓tank2速度為0

System.out.println("tank1剎車(chē)目前速度:"+tank1.getSpeed());

System.out.println("tank2剎車(chē)目前速度:"+tank2.getSpeed());

System.out.println("tank1的炮彈數(shù)量:"+tank1.getBulletAmount());

System.out.println("tank2的炮彈數(shù)量:"+tank2.getBulletAmount());


}

?

}

?

public?class?Tank {

?double?speed; ?//聲明double型變量speed

?????int?bulletAmount;

???void?speedUp(double?s){

???speed=s+speed;

???}

???void?speedDown(int?d){

???if(speed-d>=0)

????????speed=speed-d;

???else

???speed=0;

???}

???void?setBulletAmount(int?m){

???bulletAmount=m;

???}

???int?getBulletAmount(){

???return?bulletAmount;

???}

???double?getSpeed(){

???return?speed;

???}

?????void?fire(){

?? ???if(bulletAmount>=1){

?? ????bulletAmount=bulletAmount-1;

?? ????System.out.println("打出一發(fā)炮彈");

?? ???}

?? ???else{

?? ????System.out.println("沒(méi)有炮彈了,無(wú)法開(kāi)火!");

?? ???}

?????}

?

}


Java程序設(shè)計(jì)上機(jī)實(shí)驗(yàn)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
诏安县| 上杭县| 白水县| 花莲市| 山东省| 兴安县| 吴堡县| 久治县| 汝城县| 钟山县| 苍溪县| 筠连县| 胶南市| 玉林市| 普宁市| 赤壁市| 武城县| 建阳市| 长葛市| 浦城县| 胶州市| 淮安市| 南陵县| 镶黄旗| 阳曲县| 安塞县| 新化县| 昆山市| 怀柔区| 加查县| 驻马店市| 铁力市| 肃南| 苍溪县| 株洲市| 寿阳县| 天全县| 启东市| 恭城| 嘉禾县| 丰都县|