private String name private String position private int numA

private String name;

private String position;

private int numAtBats;

private int numSingles;

private int numDoubles;

private int numTriples;

private int numHomeRuns;

private double battingAverage;

6.Write a toString method that returns the player\'s name, position and batting average formatted to have 1 digit

to the left of the decimal and 3 digits to the right of the decimal. Assume DecimalFormat has been imported.

Solution

public String toString( )
{
DecimalFormat df = new DecimalFormat(\"0.000\");
return name + \"\\t\" + position + \"\\t\" + df.format(battingAverage);
}

private String name; private String position; private int numAtBats; private int numSingles; private int numDoubles; private int numTriples; private int numHome

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site