import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; /* Java application that computes an NFL passer rating, given the relevant ** input, which is provided by the user in response to a sequence of prompts. ** (If a command line argument is provided, input is read from the file that ** it names.) ** ** Authors: R. McCloskey and < STUDENT's NAME > ** Collaborated with: ... ** Known defects: ... */ public class PasserRatingNFL { private static Scanner input; // For reading input private static boolean echo; // true iff input should be printed public static void main(String[] args) { // Establish a Scanner that reads from the keyboard (unless there is a // command line argument, in which case it reads from the file it names). establishScanner(args); // Display a greeting. System.out.println("Welcome to the NFL Passer Rating application!\n"); // For each input, prompt the user for it, read the response, and // store the response in the corresponding input variable. int attempts = getInt("Enter # of passes attempted:> "); int completions = getInt("Enter # of completed passes:> "); int yards = getInt("Enter # of passing yards:> "); int numTDs = getInt("Enter # of TD passes:> "); int intercepts = getInt("Enter # of passes intercepted:> "); double passRating = passerRating(attempts, completions, yards, numTDs, intercepts); System.out.print("\nNFL Passer Rating: "); // MISSING CODE HERE System.out.println("Goodbye."); } /* Given the relevant raw passing statistics, via its formal parameters, ** computes and returns the NFL passer rating. */ public static double passerRating(int attempts, int completions, int yards, int numTDs, int interceptions) { return 0.0; // STUB } /* Returns the component of the passer rating based upon completion ** percentage (i.e., the completion percentage factor). */ public static double completionPctFactor(int attempts, int completions) { return 0.0; // STUB } /* Returns the component of the passer rating based upon ** yards per pass attempt (i.e., the yards per attempt factor). */ public static double yardsPerAttFactor(int attempts, int yards) { return 0.0; // STUB } /* Returns the component of the passer rating based upon ** touchdown frequency (i.e., the touchdown percentage factor). */ public static double touchdownPctFactor(int attempts, int numTDs) { return 0.0; // STUB } // MISSING METHOD CAN BE PLACED HERE //--------------------------------------------------------------- // DO NOT MODIFY WHAT FOLLOWS!! /* Prints the given prompt, reads the response (assumed to be an ** integer) via the 'input' Scanner, and returns it. If appropriate, ** the response is printed. */ private static int getInt(String prompt) { System.out.print(prompt); int response = input.nextInt(); if (echo) { System.out.println(response); } return response; } /* Binds to global variable 'input' a Scanner object that can read either ** from the keyboard (in case args.length == 0) or, otherwise, from the ** file whose name is args[0]. */ private static void establishScanner(String[] args) { if (args.length == 0) { input = new Scanner(System.in); echo = false; } else { try { String fileName = args[0]; input = new Scanner(new File(fileName)); echo = true; } catch (FileNotFoundException e) { e.printStackTrace(); System.out.println("\nProgram aborting"); System.exit(0); } } } }