Answer to Question #312825 in Java | JSP | JSF for rose

Question #312825

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

 


1
Expert's answer
2022-03-16T18:31:42-0400
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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS