Advertisement
BiRabittoh

WIP SiciliaJavaBot

Apr 2nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1. SICILIAGUERRABOT2020.JAVA
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. package siciliaguerrabot2020;
  8.  
  9. import java.io.BufferedReader;
  10. import java.io.FileReader;
  11. import java.io.IOException;
  12. import java.util.LinkedList;
  13. import java.util.StringTokenizer;
  14.  
  15. /**
  16.  *
  17.  * @author Marco
  18.  */
  19. public class SiciliaGuerraBot2020 {
  20.  
  21.     /**
  22.      * @param args the command line arguments
  23.      */
  24.     public static void main(String[] args) {
  25.         LinkedList<Comune> comuni = new LinkedList<>();
  26.         BufferedReader reader;
  27.         StringTokenizer st;
  28.         try {
  29.             reader = new BufferedReader(new FileReader("data.txt"));
  30.             String line = reader.readLine();
  31.             while (line != null){
  32.                 line = reader.readLine();
  33.                 st = new StringTokenizer(line);
  34.                 comuni.add(new Comune(st.nextToken(), Integer.parseInt(st.nextToken()), new Centroide(Float.parseFloat(st.nextToken()), Float.parseFloat(st.nextToken()))));
  35.             }
  36.         } catch (IOException e){
  37.             System.out.println("File non trovato");
  38.         }
  39.         for(Comune c : comuni){
  40.             System.out.println(c);
  41.         }
  42.     }
  43.    
  44.     private static int getRandomNumberInRange(int min, int max) {
  45.  
  46.         if (min >= max) {
  47.             throw new IllegalArgumentException("max must be greater than min");
  48.         }
  49.  
  50.         return (int)(Math.random() * ((max - min) + 1)) + min;
  51.     }
  52.    
  53. }
  54.  
  55. CENTROIDE.JAVA
  56. /*
  57.  * To change this license header, choose License Headers in Project Properties.
  58.  * To change this template file, choose Tools | Templates
  59.  * and open the template in the editor.
  60.  */
  61. package siciliaguerrabot2020;
  62.  
  63. /**
  64.  *
  65.  * @author Marco
  66.  */
  67. public class Centroide {
  68.     private float lat;
  69.     private float lon;
  70.  
  71.     public Centroide(float lat, float lon) {
  72.         this.lat = lat;
  73.         this.lon = lon;
  74.     }
  75.  
  76.     public float getLat() {
  77.         return lat;
  78.     }
  79.  
  80.     public float getLon() {
  81.         return lon;
  82.     }
  83.    
  84.    
  85.    
  86.     public Centroide(){
  87.         lat = 0;
  88.         lon = 0;
  89.     }
  90. }
  91.  
  92. COMUNE.JAVA
  93. /*
  94.  * To change this license header, choose License Headers in Project Properties.
  95.  * To change this template file, choose Tools | Templates
  96.  * and open the template in the editor.
  97.  */
  98. package siciliaguerrabot2020;
  99.  
  100. /**
  101.  *
  102.  * @author Marco
  103.  */
  104. public class Comune {
  105.     private boolean vivo;
  106.     private String nome;
  107.     private int pop;
  108.     private Centroide pos;
  109.  
  110.     public Comune(String nome, int pop, Centroide pos) {
  111.         this.nome = nome;
  112.         this.pop = pop;
  113.         this.pos = pos;
  114.     }
  115.    
  116.     public Comune(){
  117.        
  118.     }
  119.  
  120.     public boolean isVivo() {
  121.         return vivo;
  122.     }
  123.  
  124.     public void setVivo(boolean vivo) {
  125.         this.vivo = vivo;
  126.     }
  127.  
  128.     public String getNome() {
  129.         return nome;
  130.     }
  131.  
  132.     public int getPop() {
  133.         return pop;
  134.     }
  135.  
  136.     public Centroide getPos() {
  137.         return pos;
  138.     }
  139.  
  140.     @Override
  141.     public String toString() {
  142.         return "Comune{" + "vivo=" + vivo + ", nome=" + nome + ", pop=" + pop + ", pos=" + pos + '}';
  143.     }
  144.    
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement