package org.testing; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; public class Population { private static Individu tab[]; public Population(int nombre) throws IOException{ tab= new Individu[nombre]; Initialisation(nombre); } public void ConnaitrePopulation (int nombre){ int i; for(i=0; i < nombre; i++) { System.out.println("Ville " + tab[i].StringNum() + " X: " + tab[i].StringX() + " Y: " + tab[i].StringY()); } } public static void Initialisation (int nombre) throws IOException{ int i= 0; int j= 0; String fichier= new String("Data/coordonnee.txt"); String ligne=""; int num=-1; float x=-1; float y=-1; BufferedReader ficTexte; try { ficTexte = new BufferedReader(new FileReader(new File(fichier))); if (ficTexte == null) { throw new FileNotFoundException("Fichier non trouvé: " + fichier); } do { ligne = ficTexte.readLine(); if (ligne != null) { StringTokenizer st = new StringTokenizer(ligne); while (st.hasMoreTokens() && j<3 ) { switch(j){ case 0: { num = Integer.parseInt(st.nextToken()); j++; } case 1: { x = Float.valueOf(st.nextToken()); j++; } case 2: { y = Float.valueOf(st.nextToken()); j++; } } } tab[i]= new Individu(num,x,y); j=0; i++; } } while (ficTexte != null && i