/****************************************************************************** * This program computes NFL passer ratings. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ import org.pureprogrammer.Utils; public class FootballPasserRating2 { public static void main(String[] args) { try { String inputStr; int attempts; inputStr = Utils.prompt("Number of attempts: "); attempts = Integer.parseInt(inputStr); int completions; inputStr = Utils.prompt("Number of completions: "); completions = Integer.parseInt(inputStr); int touchdownPasses; inputStr = Utils.prompt("Number of touchdown passes: "); touchdownPasses = Integer.parseInt(inputStr); int interceptions; inputStr = Utils.prompt("Number of interceptions: "); interceptions = Integer.parseInt(inputStr); int passingYards; inputStr = Utils.prompt("Number of passing yards: "); passingYards = Integer.parseInt(inputStr); int which; inputStr = Utils.prompt("1 for NFL or 2 for NCAA: "); which = Integer.parseInt(inputStr); if (which == 1) { final double a = (completions / (double)(attempts) - 0.3) * 5.; final double b = (passingYards / (double)(attempts) - 3.) * 0.25; final double c = touchdownPasses / (double)(attempts) * 20.; final double d = 2.375 - (interceptions / (double)(attempts) * 25.); final double RATING = (a + b + c + d) / 6. * 100.; System.out.println(Utils.format("NFL Passer rating: {0:.1f}", RATING)); } else { final double a = 8.4 * passingYards; final double b = 330. * touchdownPasses; final double c = 100. * completions; final double d = 200. * interceptions; final double RATING = (a + b + c - d) / attempts; System.out.println(Utils.format("NCAA Passer rating: {0:.1f}", RATING)); } } catch (NumberFormatException ex) { System.out.println(Utils.join("", "Bad input! ", Utils.exceptionMessage(ex))); } catch (Exception ex) { System.out.println("Don't know what went wrong!"); } } }