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

[Java] 1. Write a public static method that takes a String as a parameter and re

ID: 3711976 • Letter: #

Question

[Java]

1. Write a public static method that takes a String as a parameter and returns an int. The input String will be the name of a csv file in the format "similiar, proper, profound, abroad, visible, developing", where all values are well-formed integers. There is no header in this file. This method will return the sum of the values in the "profound" column as an int

I want to do this without using the scanner class, as I will just enter the file's name in the main method. Thank you to whoever helps!!

Explanation / Answer

import java.io.*; public class ReadCSVFile { public static int totalProfound(String fileName) { int total = 0; try { BufferedReader br = new BufferedReader(new FileReader(new File(fileName))); String line; String[] words; while ((line = br.readLine()) != null) { words = line.split(","); total += Integer.parseInt(words[1].trim()); } br.close(); } catch (IOException e) { e.printStackTrace(); } return total; } }

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