5-3作业,0_o.不知道怎么做了.
WeatherTest类:
package com.imooc.thread;
public class ReadWeather extends Weather implements Runnable{
public Weather wea;
public void run(){
wea.generate();
System.out.println("读取天气数据[温度:"+wea.getTempureture()+",湿度"+wea.getHunidity());
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
GenerateWeather类:
package com.imooc.thread;
public class GenerateWeather extends Weather implements Runnable{
public Weather wea;
public void run(){
wea.generate();
System.out.println("生成天气数据[温度:"+wea.getTempureture()+",湿度"+wea.getHunidity());
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
ReadWeather类:
public class ReadWeather extends Weather implements Runnable{
public Weather wea;
public void run(){
wea.generate();
System.out.println("读取天气数据[温度:"+wea.getTempureture()+",湿度"+wea.getHunidity());
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Weather类:
package com.imooc.thread;
import java.util.Random;
public class Weather {
private static int tempureture;//表示温度
private static int hunidity;//表示湿度
public Weather(){
}
public Weather(int tempureture,int hunidity){//
this.setHunidity(hunidity);
this.setTempureture(tempureture);
}
public int getTempureture() {
return tempureture;
}
public void setTempureture(int tempureture) {
this.tempureture = tempureture;
}
public int getHunidity() {
return hunidity;
}
public void setHunidity(int hunidity) {
this.hunidity = hunidity;
}
public void
W(){
tempureture=((int)(1+Math.random()*100));//使用random获取随机数
hunidity=((int)(1+Math.random()*100));//使用random获取随机数
setTempureture(tempureture);
setHunidity(hunidity);
}
public void read(){
}
}59
收起
正在回答
2回答
read方法就是获取温度和湿度并输出。在ReadWeather类的run方法中,要完成的功能是调用read方法并休眠,不需要再写其他的输出语句了。GenerateWeather类也是同样的道理。这里要注意每个类和方法都有独立的功能,生成和读的内容不写在同一个方法里。祝学习愉快!
瞳劫
2017-01-30 21:40:09
package com.imooc.test;
import com.imooc.thread.GenerateWeather;
import com.imooc.thread.ReadWeather;
public class WeatherTest extends Thread{
public static void main(String[] args) {
GenerateWeather a=new GenerateWeather();
a.start();//这里报错了
}
}
package com.imooc.thread;
public class GenerateWeather extends Weather implements Runnable{
public Weather wea;
public void run(){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wea.generate();
}
}
package com.imooc.thread;
import java.util.Random;
public class Weather {
private static int tempureture;//表示温度
private static int hunidity;//表示湿度
public Weather(){
}
public Weather(int tempureture,int hunidity){//
this.setHunidity(hunidity);
this.setTempureture(tempureture);
}
public int getTempureture() {
return tempureture;
}
public void setTempureture(int tempureture) {
this.tempureture = tempureture;
}
public int getHunidity() {
return hunidity;
}
public void setHunidity(int hunidity) {
this.hunidity = hunidity;
}
public void generate(){
tempureture=((int)(1+Math.random()*100));//使用random获取随机数
hunidity=((int)(1+Math.random()*100));//使用random获取随机数
System.out.println("读取天气数据[温度:"+getTempureture()+",湿度"+getHunidity());
}
public void read(){
}
}
Android零基础入门2018版
- 参与学习 人
- 提交作业 5461 份
- 解答问题 7235 个
此次推出的专题为Android攻城狮培养计划的第一部分语法与界面基础篇,将带大家从0开始学习Android开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星