PRA2024/src/main/java/model/weatherForecast.java

75 lines
2.1 KiB
Java
Raw Normal View History

package model;
import java.util.ArrayList;
import java.util.List;
public class weatherForecast {
public static final List<weatherForecast> allEntries = new ArrayList<>();
private final String cityName;
private final String description;
private final double temperature;
private final int pressure;
private final int humidity;
public weatherForecast(String cityName, String description, double temperature,
int pressure, int humidity) {
this.cityName = cityName;
this.description = description;
this.temperature = temperature;
this.pressure = pressure;
this.humidity = humidity;
allEntries.add(this);
}
public String prepareForecastString() {
String weatherForecastString = String.format("""
city: %s
description: %s
temperature[K]: %.2f
pressure[hPa]: %d
humidity[%%]: %d
--------------------""", this.cityName, this.description, this.temperature,
this.pressure, this.humidity);
return weatherForecastString;
}
// public static void saveToJson() throws IOException {
// File jsonFile = new File(generateFileName(".json"));
// ObjectMapper mapper = new ObjectMapper();
// mapper.writeValue(jsonFile, allEntries);
// }
// public static void saveToXml() throws IOException {
// File xmlFile = new File(generateFileName(".xml"));
// XmlMapper mapper = new XmlMapper();
// mapper.writeValue(xmlFile, allEntries);
// }
public static List<weatherForecast> getAllEntries() {
return new ArrayList<>(allEntries);
}
public String getCityName() {
return cityName;
}
public String getDescription() {
return description;
}
public double getTemperature() {
return temperature;
}
public int getPressure() {
return pressure;
}
public int getHumidity() {
return humidity;
}
}