當前位置:首頁 » 編程軟體 » 鬼兔編程

鬼兔編程

發布時間: 2022-09-07 21:42:51

⑴ JAVA的程序設計,設計一個龜兔賽跑的線程類模擬參與賽跑。

感覺挺有趣的,試著寫了個~

public static void main(String[] arg) {
new wugui().run();
new tuzi().run();
}

static class wugui {
final int su = 4;// 烏龜的速度是每秒4米
public static boolean hasEnd = false;// 是否已經跑到終點
public void run() {
new Thread() {
public void run() {
int distance = 0;
while (distance < 100) {
try {
Thread.sleep(1000);
distance += su;
System.out.println("小烏龜跑了" + distance + "米");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
hasEnd = true;
if (tuzi.hasEnd) {
System.out.println("嗚嗚,差一點點就贏了~");
} else {
System.out.println("勝利是屬於有準備的人的,你的自大害了你!-------烏龜贏了");
}
}
}.start();
}
}

static class tuzi {
final int su = 5;// 兔子的速度是每秒5米
public static boolean hasEnd = false;// 是否已經跑到終點
public void run() {
new Thread() {
@Override
public void run() {
int distance = 0;// 跑了多少米
boolean hasXiuXi = false;// 是否休息過
while (distance < 100) {
try {
Thread.sleep(1000);
distance += su;
System.out.println("小兔子跑了" + distance + "米");
if (distance > 50 && !hasXiuXi) {
System.out.println("小兔子累了,決定休息一會兒~");
Thread.sleep((long) (10000 * Math.random()));
System.out.println("小兔子休息夠了,又開始跑了,決一勝負吧!");
hasXiuXi = true;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
hasEnd = true;
if (wugui.hasEnd) {
System.out.println("嗚嗚,早知道就不休息了~");
} else {
System.out.println("哇哈哈,你個戰5渣也想贏我~~做夢去吧!!-------兔子贏了");
}
}
}.start();
}
}

⑵ Vb程序龜兔賽跑全部步驟

1、定義龜兔兩個類,並設置好相關的屬性(速度,加速度等等)
2、添加兩個timer,在界面上模擬賽跑

⑶ 在Linux下的C語言編程

開一個線程表示龜
再開一個表示兔
龜每次增加3-8隨機數米然後休眠0.9999秒
兔每次增加5米,然後休眠0.9999秒
判斷當前龜或者兔哪個數字大於等於終點, 有則結束2個線程,並提示

⑷ Java編程 1、編寫「龜兔賽跑」模擬程序,界面設計參考下圖。

說的這么清除了就自己做啊,就是線程而已,除非你還要美工

⑸ JAVA編程題龜兔賽跑

class Animal {
public double speed;

public void run(int length) {
System.out.println(length/this.speed);
}
}
class Rabbit extends Animal {
Rabbit(int speed) {
super.speed = speed;
}
@Override
public void run(int length) {
System.out.println("Rabbit time = "+length/this.speed +" seconds");
}

}
class Tortoise extends Animal {
Tortoise(int speed) {
super.speed = speed;
}

@Override
public void run(int length) {
System.out.println("Tortoise time = "+length/this.speed +" seconds");
}
}
public class Match {
public static int length = 100;

private static void begin(Rabbit r,Tortoise t) {
r.run(length);
t.run(length);
}

public static void main(String[] args) {
Rabbit r = new Rabbit(20);
Tortoise t = new Tortoise(5);
begin(r,t);
}
}

⑹ c++編程 龜兔賽跑

我感覺這個題目有問題,兔子在休息 30min 的期間也 在 10 分鍾的時候 看一下烏龜的位置嗎?我對這個問題 很有興趣,你說一下我回去幫你寫。

熱點內容
編程知識卡片 發布:2025-03-22 05:40:40 瀏覽:371
搭建的網站伺服器連接失敗 發布:2025-03-22 05:39:08 瀏覽:592
浪潮的伺服器地址 發布:2025-03-22 05:37:30 瀏覽:409
凱撒加密在線 發布:2025-03-22 05:36:45 瀏覽:655
空調壓縮機銘牌含義 發布:2025-03-22 05:27:03 瀏覽:61
編程強省 發布:2025-03-22 05:26:21 瀏覽:142
跨雲伺服器平台 發布:2025-03-22 05:25:30 瀏覽:654
安卓如何在寶馬車上放歌 發布:2025-03-22 05:06:15 瀏覽:284
命令提示符進入文件夾 發布:2025-03-22 05:00:09 瀏覽:408
免費微商城源碼 發布:2025-03-22 04:40:25 瀏覽:826