import java.util.Scanner;import java.io.*;/** * Class ChiefsRoster processes last names, uniform numbers, and weights * from a given comma delimited data file. * @author First Last */public class...

import java.util.Scanner;import java.io.*;/** * Class ChiefsRoster processes last names, uniform numbers, and weights * from a given comma delimited data file. * @author First Last */public class ChiefsRoster{ public static void main(String[] args) throws IOException { final int MAX_ROSTER_SIZE = 100; Scanner inFile = openFile("ChiefsRoster.txt"); // Allocate arrays to hold roster data and then get the data String[] lastNames = new String[MAX_ROSTER_SIZE]; int[] numbers = new int[MAX_ROSTER_SIZE]; int[] weights = new int[MAX_ROSTER_SIZE]; int numPlayers = getRosterData(inFile, lastNames, numbers, weights); inFile.close();

// Display the average player weight System.out.printf("Average player weight: %.2f lbs.%n", getAverageWeight(weights, numPlayers)); // Find the last names of all players whose weights lie // within a given range. Scanner input = new Scanner(System.in); System.out.println("Find players with weights in a given range."); System.out.print("Low weight: "); int lowWeight = Integer.parseInt(input.nextLine()); System.out.print("High weight: "); int highWeight = Integer.parseInt(input.nextLine()); input.close(); String[] namesInWeightRange = getNamesInWeightRange(lowWeight, highWeight, lastNames, weights, numPlayers); // Display the last names of the players just found int i = 0; while (i { System.out.println(namesInWeightRange[i]); ++i; }

// Sort the player arrays based upon uniform number // and then store that data to a comma delimited file. sortByNumber(lastNames, numbers, weights, numPlayers); storeData("PartialChiefsDataByNumber.txt", lastNames, numbers, weights, numPlayers); System.out.println("Roster processing complete.");

} // end Main

/** * openFile attempts to open an input file specified by the user. The * application exits with an error code of 1 if the input file could not * be opened. * @param fileName The name of the input file to open * @throws IOException * @return a reference to an opened input file stream (Scanner) */ public static Scanner openFile(String fileName) throws IOException { // Check if the file exists and exit if it does not File file = new File(fileName); if (!file.exists()) { System.out.println("File open error: " + fileName); System.exit(1); }

// Return a reference to the opened input stream return new Scanner(file); } // end method

/** * getRosterData reads player last names, uniform numbers, and weights * from inFile and stores the data in a parallel manner into the given * arrays. * @param inFile References the opened input file. * @param lastNames An array that will hold the player last names * @param numbers An array that will hold the player uniform numbers * @param weights An array that will hold the player weights * @precondition The arrays contain enough elements to hold the number of * players read. * @throws IOException * @return The number of players read from the file. */ public static int getRosterData(Scanner inFile, String[] lastNames, int[] numbers, int[] weights) throws IOException { // Skip the header (COMPLETED) inFile.nextLine(); // Read in the players

return 0; // 0 only used to get the program to build } // end method

/** getAverageWeight determines the average weight of all players * @param weights An array of player weights * @param numPlayers The number of weights in the array * @return The average weight */ public static double getAverageWeight(int[] weights, int numPlayers) { return 0.0; // 0.0 only used to get the program to build } // end method /** * getNamesInWeightRange finds the names of all players whose weights are in * the inclusive range [lowWeight, highWeight] * @param lowWeight The lower bound of the range of weights * @param highWeight The upper bound of the range of weights * @param weights An array containing player weights * @param lastNames An array containing player names * @param numPlayers The number of players * @return An array containing the last names of all players whose weights * fall within the given weight range. */ public static String[] getNamesInWeightRange(int lowWeight, int highWeight, String[] lastNames, int[] weights, int numPlayers) { return null; // null only used to get the program to build } // end method /** * sortByNumber will sort data in the arrays according to the player's * uniform number * @param lastNames An array of player last names * @param numbers An array of player uniform numbers * @param weights An array of player weights * @param numPlayers The number of players */ public static void sortByNumber(String[] lastNames, int[] numbers, int[] weights, int numPlayers) { } // end method /** * storeData writes each player last name, uniform number, and weight to * individual lines in the file. The data is comma-delimited, and the file * contains an initial header line of "Last,#,WT" * @param fileName The name of the file that will store the data * @param lastNames An array of player last names * @param numbers An array of player uniform numbers * @param weights An array of player weights * @param numPlayers The number of players * @throws IOException */ public static void storeData(String fileName, String[] lastNames, int[] numbers, int[] weights, int numPlayers) throws IOException { } // end method
} //end class
Oct 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here