OK I have a project due tonight at midnight and I know I should have posted sooner but it seemed like such simple things that I just knew I could do it on my own. I was wrong. I need your help. I have a program that essentially makes a database in the console by asking the user for names and stats of various sports players. It saves them to a txt file, sorts them, removes them and averages the stats. No problems there. The problems I am having are that I am supposed to do error detection using exception handling which I can't get to work and everything I find on it seems to not fit with my code (try/catch with external methods when im doing it in a single method or something). My second problem is that I am supposed to implement a load function with the following parameters:

LOAD: Prompts the user for a filename that was created by a previous SAVE operation. The
players represented in the SAVE file that do not already exist in the current list of players are added to the current list of players in the application. Each player may be assumed to have a unique name. Note, neither first nor last names alone can be assumed to be unique, but the combination of both first and last name can be assumed to be unique. E.g., Jane Doe, Jane Smith, and John Doe are all valid unique names for players. Each player class must implement a new constructor that takes a single formatted string as its parameter. This constructor should, in essence, create an object with the appropriate instanced information from a string produced previously by its own toString() method. Use these constructors in your LOAD implementation.
String playerInfo = “Jane Doe: Points: 4 Assists: %: 0.25”);
SoccerPlayer player = new SoccerPlayer(playerInfo);

I know I'll probably have to use a buffered IO stream or something but I can't find anything in my books or online that talks about loading, only saving. I'm aware of the oracle java tutorial for io streams but that website has been the least helpful thing when it comes to programming. Heres the code:

Main Class:

/**
 * This program will asks the user what they want to do with a user prompt
 * and then it calls the method that corresponds to the selected command. The
 * commands will either add a player to the list, remove a player from the list,
 * show the list in it's entirety, save the list to a file, or quit the program.
 * This program uses a Player class that helps to define the player object that
 * is in use.
 */
package cs241project2;

import java.util.*;
import java.io.*;

/**
 * @author 24x24
 */
public class Main {

    public static void main(String[] args) throws IOException {

        Scanner keyboard = new Scanner(System.in);
        String menuOperation; 
        ArrayList<PlayerStats> players = new ArrayList<PlayerStats>();

        do {
            menuOperation = getMenuChoice(keyboard);
            // perform the method depending on the choice
            if (menuOperation.equalsIgnoreCase("ADD")) {
                add(keyboard, players);
            } else if (menuOperation.equalsIgnoreCase("REMOVE")) {
                remove(keyboard, players);
            } else if (menuOperation.equalsIgnoreCase("SHOW")) {
                show(players);
            } else if (menuOperation.equalsIgnoreCase("SAVE")) {
                save(keyboard, players);
            } else if (menuOperation.equalsIgnoreCase("SORT")) {
                sort(players);
            } else if (menuOperation.equalsIgnoreCase("LOAD")) {
               load(keyboard);
            }
            // repeat if the choice does not equal QUIT
        } while (!(menuOperation.equalsIgnoreCase("QUIT")));
        
        System.out.println();
        System.out.println("** GOODBYE! **");
        
    } // end method main

    /**
     * The getMenuChoice method asks the user to pick a menu option. They
     * must pick one option: add player, remove player, show players statistics,
     * save the players statistics, or quit the program. The
     * case of the keyboard is unimportant.
     * @param keyboard scanner for user to input choices
     * @return the string of a valid menu option: add, remove, show, save,
     * or quit.
     */
    public static String getMenuChoice(Scanner keyboard) {

        String choice;

        System.out.println("What operation next? (ADD, REMOVE, SHOW, SAVE, LOAD, SORT, QUIT)?");
        choice = keyboard.nextLine().trim();

        while (!(choice.equalsIgnoreCase("ADD") || choice.equalsIgnoreCase("REMOVE") || choice.equalsIgnoreCase("SHOW") || choice.equalsIgnoreCase("SAVE") || choice.equalsIgnoreCase("LOAD") || choice.equalsIgnoreCase("SORT") || choice.equalsIgnoreCase("QUIT"))) {
            System.out.println("Operation not recognized. Please choose from the available list.\n");
            System.out.println("What operation next? (ADD, REMOVE, SHOW, SAVE, LOAD, SORT, QUIT)?");
            choice = keyboard.nextLine().trim();
        }

        return choice;
    } // end method getMenuChoice

