
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

	public static void main(String[] args) throws IOException {
	
	final String COMMA_DELIMITER = ";";
	final String NEW_LINE_SEPARATOR = "\n";
	final String fileHeader = "City;X;Y";
	final int numOfCities = 800;
		
	CityContainer cityContaine = new CityContainer(numOfCities);
	
	DateFormat dateFormat = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss");
	Date date = new Date();
	
	String nametxt = "map_"+dateFormat.format(date).toString()+"_"+String.valueOf(numOfCities)+"cities"+".txt";
	String namecsv = "graph_"+dateFormat.format(date).toString()+"_"+String.valueOf(numOfCities)+"cities"+".csv";
	File filetxt = new File("C:\\Users\\nemec\\workspace\\CityGenerator\\data\\"+nametxt);
	File filecsv = new File("C:\\Users\\nemec\\workspace\\CityGenerator\\data\\"+namecsv);
	
	PrintWriter printWriter = new PrintWriter(filetxt);
	FileWriter fileWriter = new FileWriter(filecsv);
	
	fileWriter.append(fileHeader);
	fileWriter.append(NEW_LINE_SEPARATOR);
	
	for(int k=0;k<numOfCities;k++){
		fileWriter.append(String.valueOf(cityContaine.getCity(k).GetNumber()));
		fileWriter.append(COMMA_DELIMITER);
		fileWriter.append(String.valueOf(cityContaine.getCity(k).GetX()));
		fileWriter.append(COMMA_DELIMITER);
		fileWriter.append(String.valueOf(cityContaine.getCity(k).GetY()));
		fileWriter.append(NEW_LINE_SEPARATOR);
	}
	
	fileWriter.flush();
	fileWriter.close();

	double[][] zkouska = cityContaine.distanceOfCities();
	System.out.println();
	
	printWriter.println(String.valueOf(numOfCities));
	
	for(int i=0;i<numOfCities;i++){
		for(int j=0;j<numOfCities;j++){
			System.out.printf("%5f ",zkouska[i][j]);
			printWriter.print(String.valueOf(zkouska[i][j]));
			printWriter.print(" ");
		}
	  System.out.println();
	  printWriter.println();
	}
	
	printWriter.flush();
	printWriter.close();
	
	}

}
