Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use jGrasp for Java. if..else Exercise 1 : Batting Average and All Star G

ID: 664121 • Letter: P

Question

Please use jGrasp for Java.

if..else Exercise 1 : Batting Average and All Star Game

Write a Java program that accepts two integers from the user representing the number of hits and number of at-bats for a baseball player. Your program should calculate and display the player's hitting percentage. Your code should also check to see if the players hitting percentage is above or equal to 0.300 and display a message indicating the player is eligible for the all-star game if this is the case. If the percentage is below 0.300, display a message wishing the player better luck next year.

This is a Java test program and all the code should be written in a main method.

Explanation / Answer

working code:

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
             float hits,atbat;
             float per;
             Scanner in = new Scanner(System.in);
           hits = in.nextInt();
           atbat = in.nextInt();
           per=hits/atbat;
           if (per > 0.3)
           System.out.println("the player is eligible for the all-star game");
           else
           System.out.println(" better luck next year");
          
   }
}

compiled on ideone

http://ideone.com/5j3dnr