The method newRandom() is undefined for the type Weather
错误提示:Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method newRandom() is undefined for the type Weather
at com.imooc.weather.Weather.<init>(Weather.java:9)
at com.imooc.weather.WeatherTest.main(WeatherTest.java:6)
应该如何修改哦?
package com.imooc.weather;
public class WeatherTest {
public static void main(String[] args) {
Weather oneday=new Weather();
oneday.generate();
//oneday.read();
}
}
package com.imooc.weather;
import java.util.Random;
public class Weather {
private int temperature;
private int humdity;
boolean flag = false;
Random rand = newRandom();
public synchronized void generate() {
this.setTemperature(rand.nextInt(41));
this.setHumdity(rand.nextInt(101));
System.out.println("生成"+this);
}
public synchronized void read() {
System.out.println("读取"+this);
}
@Override
public String toString() {
return "天气数据 [温度:"+this.getTemperature()+",湿度"+this.humdity+"]";
}
public int getTemperature() {
return temperature;
}
public void setTemperature(int temperature) {
this.temperature = temperature;
}
public int getHumdity() {
return humdity;
}
public void setHumdity(int humdity) {
this.humdity = humdity;
}
}
正在回答
同学你好,同学如下位置中间少个空格,new和Random连起来了,所以导致报错
通过给中间加个空格试试
祝学习愉快~
- 参与学习 人
- 提交作业 9393 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星