    /**
     * The add method queries the user to keyboard the name of a player,
     * along with the points scored, assists made, and the penalty kick
     * rate for that player. The method uses an ArrayList to store Player
     * objects into a string, separated by commas between the full name, the
     * points scored, assists made, and penalty kick rate percentage.
     * @param keyboard Scanner for user keyboard
     * @param players ArrayList of all players and their stats
     */
    public static void add(Scanner keyboard, ArrayList<PlayerStats> team) {
        String sportChoice;

        System.out.println("Please enter sport type (SOCCER, PAINTBALL, BASEBALL):");
        sportChoice = keyboard.nextLine().trim();

        // error checking for sport type
        while (!(sportChoice.equalsIgnoreCase("SOCCER")
                || sportChoice.equalsIgnoreCase("PAINTBALL")
                || sportChoice.equalsIgnoreCase("BASEBALL"))) {
            System.out.println("Operation not recognized. Please choose from the available list.\n");
            sportChoice = keyboard.nextLine().trim();
        }

        //adds the appropriate type of player to the list
        if (sportChoice.equalsIgnoreCase("SOCCER")) {
            PlayerStats player = new Soccer();
            player.getValuesFromConsole(keyboard);
            team.add(player);
            System.out.println(player.confirmPlayerAdd());
        } else if (sportChoice.equalsIgnoreCase("PAINTBALL")) {
            PlayerStats player = new Paintball();
            player.getValuesFromConsole(keyboard);
            team.add(player);
            System.out.println(player.confirmPlayerAdd());
        } else if (sportChoice.equalsIgnoreCase("BASEBALL")) {
            PlayerStats player = new Baseball();
            player.getValuesFromConsole(keyboard);
            team.add(player);
            System.out.println(player.confirmPlayerAdd());
        }

        keyboard.nextLine();
    } // end method add

    /**
     * The remove method queries the user to remove a player from the
     * players list. An ArrayList is used to query the statistics, searching first
     * by last name and using the position of the first name to further verify
     * before removing it. If successful, the player will be removed. If the
     * player was not found, an error will appear and the user will be returned
     * to the main menu.
     * @param keyboard Scanner for user input
     * @param players ArrayList of all players and their stats
     */
    public static void remove(Scanner keyboard, ArrayList<PlayerStats> players) {

        String lastName;
        String firstName;
        int indexNum;

        if (players.isEmpty()) {
            System.out.println("** NO RECORDS TO REMOVE! **\n");
        } else {

            System.out.println("Please enter the last name of the player to " + "remove:");
            lastName = keyboard.nextLine().trim();
            System.out.println("Please enter the first name of the player to " + "remove:");
            firstName = keyboard.nextLine().trim();
            indexNum = findPlayer(players, lastName, firstName);

            if (indexNum == -1) {
                System.out.println("** PLAYER NOT FOUND **\n");
            } else {
                players.remove(indexNum);
                System.out.println("** REMOVED " + firstName + " " + lastName + " **\n");
            }
        }
    } // end method remove

    /**
     * The show method displays a formatted table of data to the screen.
     * An ArrayList holding Player objects is required for the data to show
     * to the screen. 
     * @param players ArrayList of all players and their stats
     */
    public static void show(ArrayList<PlayerStats> players) {

        if (players.isEmpty()) {
            System.out.println("** NO RECORDS TO SHOW **\n");
        } else {
            System.out.println("** SHOW ALL PLAYERS **\n");
            System.out.println(sort(players));
        }
    } // end method show

    /**
     * The save method asks the user for a file name and saves all of
     * the players statistics to that file. The method uses the sort method
     * to make a string, which it will then print out to the file. An ArrayList
     * holding Player objects is required for the data to be written to the
     * file.
     * @param keyboard Scanner for user keyboard
     * @param players ArrayList of all players and their stats
     * @throws IOException 
     */
    public static void save(Scanner keyboard, ArrayList<PlayerStats> players) throws IOException {

        String fileName = null; 

        if (players.isEmpty()) {
            System.out.println("** NO RECORDS TO SAVE **\n");
        } else {

            System.out.println("Please enter file name:");
            fileName = keyboard.nextLine().trim();
            FileWriter outFile = new FileWriter(fileName, true);
            PrintWriter outputFile = new PrintWriter(outFile);
            outputFile.println(sort(players));
            System.out.println("** " + players.size() + " RECORD SAVED TO " + fileName + " **\n");
            outputFile.close();
        }
    } // end method save
    
    public static void load (Scanner keyboard) throws IOException{
                String fileName = null;

        System.out.println("Please enter a file name: ");
        fileName = keyboard.nextLine().trim();

        // http://download.oracle.com/javase/tutorial/essential/io/
        // I thought this would be somewhat of how I should be doing it.
        // Not very much help
        
        // error checking for file name
        // Needs to be better and have exception
        if (fileName == null) {
            System.out.println("File not found. Please choose an available file.\n");
            fileName = keyboard.nextLine().trim();
        }
        System.out.println("Loading...");
        // load the file here
        /**
 LOAD: Prompts the user for a filename that was created by a previous SAVE operation. The
players represented in the SAVE file that do not already exist in the current list of players are added
to the current list of players in the application. Each player may be assumed to have a unique name.
Note, neither first nor last names alone can be assumed to be unique, but the combination of both
first and last name can be assumed to be unique. E.g., Jane Doe, Jane Smith, and John Doe are all
valid unique names for players.

         */
    }
    
    
    /**
     * The sort method sorts the list of players based on last name and sport type.
     * A header is added to the beginning of the string and
     * calculated averages are added to the bottom of the string. An
     * ArrayList that contains Player objects is required.
     * @param players ArrayList of all players and their stats
     * @return a formatted list of all data and averages
     */
    public static String sort(ArrayList<PlayerStats> players) {

        String completeStats = "";
        ArrayList<Baseball> basketballPlayers = new ArrayList<Baseball>();
        ArrayList<Paintball> golfPlayers = new ArrayList<Paintball>();
        ArrayList<Soccer> soccerPlayers = new ArrayList<Soccer>();
        Collections.sort(players);

        // make separate lists based on the type of player
        for (int i = 0; i < players.size(); i++) {
            if (players.get(i) instanceof Baseball) {
                basketballPlayers.add((Baseball) players.get(i));
            } else if (players.get(i) instanceof Paintball) {
                golfPlayers.add((Paintball) players.get(i));
            } else if (players.get(i) instanceof Soccer) {
                soccerPlayers.add((Soccer) players.get(i));
            }
        }

        // put all data into the string to return
        if (!basketballPlayers.isEmpty()) {
            completeStats = completeStats.concat(makeBasketballString(basketballPlayers) + "\n");
        }
        if (!golfPlayers.isEmpty()) {
            completeStats = completeStats.concat(makePaintballString(golfPlayers) + "\n");
        }
        if (!soccerPlayers.isEmpty()) {
            completeStats = completeStats.concat(makeSoccerString(soccerPlayers));
        }

        return completeStats;
    } // end sort method 


    /**
     * The findPlayer method searches through the players list for a specified player. 
     * If it is found, it will return the index in the ArrayList where the player was found. 
     * If the player was not found then it will return a -1.
     * @param players ArrayList of all players and their data
     * @param lastName last name of the player to search for
     * @param firstName first name of the player to search for
     * @return the index of the player found, or a -1 if not found
     */
    public static int findPlayer(ArrayList<PlayerStats> team,
            String lastName,
            String firstName) {

        int indexNum = 0;

        for (int i = 0; i < team.size(); i++) {
            // uses the first and last name to verify the player
            if ((team.get(i).getFirstName().equals(firstName))
                    && team.get(i).getLastName().equals(lastName)) {
                indexNum = i;
            } else {
                indexNum = -1;
            }
        }

        return indexNum;
    } // end method findPlayer

    /**
     * The average method calculates an average and rounds up to the
     * nearest hundredths place. It uses a double for the total amount that
     * was summed up and the integer number amount of items the total was for.
     * It returns a double that has been rounded to two decimal places.
     * @param total total amount of items
     * @param numberOfItems total number of items that are being averaged
     * @return a double average amount, rounded to two decimal places
     */
    public static double average(double total, int numberOfItems) {
        return Math.round((total / (double) (numberOfItems)) * 100) / (double) 100;
    } // end method average

    public static String makeBasketballString(ArrayList<Baseball> baseballPlayers) {
        String stats = null;
        double totalOne = 0;
        double totalTwo = 0;
        double totalThree = 0;

        stats = "\t\t** BASEBALL PLAYERS **\n";
        for (int i = 0; i < baseballPlayers.size(); i++) {
            stats = stats.concat(baseballPlayers.get(i).toString());
            stats = stats.concat("\n");
        }
        stats = stats.concat("Total Records: " + baseballPlayers.size() + "\n");

        // find the totals for baseball players
        for (int i = 0; i < baseballPlayers.size(); i++) {
            totalOne += baseballPlayers.get(i).getPointsScored();
            totalTwo += baseballPlayers.get(i).getOuts();
            totalThree += baseballPlayers.get(i).getBattingAverage();
        }

        // put the averages at the end
        stats = stats.concat("AVERAGES\tPoints: "
                + average(totalOne, baseballPlayers.size())
                + "   Homeruns: "
                + average(totalTwo, baseballPlayers.size())
                + "   Batting Average %: "
                + average(totalThree, baseballPlayers.size())
                + "\n");

        return stats;
    }

    public static String makePaintballString(ArrayList<Paintball> paintballPlayers) {
        String stats = null;
        double totalOne = 0;
        double totalTwo = 0;
        double totalThree = 0;

        stats = "\t\t** PAINTBALL PLAYERS **\n";
        for (int i = 0; i < paintballPlayers.size(); i++) {
            stats = stats.concat(paintballPlayers.get(i).toString());
            stats = stats.concat("\n");
        }
        stats = stats.concat("Total Records: " + paintballPlayers.size() + "\n");

        // find the totals for paintball players
        for (int i = 0; i < paintballPlayers.size(); i++) {
            totalOne += paintballPlayers.get(i).getPointsScored();
            totalTwo += paintballPlayers.get(i).getHeadShots();
            totalThree += paintballPlayers.get(i).getBallsPerSecond();
        }

        // put the averages at the end
        stats = stats.concat("AVERAGES\tPoints: "
                + average(totalOne, paintballPlayers.size())
                + "   Head Shots: "
                + average(totalTwo, paintballPlayers.size())
                + "   Balls Per Second: "
                + average(totalThree, paintballPlayers.size())
                + "\n");

        return stats;
    } // end makePaintballString

