/home/caleb/ASDV-Java/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/occurrencesOfEachCharacter.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.lab7_calebfontenot;

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

/**
 *
 * @author caleb
 */
public class occurrencesOfEachCharacter {
    public static void main(String[] args) {
        System.out.println((int) 'a' + ", " + (int) 'z');
        // Number array for each letter in alphabet
        int[] letterCount = new int[26];
        Scanner input = new Scanner(System.in);
        System.out.print("Enter a path to a file to scan: ");
        File filePath = new File(input.nextLine());
        try (Scanner fileScanner = new Scanner(filePath);) {
            char currentChar;
            int arrayIndex = 0;
            //Instruct scanner to delimit at everything
            fileScanner.useDelimiter("");
            while (fileScanner.hasNext()) {
                currentChar = fileScanner.next().toLowerCase().charAt(0);
                arrayIndex = ((int) currentChar - 97); //This will determine where in the array to increment at
                //System.out.println(currentChar);
                if (currentChar > 'a' & currentChar < 'z') {
                    letterCount[arrayIndex]++;
                }
            }
        } catch (FileNotFoundException ex) {
            System.out.println(ex);
        }
        //Alright. We should have an array with a count of every char in the file.
        for (int i = 0; i < letterCount.length; ++i) {
            if (letterCount[i] > 0) {
                System.out.println("Number of " + Character.toUpperCase((char) (i + 97)) + "'s: " + letterCount[i]);
            }
        }
    }
}