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

Can you help me write this program using Java? This is for Introduction to Compu

ID: 3863127 • Letter: C

Question

Can you help me write this program using Java? This is for Introduction to Computer Science class and we use Java. I'm having trouble converting because the 2D array has more than one data type and I don't know how to convert into an int type array that consists only of the scores. I used split(","). Please keep in mind this is an introductory level class and please comment your code. I want to use throws IOException NOT try/catch. This is the file "grades.csv". It contains a list of students and their exam grades:

Arthur Albert,74%
Melissa Hay,72%
William Jones,85%
Rachel Lee,68%
Joshua Planner,75%
Jennifer Ranger,76%
Richard Rock,80%
Jerry Rose,80%
Dorothy Smith,76%
Jon Smith,60%
Lisa Smith,90%
Michael Stone,13%
Josephine Trenton,75%
Franklin Williams,58%

Write a program in Java that reads in the file and computes the average grade for the class and then prints it to the console.

Explanation / Answer

import java.io.*; class Student{ public static void main(String args[]) throws IOException { String line = "", mark = null; Float sum = 0.0f, averagePercentage; int count=0; //Provide fully qualified path of your csv file here. String file = "grades.csv"; //Reading File BufferedReader br = new BufferedReader(new FileReader(file)); while((line = br.readLine())!= null){ //We are assigning each row in the students array i.e. student name and his/her percentage String[] students = line.split(","); //We are checking this condition because if we get any blank or null value in percentage column, then our program will throw an ArrayOutOfBound Exception which is handled by this line. mark = (students.length > 1) ? students[1].trim() : null; if(mark != null) { //mark.substring(0, (mark.length() - 1)) will trim the percentage sign from the percentage. We are doing this because percentage is of String type. // //And then we have parsed the string into float. Since we can have percentage in decimal value as well. sum = sum + Float.parseFloat(mark.substring(0, (mark.length() - 1))); //Since average is calculated by sum/total occurance thats why we are increasing counter everytime we are getting a row count++; } } averagePercentage = sum/count; System.out.println("Average percentage of student is: "+averagePercentage); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote