24小时热门版块排行榜    

查看: 860  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 什么时候开奖? +4 CrisMessi 2026-08-18 4/200 2026-08-19 00:53 by gatelove
[基金申请] 咱们一起用铁证分析2026国家社科基金中标与否 +7 启萌科技 2026-08-12 27/1350 2026-08-18 21:44 by Noways
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +3 瞬息宇宙 2026-08-15 3/150 2026-08-18 21:40 by xiaohuixin
[基金申请] 2027广东省杰青 +3 奶牛小黑 2026-08-15 9/450 2026-08-18 20:09 by 奶牛小黑
[基金申请] 朋友圈看到的 +4 wangzilk 2026-08-18 5/250 2026-08-18 19:25 by wangzilk
[基金申请] 欢迎发来filecode的Mz6后的代码验证其规律 +51 医学老男孩 2026-08-13 110/5500 2026-08-18 19:07 by icerianxia
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
[基金申请] 重要消息,中午系统在维护 +9 yuleib84 2026-08-18 10/500 2026-08-18 16:52 by archvillain
[论文投稿] 投稿咨询 +4 wwm09 2026-08-17 6/300 2026-08-18 15:36 by wwm09
[基金申请] 时间戳又变了8-15 +14 archvillain 2026-08-15 26/1300 2026-08-18 13:37 by phantomgost
[基金申请] 哪位老哥知道今年的国自然具体哪一天放榜? +13 Ldrop2023 2026-08-13 16/800 2026-08-18 12:25 by 淀粉搬运工
[基金申请] 93BebMhtakh前后11位开头都是大写 +4 且听虎啸 2026-08-17 5/250 2026-08-18 00:49 by 蔡棒棒菂
[基金申请] filecode=后面第一个是大写字母 +8 wangze12014 2026-08-14 10/500 2026-08-17 17:05 by xter9665
[基金申请] 今天系统多次维护,明天很可能放榜! +8 zju2000 2026-08-16 9/450 2026-08-17 12:20 by lmz0216
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
[基金申请] 各位道友,我要去昆明玩几天,回来见。 +7 Tide man 2026-08-14 8/400 2026-08-15 01:11 by arzu_hma
[基金申请] 重要来源:本周末出结果 +10 瞬息宇宙 2026-08-12 10/500 2026-08-13 15:46 by likettle
[基金申请] 不应该看fileCode +7 且听虎啸 2026-08-12 9/450 2026-08-13 14:27 by flydreamws
[基金申请] Filecode 又变了,巨变 +3 WH3796 2026-08-12 4/200 2026-08-13 14:13 by 小木虫6752397
[基金申请] 结合人工智能,周易传统文化,filecode打分制来了,3分以上希望很大。 +3 Tide man 2026-08-12 4/200 2026-08-13 08:35 by ZJTJZ
信息提示
请填处理意见