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

I have a question involving arrays in Java. I am supposed to writea program that

ID: 3618069 • Letter: I

Question

I have a question involving arrays in Java. I am supposed to writea program that prints a table showing a baseball player'sidentification number, batting average, and number of walks. We aregiven a text file with 25 stats (some player's have multiple stats)in this form:

3 2 1 1

This indicates that during a game player number 3 had two hits, onewalk, and one out. The batting average is computed by taking thenumber of hits and dividing it by the number of hits and outs addedtogether. I am pretty sure I need to use a two dimensional arrayfor this. If so, how would I go about adding the hits and outstogether per row, and then divide that sum by the hits?

For instance if it was 3 2 1 1... I would end up with a total of 3times at bat; if it was 4 2 1 2... I would end up with a total of 4times at bat.

Please help!!

Explanation / Answer

importjava.util.*; import java.io.*; public class baseball { publicstatic void main(String[]args) { try{ Scanner inputFile = new Scanner(newFile("input.txt")); //25 rows, 4 columns. int[][] stats = new int[25][4]; for(int i= 0; i