最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
奉化市| 军事| 玛沁县| 永丰县| 原阳县| 从化市| 布拖县| 延庆县| 丰原市| 浪卡子县| 昭苏县| 西和县| 罗城| 花莲县| 嘉黎县| 项城市| 建德市| 墨江| 疏勒县| 岑溪市| 肥西县| 寿阳县| 堆龙德庆县| 昔阳县| 罗源县| 收藏| 蒲江县| 抚远县| 镇安县| 吉水县| 张家界市| 武定县| 宁海县| 石台县| 临沧市| 公主岭市| 蒲城县| 阿城市| 西乌珠穆沁旗| 博白县| 淳化县|