24小时热门版块排行榜    

查看: 789  |  回复: 1

water11

金虫 (正式写手)

[求助] Java程序没有错误,但不显示结果,求指点。 已有1人参与

java程序运行(环境Eclipse)时没有提示错误, 但是不显示结果,不明所以,请大家帮帮忙,非常感谢。

Person.java代码如下:
public class Person {
        private boolean IsConsuming;
        private boolean IsConcerned;
        private int LastTimeChangeConcernedFromConsumingToNonConsuming;
        private ContinuousSpace <Object> mySpace; // handle for the space
       
        public Person(ContinuousSpace <Object> space, boolean consuming, boolean concerned){
                IsConsuming=consuming;
                IsConcerned=concerned;
                mySpace = space;
                LastTimeChangeConcernedFromConsumingToNonConsuming = 0;
        }       
        @ScheduledMethod (start=1, interval=1 )
        public void step () {
                LastTimeChangeConcernedFromConsumingToNonConsuming++;
        }       
        private void NonConcernedChangeFromConsumingToNonConsuming () {
                if (IsConcerned == false) {
                        double rnd = RandomHelper.nextDouble();
                        if (rnd < 0.1) {
                                IsConsuming = !IsConsuming;
                        }
                }               
        }
        private void ConsumingChangeFromNonConcernedToConcerned () {
                if (IsConcerned == false) {
                        Context <Object> context = ContextUtils.getContext(this);
                        Network <Object> net = (Network<Object> context.getProjection ("communication";
                               
                        Iterable<Object> neighbours = net.getAdjacent(this);
                        for (Object obj : neighbours) {
                                boolean neighbourConcernStatus = ((Person) obj).GetConcernStatus();
                                if (neighbourConcernStatus == true)  {
                                        IsConcerned = true;       
                                }
                        }
                }
        }
        private void ConcernedChangeFromConsumingToConsuming () {
                if ((IsConcerned == true) && (IsConsuming == true)) {
                        Context <Object> context = ContextUtils.getContext(this);
                        Network <Object> net = (Network<Object> context.getProjection ("communication";
                       
                        int number_of_neighbours = 0;
                        int number_of_noncons = 0;
                        Iterable<Object> neighbours = net.getAdjacent(this);
                        for (Object obj : neighbours) {
                                number_of_neighbours++;
                                boolean neighbourConsumingStatus = ((Person) obj).GetConsumingStatus();
                                if (neighbourConsumingStatus == false)  {
                                        number_of_noncons++;
                                }
                        }
                        if (number_of_noncons == number_of_neighbours) {
                                IsConsuming = false;
                                LastTimeChangeConcernedFromConsumingToNonConsuming = 0;
                        }
                }
        }       
        private void NonConsumingChangeFromConcernedToNonConcerned () {
                if ((IsConcerned == true) && (IsConsuming ==false) && (LastTimeChangeConcernedFromConsumingToNonConsuming > 20)) {
                        IsConcerned = false;
                }
        }
        public boolean GetConcernStatus() {
                return IsConcerned;
        }
        public boolean GetConsumingStatus() {
                return IsConsuming;
        }
}
MyStyle.java代码如下:
public class MyStyle extends DefaultStyleOGL2D {
        @Override
        public Color getColor(Object obj) {
                if (obj instanceof Person) {
                        Person agent = (Person) obj;
                        if (agent.GetConsumingStatus() == true) {
                                return Color.BLUE;
                        }
                        else {
                                return Color.RED;
                        }
                }
                else {
                        return null;
                }
        }
        @Override
        public VSpatial getVSpatial(Object obj, VSpatial shape) {
                if (obj instanceof Person) {
                        Person agent = (Person) obj;
                        if (agent.GetConcernStatus() == true) { // consuming
                                return shapeFactory.createRectangle(10, 10); // cubic
                        }
                        else {
                                return shapeFactory.createCircle(3, 10);
                        }
                }
                else {
                        return null;
                }
        }
}
MyContextBuilder.java代码如下:
public class MyContextBuilder implements ContextBuilder<Object> {
        public Context build(Context<Object> context) {               
                ContinuousSpaceFactory spaceFactory = ContinuousSpaceFactoryFinder.createContinuousSpaceFactory(null);
                ContinuousSpace <Object> space = spaceFactory.createContinuousSpace ("space", context, new SimpleCartesianAdder<Object>(),
                        new repast.simphony.space.continuous.WrapAroundBorders(), new double[]{1, 1});
               
                for (int i=1; i<=3; i++){
                        Person p = new Person(space, true, true);
                        context.add(p);
                }
                for (int i=1; i<=3; i++){
                        Person p = new Person(space, true, false);
                        context.add(p);
                }
                for (int i=1; i<=47; i++){
                        Person p = new Person(space, true, false);
                        context.add(p);
                }
                for (int i=1; i<=47; i++){
                        Person p = new Person(space, false, false);
                        context.add(p);
                }               
                // create network projection
                NetworkBuilder <Object> netBuilder = new NetworkBuilder<Object>("communication", context, false);
               
                NetworkGenerator gen;
                gen = new WattsBetaSmallWorldGenerator(0.25, 8, false); // prob connected, degree, symmetrical = false
                netBuilder.setGenerator(gen);
                netBuilder.buildNetwork();

                RunEnvironment.getInstance().endAt(1000);
                return context;
        }
}
回复此楼
已阅   关注TA 给TA发消息 送TA红花 TA的回帖

erghper

铜虫 (小有名气)

【答案】应助回帖

你给的代码看不出啥问题,我觉得关键是你要根据Java运行机制,一步一步去排除错误,比如你要调用某个方法,你最好在这个方法里面打印一下,程序是不是进入了这个方法等等
2楼2014-11-18 09:13:48
已阅   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 water11 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 285化工学硕求调剂(081700) +11 柴郡猫_ 2026-03-12 11/550 2026-03-19 09:37 by laoshidan
[基金申请] 国自科面上基金字体 +7 iwuli 2026-03-12 8/400 2026-03-19 08:55 by sjtu2012
[考研] 0703化学调剂 +8 妮妮ninicgb 2026-03-15 12/600 2026-03-19 05:55 by anny19840123
[考研] 0703化学调剂,求各位老师收留 +10 秋有木北 2026-03-14 10/500 2026-03-19 05:52 by anny19840123
[考研] 一志愿吉林大学材料学硕321求调剂 +4 Ymlll 2026-03-18 6/300 2026-03-18 22:15 by li123456789.
[考研] 一志愿中海洋材料工程专硕330分求调剂 +5 小材化本科 2026-03-18 5/250 2026-03-18 21:53 by 无懈可击111
[考研] 26调剂/材料/英一数二/总分289/已过A区线 +7 步川酷紫123 2026-03-13 7/350 2026-03-18 17:12 by 尽舜尧1
[考研] 288求调剂,一志愿华南理工大学071005 +4 ioodiiij 2026-03-17 4/200 2026-03-18 12:36 by Linda Hu
[考研] 299求调剂 +5 △小透明* 2026-03-17 5/250 2026-03-18 11:49 by 尽舜尧1
[考研] 0703化学求调剂 总分331 +3 ZY-05 2026-03-13 3/150 2026-03-18 10:58 by macy2011
[考研] 环境工程调剂 +8 大可digkids 2026-03-16 8/400 2026-03-18 09:36 by zhukairuo
[基金申请] 被我言中:新模板不强调格式了,假专家开始管格式了 +4 beefly 2026-03-14 4/200 2026-03-17 22:04 by 黄鸟于飞Chao
[硕博家园] 湖北工业大学 生命科学与健康学院-课题组招收2026级食品/生物方向硕士 +3 1喜春8 2026-03-17 5/250 2026-03-17 17:18 by ber川cool子
[考研] 290求调剂 +6 孔志浩 2026-03-12 11/550 2026-03-17 14:41 by 周舟舟77
[考研] 302求调剂 +4 小贾同学123 2026-03-15 8/400 2026-03-17 10:33 by 小贾同学123
[考研] 一志愿华中师范071000,325求调剂 +6 RuitingC 2026-03-12 6/300 2026-03-16 14:50 by 可淡不可忘
[考研] 机械专硕调剂 +3 笨笨兔子 2026-03-12 3/150 2026-03-15 20:02 by 栗子粥?
[考研] 070305求调剂 +3 mlpqaz03 2026-03-14 4/200 2026-03-15 11:04 by peike
[基金申请] 现在如何回避去年的某一个专家,不知道名字 +3 zk200107 2026-03-12 6/300 2026-03-14 17:13 by zk200107
[考研] 材料工程调剂 +9 咪咪空空 2026-03-12 9/450 2026-03-13 22:05 by 星空星月
信息提示
请填处理意见