I have a file called "results.txt" which has these values inside:
0118210:1801:XDCS1094:A:4
0118210:1801:XDCS2034:B+:4
0118210:1801:XDCS1043:C:3
0118024:1801:XDCS1094:B:4
0118024:1801:XDCS2094:A:4
I want to read the file, make it an array and remove the delimiter and calculate based on the GPA formula. This is my thought of how it should work, but I'm still not so sure because I'm new to programming. I am also trying to display my results on a new line instead of everything in a single line as shown in the image. Any help would be appreciated, it is an assignment.
public void run()
{
try{
do{
found=0;
received = in.readLine();
array2=received.split(":");
if(received.equals("QUIT")) break;
switch(received.charAt(0))
{
case 'R':
Register();
break;
case 'L':
login();
break;
case 'V':
View();
break;
}
}while(!received.equals("QUIT"));
}
catch(IOException e)
{
e.printStackTrace();
}
public void View() throws IOException
{
String grade ="";
in3 = new BufferedReader(new FileReader("results.txt"));
while((result = in3.readLine()) !=null)
{
array4=result.split(":");
if((array2[1].equals(array4[0])) && (array2[2].equals(array4[1])))
{
grade += array4[2]+" "+array4[3]+" "+array4[4];
found=1;
}
if(found==0)
out.println("No Records");
}
out.println(grade);
GCPA();
}
public void CGPA() throws IOException{
String grade = "", cgpa = "";
int IntValue = 0, IntCH = 0, IntCGPA = 0, IntArray = 0;
if(array4[3] == "A") {
IntArray = Integer.parseInt(array4[3]);
IntValue = IntArray * 4;
} else if(array4[3] == "B") {
IntArray = Integer.parseInt(array4[3]);
IntValue = IntArray * 3;
}
IntCH += IntArray;
IntCGPA = IntValue/IntCH;
out.println(IntCGPA);
}
First, how do i make the results into a new line instead everything in one line?
Adding \n
doesn't work and when I run my program it doesn't show my IntCGPA
and shows this error
Exception in thread "Thread-0" java.lang.ArithmeticException: / by zero
at MultiClientHandler1.CGPA(MultiClientHandler1.java:95)
at MultiClientHandler1.View(MultiClientHandler1.java:81)
at MultiClientHandler1.run(MultiClientHandler1.java:116)