/**
 * 7/5/11
 * Demonstrates simple static method usage using pitching statistics.
 * @author cortney
 */

import java.util.*;

public class Pitching {

    
    public static void main(String[] args) {

        // variables
        int walks, hits, ks, earnedRuns;
        double whip, era, kToBB, kTo9, innings;
        Scanner stdin = new Scanner(System.in);

        // Get pitching info from user
        System.out.println("Enter pitcher innings: ");
        innings = stdin.nextInt();
        System.out.println("Enter pitcher walks: ");
        walks = stdin.nextInt();
        System.out.println("Enter pitcher hits: ");
        hits = stdin.nextInt();
        System.out.println("Enter pitcher strikeouts: ");
        ks = stdin.nextInt();
        System.out.println("Enter earned runs: ");
        earnedRuns = stdin.nextInt();

        //print stat header information
        printHeader();

        // calculate derivative stats
        whip = getWHIP(walks, hits, innings);
        era = getERA(innings, earnedRuns);
        kToBB = getKtoBB(ks, walks);
        kTo9 = getKto9(ks);

        //print stats calculated
        printStatLine(walks, hits, ks, innings, earnedRuns,
                whip, era, kToBB, kTo9);

    }

    //Prints the header for pitching stat information
    private static void printHeader() {
        System.out.flush();
        System.out.println("\nDerived Stats");
        System.out.println("      IP       H      ER      BB       K    K/BB"
                + "     K/9    WHIP     ERA");
    }

    // calculates the Walks and hits per inning pitched
    private static double getWHIP(int walks, int hits, double innings) {
        double mywhip = (walks + hits)/innings;
        return mywhip;

    }

    // calculates earned run average
    private static double getERA(double innings, int earnedRuns) {
        double myera = (earnedRuns/innings*9);
        return myera;
    }

    // calculates the strike-outs to walks ratio
    private static double getKtoBB(int ks, int walks) {
        return (double) ks/walks;
    }

    // calculates the strike-outs per game
    private static double getKto9(int ks) {
        return (double) ks/9.0;
    }

    // prints the stats calculated
    private static void printStatLine(int walks, int hits, int ks, 
            double innings, int earnedRuns, double whip, double era,
            double kToBB, double kTo9) {

        System.out.format("%8.2f%8d%8d%8d%8d%8.2f%8.2f%8.2f%8.2f",
                innings,hits,earnedRuns,walks,ks,kToBB,kTo9,whip,era);

    }

}