    public static String makeSoccerString(ArrayList<Soccer> soccerPlayers) {
        String stats = null;
        double totalOne = 0;
        double totalTwo = 0;
        double totalThree = 0;

        stats = stats = "\t\t** SOCCER PLAYERS **\n";
        for (int i = 0; i < soccerPlayers.size(); i++) {
            stats = stats.concat(soccerPlayers.get(i).toString());
            stats = stats.concat("\n");
        }
        stats = stats.concat("Total Records: " + soccerPlayers.size() + "\n");

        // find the totals for soccer players
        for (int i = 0; i < soccerPlayers.size(); i++) {
            totalOne += soccerPlayers.get(i).getPointsScored();
            totalTwo += soccerPlayers.get(i).getAssists();
            totalThree += soccerPlayers.get(i).getPenaltyKickRate();
        }

        // put the averages at the end
        stats = stats.concat("AVERAGES\tPoints: "
                + average(totalOne, soccerPlayers.size())
                + "   Assists: "
                + average(totalTwo, soccerPlayers.size())
                + "   Penalty Kick %: "
                + average(totalThree, soccerPlayers.size())
                + "\n");

        return stats;
    } // end makeSoccerString
} // end class Main

Player Class:

package cs241project2;

/**
 * The Player class creates Player objects based on a player's first and
 * last names, the points scored, assists made, and the penalty kick rate
 * percentage. It uses basic mutators to construct the object. Public
 * accessors are available to view all of the data for the particular player.
 * A toString method is provided to create strings of data that contain the
 * player's data separated by commas, including the full name, points scored,
 * assists made, and the penalty kick rate.
 * @author 24x24
 */
public class Player
{
    private String lastName; 
    private String firstName; 
    private int pointsScored; 
    private int assists; 
    private double penaltyKickRate; 

    /**
     * The Player constructor creates a player based on their first name,
     * last name, points scored, assists made, and the penalty kick rate. Basic
     * mutators are used to construct the object. It requires strings of the
     * first and last name, integers for points scored and assists made, and
     * a double for the penalty kick rate.
     * @param lastName the last name of the player
     * @param firstName the first name of the player
     * @param pointsScored the points scored by the player
     * @param assists the assists made by the player
     * @param penaltyKickRate penalty kick rate of the player
     */
    public Player(String lastName, String firstName, int pointsScored,
            int assists, double penaltyKickRate)
    {
        this.setLastName(lastName);
        this.setFirstName(firstName);
        this.setPointsScored(pointsScored);
        this.setAssists(assists);
        this.setPointsScored(pointsScored);
        this.setPenaltyKickRate(penaltyKickRate);
    } // end constructor Player   
    
    
    // ------------------
    // Methods
    // ------------------

    /**
     * The private method setLastName is used by the Player constructor as
     * a mutator method to set the last name of the player. A string for the
     * last name is required by the method.
     * @param lastName the last name of the player
     */
    private void setLastName(String lastName)
    {
        this.lastName = lastName;
    } // end method setLastName

    /**
     * The private method setFirstName is used by the Player constructor as
     * a mutator method to set the first name of the player. A string for the
     * first name is required by the method.
     * @param firstName the first name of the player
     */
    private void setFirstName(String firstName)
    {
        this.firstName = firstName;
    } // end method setFirstName

    /**
     * The private method setPointsScored is used by the Player constructor as
     * a mutator method to set the points scored by the player. An integer
     * for the amount of points scored is required by the method.
     * @param pointsScored the amount of points scored by the player
     */
    private void setPointsScored(int pointsScored)
    {
        this.pointsScored = pointsScored;
    } // end method setPointsScored

    /**
     * The private method setAssists is used by the Player constructor as
     * a mutator method to set the assists made by the player. An integer
     * for the amount of assists made is required by the method.
     * @param assists the amount of assists made by the player
     */
    private void setAssists(int assists)
    {
        this.assists = assists;
    } // end method setAssists

    /**
     * The private method setPenaltyKickRate is used by the Player constructor
     * as a mutator method to set the penalty kick rate of the player. A double
     * for the penalty kick rate (as a percentage) is required by the method.
     * @param penaltyKickRate the rate of successful penalty kicks
     */
    private void setPenaltyKickRate(double penaltyKickRate)
    {
        this.penaltyKickRate = penaltyKickRate;
    } // end method setPenaltyKickRate

    /**
     * The getLastName method returns the last name of the player.
     * @return the last name of the player
     */
    public String getLastName()
    {
        return this.lastName;
    } // end method getLastName

    /**
     * The getFirstName method returns the first name of the player.
     * @return the first name of the player
     */
    public String getFirstName()
    {
        return this.firstName;
    } // end method getFirstName

    /**
     * The getPointsScored method returns the points scored by the player.
     * @return number of points scored by the player
     */
    public int getPointsScored()
    {
        return this.pointsScored;
    } // end method getPointsScored

    /**
     * The getAssists method returns the assists made by the player.
     * @return number of assists made by the player
     */
    public int getAssists()
    {
        return this.assists;
    } // end method getAssists

    /**
     * The getPenaltyKickRate method returns the penalty kick rate of the
     * player.
     * @return penalty kick rate of the player, in the form of a decimal
     */
    public double getPenaltyKickRate()
    {
        return this.penaltyKickRate;
    } // end method getPenaltyKickRate
} // end class Player

Player Stats Class:

package cs241project2;

import java.util.*;

/**
 * The Player class creates Player objects based on a player's first and
 * last names, the points scored, assists made, and the penalty kick rate
 * percentage. It uses basic mutators to construct the object. Public
 * accessors are available to view all of the data for the particular player.
 * A toString method is provided to create strings of data that contain the
 * player's data separated by commas, including the full name, points scored,
 * assists made, and the penalty kick rate.
 * @author 24x24
 */
public class PlayerStats implements Comparable {

    private String lastName;
    private String firstName;
    private int pointsScored;
    private String input;

    /**
     * The Player constructor creates a player based on their first name,
     * last name, points scored. Basic mutators are used to construct the object. 
     * It requires strings of the first and last name and integers for points scored.
     * @param lastName the last name of the player
     * @param firstName the first name of the player
     * @param pointsScored the points scored by the player
     */
    public PlayerStats(String lastName, String firstName, int pointsScored) {
        this.setLastName(lastName);
        this.setFirstName(firstName);
        this.setPointsScored(pointsScored);
    } // end constructor Player

    public PlayerStats() {
    }

    // ------------------
    // Methods
    // ------------------
    public void getValuesFromConsole(Scanner input) {
        System.out.println("Please enter the player's last name:   ");
        lastName = input.nextLine().trim();
        // Need to find a way to not work with numbers 
        // Also find a way to allow ' and - but no other symbols
        System.out.println("Please enter the player's first name:  ");
        firstName = input.nextLine().trim();
        // Need to find a way to not work with numbers 
        // Also find a way to allow ' and - but no other symbols
        System.out.println("Please enter the number of points scored for "
                + firstName + " " + lastName + ":  ");
        try {
            pointsScored = input.nextInt();

            while (pointsScored < 0) {
                System.out.println("Please enter a non-negative number: ");
                pointsScored = input.nextInt();
            }
        } catch (RuntimeException e) {
            System.out.println("Please enter a number: ");
            // pointsScored = input.nextInt();
        }

        //***********************
        while (input.hasNextLine()) {
            try {
                if (pointsScored < 0) {
                    System.out.print("Please choose a positive number: ");
                } else { /* Do stuff */ }
            } catch (NumberFormatException e) {
                pointsScored = 0;
            }
        }
        //***********************

    }

    public String confirmPlayerAdd() {
        return null;
    }

    /**
     * The private method setLastName is used by the Player constructor as
     * a mutator method to set the last name of the player. A string for the
     * last name is required by the method.
     * @param lastName the last name of the player
     */
    private void setLastName(String lastName) {
        this.lastName = lastName;
    } // end method setLastName

    /**
     * The private method setFirstName is used by the Player constructor as
     * a mutator method to set the first name of the player. A string for the
     * first name is required by the method.
     * @param firstName the first name of the player
     */
    private void setFirstName(String firstName) {
        this.firstName = firstName;
    } // end method setFirstName

    /**
     * The private method setPointsScored is used by the Player constructor as
     * a mutator method to set the points scored by the player. An integer
     * for the amount of points scored is required by the method.
     * @param pointsScored the amount of points scored by the player
     */
    private void setPointsScored(int pointsScored) {
        this.pointsScored = pointsScored;
    } // end method setPointsScored

    /**
     * The getLastName method returns the last name of the player.
     * @return the last name of the player
     */
    public String getLastName() {
        return this.lastName;
    } // end method getLastName

    /**
     * The getFirstName method returns the first name of the player.
     * @return the first name of the player
     */
    public String getFirstName() {
        return this.firstName;
    } // end method getFirstName

    /**
     * The getPointsScored method returns the points scored by the player.
     * @return number of points scored by the player
     */
    public int getPointsScored() {
        return this.pointsScored;
    } // end method getPointsScored

