Question: I am asked to print out a 2d array given a text file students.txt. The text file has names of students and test grades. The

I am asked to print out a 2d array given a text file students.txt. The text file has names of students and test grades. The program is asked to split each and put onyl the grades into a 2d array. The following is what I have written so far. activity 1 and 2 are needed but i can manage two if I can split the lines of each file into two strings and use them in number 2 later

import java.io.*; import java.util.*; import java.util.Arrays;

public class myIO { /**************************************************************************** * Activity 2: * This method takes the name of a file as input. * It reads a file formatted like students.txt (provided to you): * This file contains several lines: each line starts with the name of * a student (last followed by first) * and continues with a list of their grades * Each line contains the same number of grades * You have to create one array from it: * an array of integer grades (2D array: n lines and p columns, p being the number of grades per student) ****************************************************************************/ public static int[][] readGradesFromFile(String fileName) throws FileNotFoundException, IOException { int[][] grades = new int [5][4] ; FileReader fr = new FileReader("students.txt"); BufferedReader textReader = new BufferedReader(fr); String line = textReader.readLine(); String[] grade = line.split(" "); int[] someInt = Integer.parseInt(grade[]); for(int i = 0; i < grades.length ; i++) { for(int j = 2; j

/**************************************************************************** * Main method in which the above methods are tested ****************************************************************************/ public static void main(String[] args) throws FileNotFoundException, IOException {

int[][] GradesArr = readGradesFromFile("students.txt"); } }

this is the file contents

Diner Dylan 34 76 99 100 Basillas Bertha 98 96 78 89 Aranca Alberto 74 90 99 45 Estacion Esther 87 90 76 101 Castillo Carlos 76 45 67 86.

I

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!