Question: This is my coding: import java.io.*; public class FileWithOneItemPerLine { /** * * Since the Java file i/o classes can cause * i/o exceptions, all
This is my coding:
import java.io.*; public class FileWithOneItemPerLine { /** * * Since the Java file i/o classes can cause * i/o exceptions, all methods that use them must have a * throws clause appended to the method name * * NOTE: * 1. We do not catch the exceptions here -- * no try & catch blocks are used. * 2. readLine() is a method in BufferedReader, while * readNext() is for Scanner class. * 3. Each data consists of 4 lines: * student's name, program, semester and cgpa. * 4. Objective: Find the highest cgpa */ public FileWithOneItemPerLine() throws IOException { String filename = javax.swing.JOptionPane.showInputDialog( "Input student list file name:"); BufferedReader in = new BufferedReader(new FileReader(filename)); double highestCgpa = 0.0; String name = in.readLine(); //readLine(), not nextLine() while (name!= null) { String program = in.readLine(); String sem = in.readLine(); double cgpa = Double.parseDouble(in.readLine()); if (highestCgpa < cgpa) highestCgpa = cgpa; name = in.readLine(); } in.close(); System.out.println("The highest CGPA is " + highestCgpa); } public static void main(String []a) throws IOException { new FileWithOneItemPerLine(); } }
My question is:
I need to write a new program called FileWithOneItemPerLine1 based on the FileWithOneItemPerLine.java class.
The only difference now is that the four variables which make up a single data are written in a single line separated by a semi-colon (';').
So you need to do the following: (a) update the input file (do make a new one and give it a new name) so that this new input file has one data per line, like the following example: Syahirah Rosli;CS245;4;3.44 Amir Hamzah;CS230;6;3.78
Of course, you should have at least 10 data for this file
(b) update the code so that it reads 4 variables and thus one data per line. Using the String split() method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