    @Override
    public String toString() {
        return this.firstName + " " + this.lastName + ":\t";
    } // end toString

    public int compareTo(Object o) {
        PlayerStats c = (PlayerStats) o;
        int nameCompare = lastName.compareTo(c.lastName);
        return nameCompare != 0 ? nameCompare : lastName.compareTo(c.lastName);


    } // end compareTo
} // end class Player

One of the sport classes (Polymorphism and all that means I shouldn't need to post the others, right?):

package cs241project2;

import java.util.Scanner;

/**
 * @author 24x24
 */
public class Soccer extends PlayerStats {

    private int assists;
    private double penaltyKickRate;

    /**
     * The Player constructor creates a player based on their first name,
     * last name, points scored, assists made, and the penalty kick rate. Basic
     * mutators are used to construct the object. It requires strings of the
     * first and last name, integers for points scored and assists made, and
     * a double for the penalty kick rate.
     * @param lastName the last name of the player
     * @param firstName the first name of the player
     * @param pointsScored the points scored by the player
     * @param assists the assists made by the player
     * @param penaltyKickRate penalty kick rate of the player
     */
    public Soccer(String lastName, String firstName, int pointsScored, int assists, double penaltyKickRate) {
        super(lastName, firstName, pointsScored);
        setAssists(assists);
        setPenaltyKickRate(penaltyKickRate);
    } //end constructor Player

    public Soccer() {
    } // end of basic constructor
    
    
    
    // ------------------
    // Methods
    // ------------------

    @Override
    public void getValuesFromConsole(Scanner input) {

        super.getValuesFromConsole(input);
        System.out.println("Please enter the number of assists for " + super.getFirstName() + " " + super.getLastName() + ":  ");
        assists = input.nextInt();
        while (assists < 0){
            System.out.println("Please enter a non-negative number: ");
            assists = input.nextInt();
        }
        System.out.println("Please enter the penalty kick percentage (example 0.25 for 25%) for " + super.getFirstName() + " " + super.getLastName() + ":  ");
        penaltyKickRate = input.nextDouble();
        while (penaltyKickRate < 0){
            System.out.println("Please enter a non-negative number: ");
            penaltyKickRate = input.nextInt();
        }
    } // end method getValuesFromConsole

    @Override
    public String confirmPlayerAdd() {
        return "** PLAYER ADDED **\n " + super.getFirstName() + " " + super.getLastName() + "\tPoints: "
                + super.getPointsScored() + "\tAssists: " + assists + "\tPenalty Kick %: "
                + penaltyKickRate + "\n";
    } // end method confirmPlayerAdd

    /**
     * The private method setPenaltyKickRate is used by the Soccer
     * constructor as a mutator method to set the penalty kick rate of the
     * player. A double for the penalty kick rate (as a percentage) is
     * required by the method.
     * @param penaltyKickRate the rate of successful penalty kicks
     */
    private void setPenaltyKickRate(double penaltyKickRate) {
        this.penaltyKickRate = penaltyKickRate;
    } // end method setPenaltyKickRate

    /**
     * The private method setAssists is used by the Soccer
     * constructor as a mutator method to set the assists made by the player.
     * An integer for the amount of assists made is required by the method.
     * @param assists the amount of assists made by the player
     */
    private void setAssists(int assists) {
        this.assists = assists;
    } // end method setAssists

    /**
     * The getAssists method returns the assists made by the player.
     * @return number of assists made by the player
     */
    public int getAssists() {
        return this.assists;
    } // end method getAssists

    /**
     * The getPenaltyKickRate method returns the penalty kick rate of the
     * player.
     * @return penalty kick rate of the player, in the form of a decimal
     */
    public double getPenaltyKickRate() {
        return this.penaltyKickRate;
    } // end method getPenaltyKickRate

    @Override
    public String toString() {
        return super.toString() + "Points: " + super.getPointsScored()
                + "   Assists: " + getAssists() + "   Penalty Kick %: "
                + getPenaltyKickRate();
    } // end toString method
} // end class Soccer

I'll be working on this all day being that it is due tonight so I will post if I have any results. I do have an exam in the middle of the day but I will get back to the code right after that. Thanks for any and all help that you can give. Also if you do need to see the paintball and baseball classes I can post those but all I did with those is change what stat it asked for. I figured I could save some space without repeating code.

Recommended Answers

All 12 Replies

TOOOOOO much code to go thru.
Can you make a small program that demonstrates the problem you are having and that executes so we can compile and execute it to see the problem and help you find a fix.

Hey sorry about the massive amount of code. If I hadn't given all of that the first reply would have been something about not doing my homework for me or asking for code so I figured I would just post most of it. The portion I am having issues with for the loading implementation is in main at 197:

public static void load (Scanner keyboard) throws IOException{
                String fileName = null;
 
        System.out.println("Please enter a file name: ");
        fileName = keyboard.nextLine().trim();
 
        // http://download.oracle.com/javase/tutorial/essential/io/
        // I thought this would be somewhat of how I should be doing it.
        // Not very much help
 
        // error checking for file name
        // Needs to be better and have exception
        if (fileName == null) {
            System.out.println("File not found. Please choose an available file.\n");
            fileName = keyboard.nextLine().trim();
        }
        System.out.println("Loading...");

This part, from my understanding, needs to have an IO buffered reader that goes over the txt file and makes players out of that. The Professor said that we will probably need to change the player constructor to something like this:
String playerInfo = “Jane Doe: Points: 4 Assists: %: 0.25”);
SoccerPlayer player = new SoccerPlayer(playerInfo)
And then I'm assuming the players would be on a new line and then somehow the buffered reader will parse through that and know whats going on?

The second issue is kind of why I posted so much code. We have to make our code "Bulletproof" with exceptions. If there is a user entry that asks for numbers, it has to take only numbers, and only numbers that make sense. No negatives when asking for a score, no symbols, no letters. Same for the names which I think will be even harder: Only letters, apostrophes, and hyphens. These should all fail gracefully by using an exception to ask the user to re-enter using the proper parameters. I think that because most of the code is fairly similar this should be about two exceptions copied over and over and then tweaked. I have started trying to catch an unchecked exception in player stats which is probably the wrong way because it is definitely not working. If somebody could show me what I'm doing wrong here I could probably be fine for the rest of it. My experiments with trying this:

try {
            pointsScored = input.nextInt();
 
            while (pointsScored < 0) {
                System.out.println("Please enter a non-negative number: ");
                pointsScored = input.nextInt();
            }
        } catch (RuntimeException e) {
            System.out.println("Please enter a number: ");
            // pointsScored = input.nextInt();
        }
 
        //***********************
        while (input.hasNextLine()) {
            try {
                if (pointsScored < 0) {
                    System.out.print("Please choose a positive number: ");
                } else { /* Do stuff */ }
            } catch (NumberFormatException e) {
                pointsScored = 0;
            }
        }
        //***********************
 
    }

