Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.InputStream;
- import java.util.*;
- class WeatherStats{
- private Map<String, String> vrnezi;
- private Map<String, String> minTemp;
- private Map<String, String> maxTemp;
- private Map<String, String> pritisok;
- public WeatherStats(InputStream in){
- vrnezi = new HashMap<String, String> ();
- minTemp = new HashMap<String, String> ();
- maxTemp = new HashMap<String, String> ();
- pritisok = new HashMap<String, String> ();
- Scanner scanner = new Scanner(in);
- while(scanner.hasNext()){
- String[] delovi = scanner.nextLine().split(";");
- String grad = delovi[0];
- for(int i=1;i<delovi.length;i++){
- String [] delovi2 = delovi[i].split(" ");
- minTemp.put(grad + " " + delovi2[1], delovi2[2]);
- maxTemp.put(grad + " " + delovi2[1], delovi2[3]);
- pritisok.put(grad + " " + delovi2[1], delovi2[4]);
- vrnezi.put(grad + " " + delovi2[1], delovi2[5]);
- }
- break; //TRGNI OVA ZA DA RABOTI NA ELAB!
- }
- }
- public String temperature(String city, String type){
- String fin = "";
- if(type.equals("min")){
- int mintemp = Integer.MAX_VALUE;
- Iterator it = minTemp.entrySet().iterator();
- while(it.hasNext()){
- Map.Entry en = (Map.Entry) it.next();
- String [] pom = ((String) en.getKey()).split(" ");
- if(pom[0].equals(city)){
- if(Integer.valueOf((String) en.getValue()) < mintemp){
- mintemp = Integer.valueOf((String) en.getValue());
- fin = mintemp + "*C " + pom[1];
- }
- }
- }
- }
- else if(type.equals("max")){
- int maxtemp = Integer.MIN_VALUE;
- Iterator it = maxTemp.entrySet().iterator();
- while(it.hasNext()){
- Map.Entry en = (Map.Entry) it.next();
- String [] pom = ((String) en.getKey()).split(" ");
- if(pom[0].equals(city)){
- if(Integer.valueOf((String) en.getValue()) > maxtemp){
- maxtemp = Integer.valueOf((String) en.getValue());
- fin = maxtemp + "*C " + pom[1];
- }
- }
- }
- }
- else{
- //МН ЗАМАРАЊЕ, АЈ ПОСЛЕ
- }
- return fin;
- }
- public String temeratureMin(){
- String fin = "";
- int mintemp = Integer.MAX_VALUE;
- Iterator it = minTemp.entrySet().iterator();
- while(it.hasNext()){
- Map.Entry en = (Map.Entry) it.next();
- String [] pom = ((String) en.getKey()).split(" ");
- if(Integer.valueOf((String) en.getValue()) < mintemp){
- mintemp = Integer.valueOf((String) en.getValue());
- fin = pom[0] +" " +mintemp + "*C " + pom[1];
- }
- }
- return fin;
- }
- public String temeratureMax(){
- String fin = "";
- int mintemp = Integer.MIN_VALUE;
- Iterator it = maxTemp.entrySet().iterator();
- while(it.hasNext()){
- Map.Entry en = (Map.Entry) it.next();
- String [] pom = ((String) en.getKey()).split(" ");
- if(Integer.valueOf((String) en.getValue()) > mintemp){
- mintemp = Integer.valueOf((String) en.getValue());
- fin = pom[0] +" " + mintemp + "*C " + pom[1];
- }
- }
- return fin;
- }
- public int rainyDays(String city){
- int brojac = 0;
- Iterator it = vrnezi.entrySet().iterator();
- while(it.hasNext()){
- Map.Entry en = (Map.Entry) it.next();
- String [] pom = ((String) en.getKey()).split(" ");
- if(pom[0].equals(city)){
- if(Float.valueOf((String) en.getValue()) > 0.05){
- brojac++;
- }
- }
- }
- return brojac;
- }
- public void print(){
- Iterator it = vrnezi.entrySet().iterator();
- while(it.hasNext()){
- System.out.println(it.next());
- }
- }
- }
- public class WeatherStatsTest {
- public static void main(String[] args) {
- WeatherStats we = new WeatherStats(System.in);
- System.out.println(we.rainyDays("Berovo"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement