私は学部生です。私は私の授業のために書いているコードのトラブルシューティングの助けを求めています。Javaの教訓の質問
import weather.WeatherData;
import Weather.data.classes.WeatherReading;
import Weather.data.classes.WeatherStation;
/**
* QUESTION 01
*
* If you decide to answer question 01 then the main method below should be used as the entry point for your application
* You may use as many other classes as you feel necessary as long as all code is supplied
*
* Remember to add -Xmx1024m to the VM arguments using menu run --> run configurations in eclipse
*/
public class Answer01 {
public static void main(String[] args) {
System.out.println("Question 01");
/*
* Add your code below
*/
WeatherStation x = new WeatherStation("site", "a", 1.1, 1.0);
WeatherReading y = new WeatherReading(1,2,3,4,5,6);
String line[] = WeatherData.getData();
ArrayList<WeatherStation>weatherSize = new ArrayList<>();
for(int i = 1; i < line.length; i++){
String [] split = line[i].split(",");
WeatherStation z = new WeatherStation(line[0], line[1], Double.parseDouble(line[2]), Double.parseDouble(line[3]));
weatherSize.add(z);
}
System.out.println(weatherSize.size() + " test");
}
}
私がここに持ってる問題はweatherSize.size()
はなく136
で正解の0
をプリントアウトしていることです。コードは、JARファイルからデータを描画
はweather.WeatherData
と呼ばれ、私はゲッターとセッターとtoString()
メソッドを持つ2つのクラスを作成し、WeatherStation
とWeatherReading
と呼ばれます。
jarファイルはWeatherData.jarというライブラリ項目で、ukの異なる場所に記録された気象データを記録します。
String [] weatherData = WeatherData.getData();
文字列の配列を返します。インデックス0の最初の要素にはヘッダー情報が含まれています。
要素0:サイトID、サイト名、緯度、経度、年、月、日、時、風速、温度 要素1: 3002、Baltasoundの(3002)、60.7490、-0.8540,2015,01,01,0私はAnswer01
のための私のコードを実行すると、21,8.70
は、それは単に言う:0テスト
package Weather.data.classes;
public class WeatherStation {
public String siteId;
public String siteName;
public double latitude;
public double longitude;
public WeatherStation(String siteId, String siteName, double latitude, double longitute){
super();
this.siteId = siteId;
this.siteName = siteName;
this.latitude = latitude;
this.longitude = longitude;
}
}
そしてWeatherReading
:
package Weather.data.classes;
public class WeatherReading {
public int year;
public int month;
public int date;
public int hour;
public int windSpeed;
public int temperature;
public WeatherReading(int year, int month, int date, int hour, int windSpeed, int temperature){
this.year = year;
this.month = month;
this.date = date;
this.hour = hour;
this.windSpeed = windSpeed;
this.temperature = temperature;
}
}
サンプルをa * little *ビットで区切り、試してみるためのサンプルデータを提供できますか? – Makoto
なぜこれをやっているのですか? 'String [] split = line [i] .split("、 ")'?あなたはどこで '分割 'を使っていますか? –
@JacobBarnesええ、配列の最初の行は、サイトID、サイト名、緯度、経度などのヘッダー情報を持っています – Ash