feat: add the first display class
This commit is contained in:
parent
96c1866978
commit
25ad77e394
@ -5,6 +5,11 @@ import java.io.IOException;
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
String APIKey = "cef8e1b6ea364994b5072423240111";
|
String APIKey = "cef8e1b6ea364994b5072423240111";
|
||||||
}
|
WeatherAPI weatherAPI = new WeatherAPI(APIKey);
|
||||||
|
WeatherDisplay display = new WeatherDisplayBasic();
|
||||||
|
|
||||||
|
display.addAPI(weatherAPI);
|
||||||
|
|
||||||
|
display.display(5, "Bordeaux");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package eirb.pg203;
|
package eirb.pg203;
|
||||||
|
|
||||||
public interface WeatherDisplay {
|
public interface WeatherDisplay {
|
||||||
void display();
|
void display(int days, String city);
|
||||||
|
|
||||||
void addAPI(WeatherDataAPI w);
|
void addAPI(WeatherDataAPI w);
|
||||||
}
|
}
|
||||||
|
53
src/main/java/eirb/pg203/WeatherDisplayBasic.java
Normal file
53
src/main/java/eirb/pg203/WeatherDisplayBasic.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package eirb.pg203;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
class WeatherDisplayBasic implements WeatherDisplay {
|
||||||
|
ArrayList<WeatherDataAPI> apis;
|
||||||
|
|
||||||
|
WeatherDisplayBasic() {
|
||||||
|
this.apis = new ArrayList<WeatherDataAPI>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayHeader(int days) {
|
||||||
|
StringBuilder line = new StringBuilder();
|
||||||
|
line.append("Source\t");
|
||||||
|
|
||||||
|
for (int i = 0 ; i < days ; ++i) {
|
||||||
|
line.append("\tJ + ")
|
||||||
|
.append(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.err.println(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayTemperatures(String ApiName, ArrayList<Temperature> temperatures) {
|
||||||
|
StringBuilder line = new StringBuilder();
|
||||||
|
line.append(ApiName);
|
||||||
|
|
||||||
|
for (Temperature temp: temperatures) {
|
||||||
|
line.append('\t')
|
||||||
|
.append(temp.getTemp());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.err.println(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void display(int days, String city) {
|
||||||
|
ArrayList<Temperature> temperatures;
|
||||||
|
displayHeader(days);
|
||||||
|
|
||||||
|
for (WeatherDataAPI w: apis) {
|
||||||
|
try {
|
||||||
|
temperatures = w.getTemperatures(days, city);
|
||||||
|
displayTemperatures(w.getAPIName(), temperatures);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("ntm++ martin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAPI(WeatherDataAPI w) {
|
||||||
|
this.apis.add(w);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user