Question: I need help, I don't know what's going with line 40 in my code but its messing everything up. My code is copy and pasted
I need help, I don't know what's going with line 40 in my code but its messing everything up. My code is copy and pasted below and the instructions are also there.
My Code
~~~~~~~~
package ishod_lab5;
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner;
/** * * @author donovanisho */ public class IshoD_Lab5 {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here ArrayList
Scanner fileScanner;
try { fileScanner = new Scanner(new File("monday.txt"));
} catch (FileNotFoundException e) { System.out.println("Input file monday.txt couldn't be accessed!, Exiting..."); e.printStackTrace(); return; }
while (fileScanner.hasNextLine()) { String[] data = fileScanner.nextLine().strip().split(" "); // System.out.println(Arrays.asList(data)); degree.add(data[0]); grade.add(Double.parseDouble(data[1])); } fileScanner.close();
System.out.println(" Degree\tGrade");
int i = 0; while (i
double csSum = 0; double itSum = 0; int csCount = 0; int itCount = 0;
i = 0;
while (i
} else if (degree.get(i).equalsIgnoreCase("IT")) { itSum += grade.get(i); ++itCount; } ++i; }
System.out.printf(" Average grade is for CS is %.2f ", csSum / csCount); System.out.printf("Average grade is for IT is %.2f ", itSum / itCount); } }
~~~~~~~~~~~

lab5.txt
~~~~~~~
3 CS 3.5 CS 3 IT 3.9 CS 3.3 CS 3.5 CS 3.4 CS 3.9 IT 3.1 CS 3.3 CS 1.3 CS 3.3 IT 3 IT 3.3 CS 3 IT 3.7 CS 3.7 CS 1.6 CS 3.1 CS 3.4 CS 3.3 IT 3.3 IT 1.3 CS 3.3 CS 3.1 CS 1.6 CS 3.9 IT 3.9 CS 3.3 CS 1.7 IT 3.8 CS 3.8 IT 3.8 CS 3.9 CS 3.8 IT 3.7 CS 3.9 IT 3.8 IT 3.7 CS 3.8 CS 3.3 CS 3.4 IT 1.1 CS 1.8 IT 3.7 CS 3.1 CS 3.3 CS 3.4 IT 3.9 IT 3.9 CS 3.5 IT 3.3 IT 3.5 IT
~~~~~~~~~
Instructions First download the file called labs.txt and add it to your project as shown in the videos Write a program that does the following: 1) Open the file for input. a) Create 2 ArrayLists. i) The first ArrayList will hold the student degree which is a String ii) The second ArrayList will hold the student grade which is a double b) Use a while loop to input 2 pieces of data at a time from the file (Open monday.txt to see how it's formatted). Each line represents a single student. i) The student grade which is a double. (1) Add it to the student grade ArrayList ii) The student degree which is "IT" or "CS" (1) Add it to the student degree ArrayList 2) After you fall out of the while loop a) close the file b) Output a string to indicate what each column holds c) Use another while loop to print out the information for each student on a single line from the two ArrayLists. (Your while loops will be based on the size of the Arraylist as shown in the Chapter 5 video and the Chapter 5 - More ArrayList Examples video.) d) Example Output Degree Grade CS 3.0 CS 3.5 -T 3.0 CS 3.9 CS 3.3 3.5 CS 3.4 3) After you fall out of the for loop use a while loop to loop through the all the degrees stored in the student degree ArrayList (Your while loops will be based on the size of the Arraylist as shown in the Chapter 5 video and the Chapter 5 - More ArrayList Examples video.) a) Inside the while loop write an if block using the degree as an expression to compare against i) if degree is "CS" add the grade from the student grade ArrayList to a Cs sum, and increment a counter for the number of CS students ii) if degree is "IT" add the grade from the student grade ArrayList to a IT sum, and increment a counter for the number of IT students b) When the loop finishes print out average CS grade and average IT grade c) Example output Average grade is for CS is 3.2 Average grade is for it is 3.3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
