/**
* Given a quarterback's yards gained, passing attempts, and
* interceptions, computes his Pass Efficiency Rating.
*
* @author Jim Glenn
* @version 0.1 9/8/2003
*/
public class PassEfficiencyRating
{
/**
* Computes a quaterback's PER. Inputs for yards, attempts,
* and interceptions are hard-coded.
*
* @param args ignored
*/
public static void main(String[] args)
{
// declare and initialize the inputs
int yards = 200;
int attempts = 20;
int interceptions = 3;
// compute PER
double per = (double)(yards - interceptions * 40) / attempts;
// display result
System.out.println("PER = " + per);
}
}
/**
* Given a pitchers's outs recorded and earned runs allowed,
* computes that's pitchers ERA.
*
* @author Jim Glenn
* @version 0.1 9/8/2003
*/
public class ERACalculator
{
/**
* Computes a pitcher's ERA. Inputs for outs and earned runs
* are hard-coded.
*
* @param args ignored
*/
public static void main(String[] args)
{
// declare and initialize the inputs
int outs = 200;
int earnedRuns = 20;
// compute era
double era = earnedRuns / ((double)outs / 27);
// display result
System.out.println("ERA = " + era);
}
}
/**
* Given a pitchers's innings pitched and earned runs allowed,
* computes that's pitchers ERA. Innings pitched are assumed to
* be input in baseball style fractions (so 66.2 instead of 66 2/3).
*
* @author Jim Glenn
* @version 0.1 9/8/2003
*/
public class ERACalculator2
{
/**
* Computes a pitcher's ERA. Inputs for outs and earned runs
* are hard-coded.
*
* @param args ignored
*/
public static void main(String[] args)
{
// declare and initialize the inputs
double innings = 66.2; // meaning 66 2/3
int earnedRuns = 20;
// split innings into whole and fractional parts
int wholeInnings = (int)innings;
int thirdsOfInnings = (int)((innings - wholeInnings) * 10 + 0.5);
int outs = wholeInnings * 3 + thirdsOfInnings;
// compute era
double era = earnedRuns / ((double)outs / 27);
// display result
System.out.println("ERA = " + era);
}
}
This code can also be downloaded from the files PassEfficiencyRating.java, ERACalculator.java, and ERACalculator2.java.