首页 \ 问答 \ 并发编程。(Concurrent Programming. Using Karel the Robot)

并发编程。(Concurrent Programming. Using Karel the Robot)

我在计算机科学课上,我们已经开始使用Karel the Robot作为Java OOP的入门。 我想同时运行两个Karel the Robots,执行两个不同的任务。 我曾尝试在互联网上查找解决方案,并且我已经成功地制作了一个工作线程,但是,我无法同时运行两个Karel the Robots。 任何有关此并发编程问题的帮助将不胜感激。 这是我一直在使用的代码:

package karel;
import kareltherobot.*;
import kareltherobot.Directions;
import kareltherobot.World;
public class KarelSample implements Directions
{
    public static void main(String [] args)  
    {


          Thread Karelrunner = new Thread();
          Karelrunner.start();
 UrRobot Karel = new UrRobot ( 1,5, North, 2);
 Karel.move();
 Karel.move();
 Karel.putBeeper();
 Karel.turnLeft();
 Karel.move();


}




    static
    {   
    World.setVisible(true);
    World.showSpeedControl(true);



}


    class Karelrunner implements Directions {

        UrRobot Karel2 = new UrRobot(8,8, South, 2);
        Karel2.move();
        Karel2.move();
        Karel2.turnLeft();
        Karel2.turnLeft();
        Karel2.putBeeper();
        Karel2.move();
}



}

我还使用了Karel J Robot书籍的例子,其中线程设置代码如下:

public static void main (String [] args)
{ ...

Karelrunner r = new Karelrunner();
World.setupThread(r);

  . . .
}

请以任何方式帮助,我正在尝试制作一个多线程并发程序。 我是新手,感谢您的时间和关注。


I am in a computer Science class and we have started with using Karel the Robot as the introduction to Java OOP. I want to run two Karel the Robots at the same time, performing two different tasks. I have tried looking up solutions on the internet, and I have been successful in making a working thread, however, I am unable to run two Karel the Robots at the same time. Any help on this Concurrent Programming issue would be appreciated. Here's the code I have been using:

package karel;
import kareltherobot.*;
import kareltherobot.Directions;
import kareltherobot.World;
public class KarelSample implements Directions
{
    public static void main(String [] args)  
    {


          Thread Karelrunner = new Thread();
          Karelrunner.start();
 UrRobot Karel = new UrRobot ( 1,5, North, 2);
 Karel.move();
 Karel.move();
 Karel.putBeeper();
 Karel.turnLeft();
 Karel.move();


}




    static
    {   
    World.setVisible(true);
    World.showSpeedControl(true);



}


    class Karelrunner implements Directions {

        UrRobot Karel2 = new UrRobot(8,8, South, 2);
        Karel2.move();
        Karel2.move();
        Karel2.turnLeft();
        Karel2.turnLeft();
        Karel2.putBeeper();
        Karel2.move();
}



}

I have also used the Karel J Robot book's example where the thread setup code would be as follows:

public static void main (String [] args)
{ ...

Karelrunner r = new Karelrunner();
World.setupThread(r);

  . . .
}

Please help in any way you can, I am trying to make a multi-threaded concurrent program. I am new to this and thanks for your time and attention.


原文:https://stackoverflow.com/questions/12232922
更新时间:2024-03-10 15:03

相关问答

