// Scott DeRuiter 9/22/2002 // Slug.java // User inputs the number of at-bats, singles, doubles, triples and home runs. // Calculates the batting average and the slugging percentage. // 7/15/2011 - Greenstein: Changed TextReader to Scanner import java.util.Scanner; public class Slug { public static void main ( String [] args ) { int atbats, singles, doubles, triples, homeruns = 0; double batting, slugging = 0.0; Scanner keyinput = new Scanner ( System.in ); System.out.print ( "\n\n\nNumber of at-bats (excluding walks) -> " ); atbats = keyinput.nextInt ( ); System.out.print ( "Number of singles -> " ); singles = keyinput.nextInt ( ); System.out.print ( "Number of doubles -> " ); doubles = keyinput.nextInt ( ); System.out.print ( "Number of triples -> " ); triples = keyinput.nextInt ( ); System.out.print ( "Number of home runs -> " ); homeruns = keyinput.nextInt ( ); batting = (double)( singles + doubles + triples + homeruns ) / (double)atbats; slugging = (double)( singles + 2 * doubles + 3 * triples + 4 * homeruns ) / (double)atbats; System.out.println ( "\n\nHere are your stats" ); System.out.println ( "Batting Average: " + Format.right ( batting, 8, 3 ) ); System.out.println ( "Slugging Percentage: " + Format.right ( slugging, 8, 3 ) + "\n\n\n"); } }