These have thus far only given me errors pointing to an inputMismatchedException on line 46 which is what I thought I was trying to catch. It's a runtime exception though so it might not work this way.
Thanks again for taking a look and trying to help me out.

needs to have an IO buffered reader that goes over the txt file and makes players out of that

Where is your code for doing this?

To help us, write a small program that demonstrates the problem you are having and that executes so we can compile and execute it to see the problem and help you find a fix.

Sorry for the delay, I had an exam that took entirely too long. The code that I have for the loading section is as follows:

public static String load(Scanner keyboard) throws FileNotFoundException {
        System.out.print("Enter the file path: ");
        String filePath = keyboard.nextLine();
        String text = "";
        File file = new File(filePath);
        Scanner fileScanner = new Scanner(file);
        while (fileScanner.hasNext()) {
            System.out.println("Loading...");
            text = fileScanner.nextLine();
            //Print out confirmation of file loaded
            System.out.println("The contents of the have been loaded succesfuly.\n");
        }
        return text;}

I was asking if I need to use an IO buffered reader or not and if so how would I do that. I still can't figure out how to make it take the contents of the file and make players out of it.

The second portion is sort of similar in that I don't know how to do the exception handling so I don't really know how to write that portion of the code. If I had enough know-how to write a small program that executes and handles the exceptions then I would probably be able to write my big program to handle exceptions. The exception handling code that I have written is what I have written above. This is my only working knowledge of exceptions and it isn't working and that is why I was asking for some help. I wrote it to catch a runtime exception and it didn't do that so I was asking if this was how it should be done, if I was missing a step, or if I was just plain doing it wrong. This is the two different ways I have tried to handle an exception that occurs when a letter is entered instead of a number (InputMismatchException):

try {
            pointsScored = input.nextInt();
 
            while (pointsScored < 0) {
                System.out.println("Please enter a non-negative number: ");
                pointsScored = input.nextInt();
            }
        } catch (RuntimeException e) {
            System.out.println("Please enter a number: ");
            // pointsScored = input.nextInt();
        }
 
        //***********************
        while (input.hasNextLine()) {
            try {
                if (pointsScored < 0) {
                    System.out.print("Please choose a positive number: ");
                } else { /* Do stuff */ }
            } catch (NumberFormatException e) {
                pointsScored = 0;
            }
        }
        //***********************
 
    }

I just need to know if this is completely off or how I should tweak it. I'm not asking for my code to be written for me but I also don't know enough to know where I'm going wrong. Like I said in my first post, I have looked and can't find the answers to this and that is why I came here.
Thanks in advance for any help you feel like giving me.

if I need to use an IO buffered reader or not

