Write a program that takes two integers as input from the keyboard, representing the number of hits and the number of at-bats for a batter in baseball. Calculate the batter’s hitting percentage and print it, then check if the hitting percentage is above 0.300. If it is, output that the player is eligible for the All Stars Game, otherwise, output that the player is not eligible.
Sample Input
Enter number of hits > 10
Enter number of at-bats > 40
Sample Output
Batters hitting percentage is : 25%
The player is not eligible for the All Stars Game
import java.util.Scanner;
public class Baseball {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.print("Enter number of hits > ");
int numberOfHits = in.nextInt();
System.out.print("Enter number of at-bats > ");
int numberOfAtBats = in.nextInt();
double hittingPercentage = (double) numberOfHits/(double) numberOfAtBats;
double goodPercentOfHitting = 0.300;
if((hittingPercentage)>goodPercentOfHitting){
System.out.println("Batters hitting percentage is : "+hittingPercentage*100+"%.");
System.out.println("The player is eligible for the All Stars Game.");
}
else{
System.out.println("Batters hitting percentage is :"+hittingPercentage*100+"%.");
System.out.println("The player is not eligible for the All Stars Game.");
}
in.close();
}
}
Comments
Leave a comment