java卡雷尔机器人代码 卡雷尔机器人程序

跪求大神荣光 回答下面的机器人的JAVA代码

import java.text.DecimalFormat;

10多年专注成都网站制作,成都定制网站,个人网站制作服务,为大家分享网站制作知识、方案,网站设计流程、步骤,成功服务上千家企业。为您提供网站建设,网站制作,网页设计及定制高端网站建设服务,专注于成都定制网站,高端网页制作,对成都集装箱等多个领域,拥有丰富的网站营销经验。

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class WalkDistance {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n = in.nextInt();

for (int i = 0; i n; i++) {

String order = in.next();

System.out.println(new DecimalFormat("0.00").format(calDistance(order)));

}

in.close();

}

private static float calDistance(String order) {

char[] orderChar = order.toCharArray();

ListString orderList = new ArrayListString();

int num = 0;

for (int i = 0, len = orderChar.length; i len; i++) {

if (orderChar[i] = '0' orderChar[i] = '9') {

num++;

} else {

if (num == 0) {

orderList.add(String.valueOf(orderChar[i]));

} else {

StringBuffer sb = new StringBuffer();

for (int j = num; j 0; j--) {

sb.append(String.valueOf(orderChar[i - j]));

}

orderList.add(sb.toString());

orderList.add(String.valueOf(orderChar[i]));

num = 0;

}

}

if (i == len - 1 num != 0) {

StringBuffer sb = new StringBuffer();

for (int j = num - 1; j = 0; j--) {

sb.append(String.valueOf(orderChar[i - j]));

}

orderList.add(sb.toString());

}

}

Point curPoint = new Point(0, 0, 90);

for (int i = 0, len = orderList.size(); i len; i++) {

if ("R".equals(orderList.get(i))) {

curPoint.angle = (curPoint.angle - 90 + 360) % 360;

} else if ("L".equals(orderList.get(i))) {

curPoint.angle = (curPoint.angle + 90) % 360;

} else {

curPoint.setLocation(curPoint, orderList.get(i));

}

}

return curPoint.getDis();

}

static class Point {

private int x;

private int y;

private int angle;

private float dis;

public Point(int x, int y, int angle) {

this.x = x;

this.y = y;

this.angle = angle;

this.dis = (float) 0;

}

public void setLocation(Point point, String distance) {

if (point.angle == 0) {

point.x += Integer.valueOf(distance);

} else if (point.angle == 90) {

point.y += Integer.valueOf(distance);

} else if (point.angle == 180) {

point.x -= Integer.valueOf(distance);

} else {

point.y -= Integer.valueOf(distance);

}

}

public float getDis() {

return (float) Math.sqrt(this.x * this.x + this.y * this.y);

}

}

}

卡雷尔机器人学java的问题

其实卡雷尔你不怎么需要知道他的概念,他只是让你知道什么是程序指令,是帮助你进入JAVA的东西。 ~

下载了卡雷尔机器人,导入eclipse中运行不了!!

运行啊,点击那个奔跑的人形状。不过先要导入Assignment,点击import

projects,选择Assignment路径。慢慢摸索一下,应该可以的。


网站标题:java卡雷尔机器人代码 卡雷尔机器人程序
文章起源:http://ybzwz.com/article/dddcggg.html