import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.NoSuchElementException;

public class PopDen02{
    public static void main(String[] args){
        String filename = "countryData.txt";
        File fileGodwinIsAwesome = new File( filename );

        Scanner fileScanner = null;
        try{
            // Try to open data file
            fileScanner = new Scanner(fileGodwinIsAwesome );
            // Ignore first line
            String header = fileScanner.nextLine();
            System.err.println("DEBUGGING: Ignoring the header '" + header + "'");
            // For each subsequent line
            while( fileScanner.hasNextLine() ){
                // Read in county name, population and area
                String countryId = fileScanner.next();
                int population = fileScanner.nextInt();
                double area = fileScanner.nextDouble();
                String endOfLine = fileScanner.nextLine();  // consume newline
                // Display population density (population / area), rounded to 1 decimal place
                System.out.println(countryId + "\t" + Math.round(population / area * 10.0)/10.0);
            }

        }catch(FileNotFoundException e){
            System.err.println("Sorry, unable to open " + fileGodwinIsAwesome);
            System.exit(1);
        }catch(NoSuchElementException e2){
            System.err.println("Sorry, error parsing " + fileGodwinIsAwesome + ": " + e2.getMessage());
        }

        fileScanner.close();
    }
}