Data Object
package com.company;
public class DataObject {
private static String separator = ";";
private String timestamp;
private double basilejTemperature;
private double basilejPreciptitationTotal;
private double basilejWindSpeed;
private double basilejWindDirection;
public String getTimestamp() {
return timestamp;
}
public double getBasilejTemperature() {
return basilejTemperature;
}
public double getBasilejPreciptitationTotal() {
return basilejPreciptitationTotal;
}
public double getBasilejWindSpeed() {
return basilejWindSpeed;
}
public double getBasilejWindDirection() {
return basilejWindDirection;
}
public static DataObject createDataItemFromLine(String line){
try{
String[] values = line.split(separator);
return new DataObject(values[0], Double.parseDouble(values[1]),Double.parseDouble(values[2]),Double.parseDouble(values[3]),Double.parseDouble(values[4]));
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public DataObject(String timestamp,double basilejTemperature,double basilejPreciptitationTotal,double basilejWindSpeed, double basilejWindDirection){
this.timestamp = timestamp;
this.basilejTemperature = basilejTemperature;
this.basilejPreciptitationTotal = basilejPreciptitationTotal;
this.basilejWindSpeed = basilejWindSpeed;
this.basilejWindDirection = basilejWindDirection;
}
public void print(){
System.out.println(getTimestamp() + " " + getBasilejTemperature() + " " + getBasilejPreciptitationTotal() + " " + getBasilejWindSpeed() + " " + getBasilejWindDirection());
}
@Override
public String toString() {
return "DataObject{" +
"timestamp='" + timestamp + '\'' +
", basilejTemperature=" + basilejTemperature +
", basilejPreciptitationTotal=" + basilejPreciptitationTotal +
", basilejWindSpeed=" + basilejWindSpeed +
", basilejWindDirection=" + basilejWindDirection +
'}';
}
}
Data Organizer
package com.company;
import java.util.ArrayList;
public class DataOrganizer {
private ArrayList<DataObject> dataObjects;
public DataOrganizer(ArrayList<String> sourceDataList, boolean sourceDataContainsHeader){
dataObjects = new ArrayList<>(sourceDataList.size());
for(int i = (sourceDataContainsHeader) ? 1 : 0; i < sourceDataList.size(); i++){
DataObject item = DataObject.createDataItemFromLine(sourceDataList.get(i));
if(item != null) dataObjects.add(item);
}
}
public void printAllDataItem() { for(DataObject item : dataObjects) item.print(); }
public double maxTeplota(){
double tmp = 0;
for(DataObject itemTmp : dataObjects){
if(itemTmp.getBasilejTemperature() > tmp) tmp = itemTmp.getBasilejTemperature();
}
return tmp;
}
}
File Organizer
package com.company;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
public class FileOrganizer {
public static ArrayList<String> fileFromresourcetoArrayList(String filename){
ArrayList<String> lines = new ArrayList<>();
File file = new File(FileOrganizer.class.getClassLoader().getResource(filename).getFile());
try{
for (String line : Files.readAllLines(file.toPath())) {
lines.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return lines;
}
}
main
package com.company;
public class Main {
public static void main(String[] args) {
// write your code here
DataOrganizer dm = new DataOrganizer(FileOrganizer.fileFromresourcetoArrayList("dataexport_edit.csv"), true);
dm.printAllDataItem();
System.out.println(dm.maxTeplota());
}
}