Requirement

留学生作业代写,网课代修-英国、澳大利亚、北美代写等In this assignment you will write a graphics-based program to do a , 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,即問題,類似布朗運動,物體在下一刻走動的方向完全是隨機的。本題利用隨機數生成器來模擬下一刻的方位。框架使用java的包實現了UI部分,我們只需要將隨機算法加入到提供的框架中。
留学生作业代写,网课代修-英国、澳大利亚、北美代写等解題的關鍵是了解隨機數生成器的用法,根據提供的框架,找到對應函數入口,根據給定的測試集進行調試即可。

Tips

從測試函數入口入手

1
2
3
4
5
private void testTranslate(Impoint loc, int deltaX, int deltaY) {
...
ImPoint p2 = loc.translate(deltaX, deltaY);
...
}

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

1
2
3
4
5
6
7
8
9
10
11
12
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);
}
...
}

19 分類
51 標簽
微信
Essay_Cheery
郵箱
[email protected]

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信