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

playing around with do while

parent 9e5b5210
No related branches found
No related tags found
No related merge requests found
......@@ -19,8 +19,9 @@ public class Forecast {
*/
public static void main(String[] args) {
SearchingAndComparing.MethodSearchingAndComparing();
// do {
SearchingAndComparing.MethodSearchingAndComparing( /*OurScanner.ScanToSearch()*/);
// }while (SearchingAndComparing.GetFlag() == false );
CopyToFile.CopyURLToFile("weatherCache\\" + SearchingAndComparing.GetID() + ".json");
......
package de.hdm_stuttgart.mi.sd1.weather.model;
import java.util.Scanner;
public class OurScanner {
public static String ScanToSearch() {
System.out.println("Please enter your City: ");
Scanner scanCity = new Scanner(System.in);
return scanCity.nextLine();
}
}
......@@ -11,13 +11,11 @@ public class SearchingAndComparing {
static int idToSearch = 0;
static String searchedCity;
static boolean flagIfNothingFound = true;
static public void MethodSearchingAndComparing() {
System.out.println("Please enter your City: ");
Scanner scanCity = new Scanner(System.in);
String searchedCity = scanCity.nextLine();
// String searchedCity = "Republic of India";
static public void MethodSearchingAndComparing(/*String searchedCity*/) {
/**
* Searching and comparing cities
......@@ -28,19 +26,22 @@ public class SearchingAndComparing {
int k = 0;
City[] citySelector = new City[2000];
for (int i = 0; i <= Cities.cities.length - 1; i++) {
City createdCity = Cities.cities[i];
if (createdCity.getName().toLowerCase().contains(searchedCity.toLowerCase())) {
citySelector[k] = createdCity;
k++;
} else {
controlNumber++;
}
if (controlNumber > Cities.cities.length - 1) {
System.err.println("City not found");
do {
searchedCity = OurScanner.ScanToSearch();
for (int i = 0; i <= Cities.cities.length - 1; i++) {
City createdCity = Cities.cities[i];
if (createdCity.getName().toLowerCase().contains(searchedCity.toLowerCase())) {
citySelector[k] = createdCity;
k++;
} else {
controlNumber++;
}
if (controlNumber > Cities.cities.length - 1) {
flagIfNothingFound = false;
System.err.println("City not found");
}
}
}
} while (flagIfNothingFound == false);
if (citySelector[1] != null) {
......@@ -66,7 +67,7 @@ public class SearchingAndComparing {
}
scanCity.close();
// scanCity.close();
idToSearch = citySelector[0].getId();
}
......@@ -80,4 +81,8 @@ public class SearchingAndComparing {
return idToSearch;
}
public static boolean GetFlag() {
return flagIfNothingFound;
}
}
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