As an exercise, I wanted to write a little application of my own imagination. I thought I would do something to calculate On Base Percentage (times reached base / plate appearances).
I'm having a hard time figuring out on to deal with the FLOAT output so that it comes out as something like .450 instead of some weird crap.
Any pointers would be appreciated.
Here is my latest attempt (of many) to get it:
import java.util.*;
public class CalcOBP { int plateAppearances; int reachBase;
public float CalcOBP(String inPlateAppearances, String inReachBase) { float result = (Float(inReachBaseF) / Float(inPlateAppearancesF)); return (float)result; }
public static void main(String[] arguments) { CalcOBP cal = new CalcOBP(); float reachBase = Float.parseFloat(arguments[0]); float plateAppearances = Float.parseFloat(arguments[1]); System.out.println("This Batter's OBP is: " + cal); } }
Hi, i think u can use in the NumberFormat class of java.text package for this.. u can limit the fraction digits to be displayed after the calculation..