更多
  • 优化。 最长的时间,有必要手工完成。 现在大多数编译器可以比任何人都做得更好。 注意:这并不是说手部优化还没有完成,正如评论中指出的那样。 我只是说, 过去手动完成的许多优化现在都是自动完成的 。 Optimizations. For the longest time, it was necessary to do this by hand. Now most compilers can do it infinitely better than any human ever could. Note: Thi ...
  • 在功能性编程方面,基本概念是什么是社区共识。 在为什么功能编程重要(PDF)中 ,John Hughes认为它们是高阶函数和懒惰评估。 佩戴发衬衫:回顾Haskell ,Simon Peyton Jones说,真正的本质不是懒惰而是纯洁。 理查德·伯德会同意。 但是,有一大堆的Scheme和ML程序员很乐意用程序编写副作用。 作为二十年来实践和教授功能编程的人,我可以给你一些被认为是功能编程核心的想法: 核心是嵌套的,具有适当词汇范围的一级函数 。 这意味着您可以在运行时创建一个匿名函数,其空闲变量可能是封 ...
  • 这个问题的答案取决于你想要学习的内容。 Python和Ruby 通常建议像Python和Ruby这样的高级语言,因为它们是高级的,语法很可读。 然而,这些语言都有针对公共数据结构的抽象。 没有什么可以阻止您实现自己的版本作为学习练习,但是您可能会发现,在其他高级数据结构之上构建高级数据结构,这不一定有用。 此外,Ruby和Python是动态类型语言。 这可能是好的,但也可能让初学者感到困惑,因为它们通常在运行时通常不会显现,因此可能更难(最初)捕获错误。 C C在另一个极端。 如果您想要学习真正的低级细节, ...
  • 既然你问了关于书的具体问题,我会建议O'Reilly的Access Cookbook 。 我发现这对于Access VBA的中间级别方法很有用。 除书籍以外,我获得的最大收益是参与microsoft.public.access新闻组。 它让我有机会研究许多真正的Access专家的方法。 当我回答问题时,我可以从他们的评论中受益。 Since you asked specifically about books, I'll suggest O'Reilly's Access Cookbook. I found ...
  • 这看起来像一个很好和简单的例子: http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming#Example 从维基百科文章复制的示例: class Animal: def __init__(self, name): # Constructor of the class self.name = name def talk(self): # Abstract m ...
  • 好! 四个问题:) 1)OpenGL和DirectX都很好。 OpenGL正确地跨平台,并在手机上工作。 DirectX提供了一些高级功能,但你也可以做一个工作。 2)Maya和3ds都是3D工具。 你可以使用它们,但你也可以使用2D的东西,尤其是手机游戏。 3)首先要看的是这里 。 快速介绍,向您展示2D形状的动画。 给你所有的基础知识,无论你是做2D还是3D开发,它都会适用。 显然,从3D开始是困难的,因为你需要知道更多的触发。 4)免费的3D游戏引擎是Quake引擎( 这里 ),它足够简单,可以掌握, ...
  • 我没有读过这本书,但是我很难相信他们写了一本书,“其基础......面向对象编程是非常浪费记忆的”(完全披露:安迪和芭芭拉是我的朋友)。 安迪永远不会说OOP会浪费内存。 他会说某种特定的算法或技术是浪费的,并且在某些情况下可能会建议采用较少的OO方法,但是,他会首先争辩说,作为一般规则,OO设计不会浪费任何其他风格。节目。 面向对象设计浪费的论点很大程度上来自于C ++“hello world”程序的EXE往往比C“hello world”程序的EXE更大。 这主要是因为iostreams大于printf ...
  • 任何设计良好的应用程序都可以使用任何或所有这些概念。 特定于语言的书籍倾向于专注于语言细节(出于正当理由),并且通常忽视基本的设计原则。 另一个重要的观点是代表,泛型,反思等都有自己的位置,但不应该仅仅因为“因为”而在应用程序中实现。 这会造成不必要的复杂性。 所有这些都说,选择一个你感兴趣的项目。 更好的是,你真的想要使用的东西。 然后,在编码之前,考虑如何构建应用程序,以便稍后修改和添加功能。 如果你将所有的代码放在窗体/代码隐藏页面中,那么你可能做错了什么。 花一些时间学习设计模式 。 这些是组织随着 ...
  • 好吧,我应该说我可以很好地处理它。 我花了很多时间论坛的例子: http://www.vbaexpress.com/forum/ http://www.mrexcel.com/ http://www.excelforum.com/excel-programming-vba-macros/ 这是一些书籍清单: http://www.mrexcel.com/articles.shtml http://www.datapigtechnologies.com/ExcelMain.htm http://dmcritc ...
  • 有面向对象的内核。 实际上,至少有两个用C#编写的内核(这些项目称为奇点和宇宙)。 虽然从技术上来说它不是性能问题,因为你可以编写非常快速和高效的面向对象的代码,但通常需要花费更多的精力在面向对象的语言中编写高效的代码(即,oop语言通常使得编写非常容易代码效率不高)。 更重要的是,oop的各种功能通常对内核编程没有多大帮助,因为你必须编写非常低级的代码,这些代码可以摆弄位或专门使用寄存器。 这也是人们不会用其他高级语言编写操作系统的原因相同... oop与否。 C只是编写内核的一种非常有效的语言。如果没有 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。