import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.lang.SecurityException;

import java.util.Scanner;
import java.lang.NullPointerException;
import java.io.File;

class Oct28 {
	public static void main(String[] args) {

		PrintWriter pw = null;

		try {
			pw = new PrintWriter("written.txt");
		}
		catch(FileNotFoundException | SecurityException ex) {
			System.out.println("Cannot open file for writing");
			System.out.println(ex);
			ex.printStackTrace();	
			System.exit(0);	
		}

		pw.println("Hello joe!");
		pw.print("How are you?\n");
		pw.printf("I am %s\n", "good!");

		pw.close();

		// Lab 11

		//#1
		Scanner fin = null;

		try {
			fin = new Scanner(new File("scores.txt"));
		}
		catch(FileNotFoundException | NullPointerException ex) {
			System.out.println("Cannot open for writing");
			System.exit(0);
		}

		fin.useDelimiter("[:\\n]");

		int length = fin.nextInt();
		int[] scores = new int[length];

		for(int i = 0; i < length; i++) {
			scores[i] = fin.nextInt();
		}	

		for(int elm : scores) {
			System.out.printf("%d ", elm);
		}
		System.out.println();

		double sum = 0;
		for(int elm : scores) {
			sum += elm;
		}

		System.out.printf("mean average: %.2f\n", sum / length);
		System.out.println();
		
		//#2

		try {
			fin = new Scanner(new File("strings.txt"));
		}
		catch(FileNotFoundException | NullPointerException ex) {
			System.out.println("Cannot open for writing");
			System.exit(0);
		}

		fin.useDelimiter("[,\\n]");

		length = fin.nextInt();
		String[] names = new String[length];

		for(int i = 0; i < length; i++) {
			names[i] = fin.next();
		}	

		for(String elm : names) {
			System.out.printf("%s\n", elm);
		}
		System.out.println();
	
		//3
 
		try {
			fin = new Scanner(new File("chars.txt"));
		}
		catch(FileNotFoundException | NullPointerException ex) {
			System.out.println("Cannot open for writing");
			System.exit(0);
		}

		fin.useDelimiter("[-\\n]");

		char[][] matrix = new char[3][5];

		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 5; j++) {
				String token = fin.next();
				char nextChar = token.charAt(0);
				matrix[i][j] = nextChar;
			}	
		}	

		for(char[] row : matrix) {
			for(char elm : row) {
				System.out.printf("%c ", elm);
			}
			System.out.println();
		}














	}
}
