This program is set up for a user to input five names(lastname, first) in random order along with their 5 test scores and then gives their average score, then states they pass or fail. The program will alphabetize the names, average the scores and return the pass/fail. The problem is I would like to put it in the following format;like a chart..
Name Grade1 Grade2 Grade 3 Grade 4 Grade5 Avg Pass/fail
Here is what I have so far
CODE
/* finalProject.java */
import java.awt.*;
import java.lang.*;
import java.io.*;
import java.util.*;
public class finalProject {
int MAX =100;
int JMAX =5;
public static void main(String[] a) {
finalProject ts = new finalProject();
// Maybe here you could have something that would choose to do one or the other.
// Right now it should do both, one after the other.
ts.init();
ts.jinit();
}
public void init() {
int j=0;
boolean f=true;
String[] ar = new String[MAX];
for (j=0; j<MAX; j++) { ar[j] = ""; }
j=0;
System.out.println("In init\n--------------------------------------------------\n");
InputStreamReader isr = new InputStreamReader ( System.in );
BufferedReader br = new BufferedReader ( isr );
System.out.println("Type student names on individual lines in last name, first name format.");
System.out.println("When finished entering student names, enter a ? and then hit enter.");
String s = null;
while (f) {
try {
s = br.readLine ();
s=s.replace("\n","");
s=s.replace("\r","");
// System.out.println("["+s+"]");
if (s.equals("?")) { f=false; }
else { ar[j++] = s; }
}
catch ( IOException ioe ) { }
if (j > JMAX) { f=false; }
}
System.out.println("\nStudent Name\t\tGrade1-Grade2-Grade3-Grade4-Grade5-Average-Pass/Fail");
Arrays.sort(ar);
for (int i=0; i<ar.length; i++) {
try {
if (ar[i].length() > 0) { System.out.println("\n" + ar[i]); }
}
catch (Exception e) { }
}
}
public void jinit() {
System.out.println("In jinit\n--------------------------------------------------\n");
int j=0;
int average;
String strPass, strFail, strDef,
strToPrint = "";
String Pass;
String Fail;
String Result;
boolean f=true;
String[] ar = new String[JMAX];
int[] theInts = new int[JMAX];
for (j=0; j<JMAX; j++) { ar[j] = ""; theInts[j] = 0; }
j=0;
InputStreamReader isr = new InputStreamReader ( System.in );
BufferedReader br = new BufferedReader ( isr );
System.out.println("Enter five grades per student");
System.out.println("When last grade is entered type a ? and hit enter");
String s = null;
while (f) {
try {
s = br.readLine ();
s=s.replace("\n","");
s=s.replace("\r","");
// System.out.println("["+s+"]");
if (s.equals("?")) { f=false; }
else { ar[j] = s;
try {
theInts[j] = Integer.parseInt(s);
j++;
}
catch(Exception e) {
System.out.println("Numbers only please!!!");
}
}
}
catch ( IOException ioe ) { }
if (j > JMAX) { f=false; }
}
average = ((theInts[0]+theInts[1]+theInts[2]+theInts[3]+theInts[4]) / 5);
Result = strToPrint;
strFail = "Fail";
strPass = "Pass";
if(average >= 60){
strToPrint = strPass;
}
else if(average <= 59){
strToPrint = strFail;
}
System.out.println("\n" + "\t\t" + ar[0] + " " + ar[1] + " " + ar[2] + " " + ar[3] + " " + ar[4]+ " " + average + " " + strToPrint);
}
}