gpt4 book ai didi

java - 新手 : Items set to zero

转载 作者:行者123 更新时间:2023-11-30 06:48:42 26 4
gpt4 key购买 nike

过去几个月我一直在编写代码,并且刚刚开始使用 Java。

我在测试我的一些代码时收到这些奇怪的错误消息。

在我的一个练习中,我有这个类 WeatherRecord。我这样定义它:

class WeatherRecord {
Date d;
double precipitation;
TemperatureRange today;
TemperatureRange normal;
TemperatureRange record;

WeatherRecord(Date d, double precipitation, TemperatureRange today,
TemperatureRange normal, TemperatureRange record) {
d = this.d;
precipitation = this.precipitaiton;
today = this.today;
normal = this.normal;
record = this.record;
}

看起来很花花公子。我也有一些意见和方法,但我把它们放在一边了。

然后,稍后在我的例子中,我举了一个例子,像这样:

WeatherRecord record2 = new WeatherRecord(this.date2, 0.24,
this.temp2, this.tempNormal, this.coldTemp);

date2、temp2 和所有这些东西都是以前定义的。

然后我使用一个测试程序库来检查以确保降水量设置为 0.24(因为我的一种方法之前不起作用,所以我正在检查):

 boolean test(Tester t) {
return t.checkExpect(this.record2.precipitaiton, 0.24);

}

我的控制台告诉我实际值为 0.0,而不是 .24。我在很多不同的练习中一直遇到这种错误。

你们有没有立即注意到我做错了什么?我应该提供更多信息吗?

谢谢!

最佳答案

d = this.d; 这段代码应该反过来。 this.d = d;

以及其他人。

this.var 表示对象的 var 而您接收到方法或构造函数中的变量不是以 this 开头的

关于java - 新手 : Items set to zero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43970990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com