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

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

Java代碼編寫:CS455 Random Walk

2022-10-25 15:20 作者:拓端tecdat  | 我要投稿

全文鏈接:tecdat.cn/?p=29602

Requirement

In this assignment you will write a graphics-based program to do a?random walk, sometimes also known as a drunkard’s walk. This random walk simulates the wandering of an intoxicated person on a square street grid. The drunkard will start out in the middle of the grid and will randomly pick one of the four compass directions, and take a step in that direction, then another step from that new location in a random direction, etc.

This assignment will give you practice with creating classes, using loops, using the java library for random number generation, doing console-based IO, and drawing to a graphics window. Also you’ll get practice in general program development.

Analysis

Randow Walk,即隨機(jī)游走問題,類似布朗運動,物體在下一刻走動的方向完全是隨機(jī)的。本題利用隨機(jī)數(shù)生成器來模擬下一刻的方位。框架使用java的awt包實現(xiàn)了UI部分,我們只需要將隨機(jī)算法加入到提供的框架中。
解題的關(guān)鍵是了解隨機(jī)數(shù)生成器的用法,根據(jù)提供的框架,找到對應(yīng)函數(shù)入口,根據(jù)給定的測試集進(jìn)行調(diào)試即可。

Tips

從測試函數(shù)入口入手

private void testTranslate(Impoint loc, int deltaX, int deltaY) { ? ... ? ImPoint p2 = loc.translate(deltaX, deltaY); ? ... } 復(fù)制代碼

因此我們需要實現(xiàn)ImPoint類,以及translate方法,核心代碼如下

class ImPoint { ? private int x; ? private int y; ? ... ? public Impoint translate(int deltaX, int deltaY) { ? ? Random r = new Random(); ? ? int x = deltaX + nextInt(2) - 1; ? ? int y = deltaY + nextInt(2) - 1; ? ? return new Impoint(x, y); ? } ? ... }


Java代碼編寫:CS455 Random Walk的評論 (共 條)

分享到微博請遵守國家法律
新安县| 凌海市| 信丰县| 乌什县| 博罗县| 喜德县| 西畴县| 丰县| 德化县| 石楼县| 叶城县| 汉源县| 武城县| 嘉峪关市| 缙云县| 丽水市| 克什克腾旗| 阿拉善盟| 南木林县| 阳新县| 乌鲁木齐县| 宜宾县| 蕉岭县| 长垣县| 阿拉善盟| 昌图县| 汽车| 都昌县| 若羌县| 孝感市| 昌邑市| 黄龙县| 六安市| 潼南县| 花莲市| 老河口市| 平利县| 大同县| 望都县| 小金县| 丰镇市|