Skip to content
Snippets Groups Projects
Commit 9631eeb8 authored by Haug Michael's avatar Haug Michael
Browse files

added FormatOutput with method to print coords. output can now be changed in...

added FormatOutput with method to print coords. output can now be changed in style/format to our needs
parent a1c5e099
No related branches found
No related tags found
No related merge requests found
......@@ -19,16 +19,18 @@ public class Forecast {
*/
public static void main(String[] args) {
SearchingAndComparing.MethodSearchingAndComparing();
/*
CopyToFile.CopyURLToFile("weatherCache\\" + SearchingAndComparing.GetID() + ".json");
CopyToFile.CopyFileToWeather();
WeatherOutput.PrintWeather();
*/
}
}
package de.hdm_stuttgart.mi.sd1.weather.model;
public class FormatOutput {
public static String cleanCoordOutput(String additionalProperties) {
int controllDigit = 0;
int firstIndexLon = 0;
int lastIndexLon = 0;
int firstIndexLat = 0;
int lastIndexLat = 0;
char[] coordsInArray = additionalProperties.toCharArray();
for (int i = 0; controllDigit != 2; i++) {
if (coordsInArray[i] == '=') {
controllDigit++;
firstIndexLon = i + 1;
}
}
controllDigit = 0;
for (int i = 0; i < coordsInArray.length; i++) {
if (coordsInArray[i] == ',') {
lastIndexLon = i;
}
}
for (int i = 0; controllDigit != 3; i++) {
if (coordsInArray[i] == '=') {
controllDigit++;
firstIndexLat = i + 1;
}
}
controllDigit = 0;
for (int i = 0; controllDigit != 1; i++) {
if (coordsInArray[i] == '}') {
lastIndexLat = i;
controllDigit++;
}
}
String coordsLon = additionalProperties.substring(firstIndexLon, lastIndexLon);
String coordsLat = additionalProperties.substring(firstIndexLat, lastIndexLat);
return coordsLon + ", " + coordsLat;
}
}
......@@ -4,6 +4,7 @@ import de.hdm_stuttgart.mi.sd1.weather.cities.Cities;
import de.hdm_stuttgart.mi.sd1.weather.cities.City;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
public class SearchingAndComparing {
......@@ -46,7 +47,7 @@ public class SearchingAndComparing {
City[] multipleResults = Arrays.copyOf(citySelector, k);
for (int i = 0; i < multipleResults.length; i++) {
System.out.println(i + 1 + ". " + multipleResults[i].getName() + " \n country: " + multipleResults[i].getCountry() + " | coordinates: " + citySelector[i].getAdditionalProperties());
System.out.println(i + 1 + ". " + multipleResults[i].getName() + " \n country: " + multipleResults[i].getCountry() + " | coordinates: " + FormatOutput.cleanCoordOutput(citySelector[i].getAdditionalProperties().toString()));
}
System.out.println("Please enter the number of the city you want weatherdata for: ");
Scanner scanCityChoice = new Scanner(System.in);
......@@ -76,7 +77,6 @@ public class SearchingAndComparing {
}
public static int GetID() {
return idToSearch;
}
......
......@@ -16,6 +16,10 @@ public class WeatherOutput {
for (int i = 0; i < weatherObject.getList().length - 1; i++) {
System.out.print(weatherObject.getList()[i].getDtTxt() + ": "); // output nicht wie bei Goik
double timeStamp = weatherObject.getList()[i].getDt();
timeStamp = timeStamp;
System.out.println(timeStamp);
// January 1, 1970 00:00:00.000 GMT
Main MainWeatherData = weatherObject.getList()[i].getMain();
System.out.print(Math.round(MainWeatherData.getTemp()) + "°C");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment