急求!java面向对象程序设计定义三个对象 太阳,蚂蚁,树,向日葵 实现随着从日出到日落时蚂蚁,树,向日葵有规律的变化过

急求!java面向对象程序设计
定义三个对象 太阳,蚂蚁,树,向日葵 实现随着从日出到日落时蚂蚁,树,向日葵有规律的变化过程 :随着时间的变化 蚂蚁数量增长,树长得越来越高,向日葵始终面向太阳
时间从早7:00~晚7:00 隔两个小时变化一次 可以用循环语句
太阳:从日出到日落的角度范围 0度~180度 每隔两个小时变化30度
树:起初1m ,每两个小时长高0.1m
蚂蚁:起初一个,每两个小时增加一个
向日葵 随着太阳变化
tey_lsp 1年前 已收到1个回答 举报

jizaberu朱 幼苗

共回答了16个问题采纳率:93.8% 举报

import java.util.logging.Level;
import java.util.logging.Logger;
public class Sun {
public static int hh = 7;
public static int mm = 0;
public static int ss = 0;
public static int angle = 0;
Tree a;
Ant b;
SunFlower c;
Sun(){
a = new Tree();
b = new Ant();
c = new SunFlower();
while(true){
try {
Thread.sleep(1000);//1000毫秒,秒加一
} catch (InterruptedException ex) {
Logger.getLogger(Sun.class.getName()).log(Level.SEVERE,null,ex);
}
addTime();
}
}
public void addTime(){
while(hh

1年前 追问

6

tey_lsp 举报

该怎么用eclipse软件运行程序 class名应该是什么

举报 jizaberu朱

叫Sun 重写了一下, 可以输出 import java.util.logging.Level; import java.util.logging.Logger; public class Sun { public static int hh = 7; public static int mm = 0; public static int ss = 0; public static int angle = 0; Tree a; Ant b; SunFlower c; Sun(){ a = new Tree(); b = new Ant(); c = new SunFlower(); while(true){ try { Thread.sleep(1);//1000毫秒,秒加一 } catch (InterruptedException ex) { Logger.getLogger(Sun.class.getName()).log(Level.SEVERE, null, ex); } addTime(); } } public void addTime(){ while(hh <= 19){ ss++; if(ss == 60){ mm++; ss = 0; } if(mm == 60){ hh++; mm = 0; } addAngle();//测试时间 } } public void addAngle(){ if(((hh == 9)||(hh == 11)||(hh == 13)||(hh == 15)||(hh == 17)||(hh == 19))&&(mm == 0)&&(ss == 0)){ // 9 11 13 15 17 19 angle += 30; //若为 9 11 13 15 17 19 角度加30 a.addHeight();//树高度加0.1 new Ant(); //new一只蚂蚁,蚂蚁计数加一 c.faceOfSun(angle); System.out.println(hh); System.out.println(angle); System.out.println(Ant.count); System.out.println(a.height); } } public static void main(String ars[]){ new Sun(); } } class Ant { public static int count = 0; Ant(){ count++; } } class Tree { public double height = 1; public void addHeight(){ height += 0.1; } } class SunFlower { private int angle = 0; public void faceOfSun(int angle){ this.angle = angle; } }

tey_lsp 举报

运行不了 不知道哪里错了 帮我指导一下吧

举报 jizaberu朱

我运行的时候是没有问题的,你的Sun 建类的时候 首字母小写了......我的是大写的...
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 18 q. 0.100 s. - webmaster@yulucn.com