Probably not. The Scanner class should work for reading lines from a file.

how to make it take the contents of the file and make players out of it.

Does your code read all of the lines of the file? Your printlns in side the loop do not show what was read.
How many times does the following print:

System.out.println("The contents of the have been loaded succesfuly.\n");

To make players from the lines read, parse the lines to get the items to make a player and use the new statement to create a player with those items passed to the constructor.

The stuff within the loop doesn't print. I mostly put that stuff in a bit early as placeholders but I think the while loop is wrong so that might be the issue. It looks like while(fileScanner.hasNext()) is not cooperating. I thought maybe it was just because I didn't have it going anywhere that maybe it wasn't completing but I guess it should be printing those 2 statements at some point.

I did get it to work with an exception handler but it only works the once. I put a try catch up in the menu operand choices in main to catch the FileNotFoundException and then I have it calling the load option again. If you enter the wrong file twice though, it crashes.

} else if (menuOperation.equalsIgnoreCase("LOAD")) {
                try{load(keyboard);
                }catch (FileNotFoundException e){
                    System.out.println("You have entered an invalid file path.\n"
                            + "Please try again.\n");
                    load(keyboard);
                }
                
            }

Ok I lied. If I have a file that's not a pdf ( I wasn't paying attention to my file path) it does work. I saved a file with a soccer player in it and loaded that file. In the debugger it looked like it loaded each line of the file (which in the manner I have it formatted it will be loading ***SOCCER PLAYERS*** as a player). The output was:

What operation next? (ADD, REMOVE, SHOW, SAVE, LOAD, SORT, QUIT)?
load
Enter the file path: /home/24x24/Dropbox/NetBeansProjects/Project2/CS241project2/test1
Loading...
The contents of the file have been loaded succesfuly.

Loading...
The contents of the file have been loaded succesfuly.

Loading...
The contents of the file have been loaded succesfuly.

Loading...
The contents of the file have been loaded succesfuly.

What operation next? (ADD, REMOVE, SHOW, SAVE, LOAD, SORT, QUIT)?

So the loop works, I need to take out the loaded successfully part and move it outside of the loop. How would I go about parsing it so that it will avoid the soccer players and averages and stuff like that? Or will I need to make it format a different way?

How would I go about parsing it so that it will avoid the soccer players and averages

"avoid"? Not sure what you mean.
What info do you want to get from the file and put into the player object?
Answering that should show you what to do.

Who creates the file? What info does it have? What info do you want to get into the program? I can't answer these questions.

From the code I have written so far I have each player type separated and I also have the averages of the group of players at the bottom of each type so if it were to parse through the file can I have it check to see if the string will work as a player and avoid the rest? The only reason I have that stuff in is that it was part of the assignment:

** SOCCER PLAYERS **
jane doe: Points: 4 Assists: 3 Penalty Kick %: 0.34
// There would be more players if entered but this is just an example of how its formatted
Total Records: 1
AVERAGES Points: 4.0 Assists: 3.0 Penalty Kick %: 0.34

can I have it check to see if the string will work as a player and avoid the rest?

yes if you can recognize the one part from the other, you should be able to avoid the parts you don't want.

OK so this is where I am going with this. Let me know if I'm on the right path:

public static String load(Scanner keyboard) throws FileNotFoundException {
        System.out.print("Enter the file path: ");
        String filePath = keyboard.nextLine();
        String text = "";
        File file = new File(filePath);
        Scanner fileScanner = new Scanner(file);
        while (fileScanner.hasNext()) {
            System.out.println("Loading...");
            text = fileScanner.nextLine();
            // Parse the player here
            boolean contains = text.contains("** "); 
    if (contains == false){
        text.split("\t");
         PlayerStats player = new Soccer(); // Needs to differentiate between types
            player.getValuesFromConsole(keyboard); // This would need changed to being pulled in from text
            team.add(player);
        
    }
        }
        System.out.println("The contents of the file have been loaded succesfuly.\n");
        return text;}

I made the boolean contains look for any line that starts with "** " so any of the parts that aren't players can be skipped. If those aren't in the line then it should go into the loop that creates a new player. I'm still kind of foggy on how this should work though so it might take me a few tries before I get that going. I am using text.split with the regex of a tab for a delimiter to grab tokens for the player constructor. I'll keep at it but I'm not sure if I'm on the right path.

Some comments on the code:
You don't need to use a boolean to remember something to the next statement.
You could code the test directly in the if statement. The false test is done by using the NOT symbol: !text.contains(...)

Read the API doc for the the split() method does. You are not using it correctly.

There are several ways to get the data from the file to the object:
1) let the object read the file - I think this is the worst one. What to do with an error in the input data.
2) Read a line and pass that to the object - This could have to detect an error and throw an exception if the data is bad
3) Read a line, parse it and put the items in a constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.