import java.util.ArrayList; import javax.swing.*; import java.text.*; import java.awt.*; public class Student { private String id = new String (); private String name = new String (); private double gpa; private Student [] person; private Student [] answers; private Student [] questions; Student() //Constructor { id = "Unknown ID"; name = "Unknown Name"; gpa = 0; } Student (String idnum, String n, double g) { id = idnum; name = n; gpa = g; } Student (int howManyKids, int howManyAnswers, String idnum, String n, double g) { id = new String(idnum); name = new String(n); double gpa = g; int i = 0; int a =0; person = new Student[howManyKids]; for (i=0; i < howManyKids; ++i) person [i] = new Student(); answers = new Student[howManyAnswers]; for (a=0; a < howManyAnswers; ++a) answers [a] = new Student(); //populate (howManyKids); //populate (howManyAnswers); } public void setAllStudentFields (int howManyKids, int howManyAnswers, String idnum, String n, double g) { id = new String(idnum); name = new String(n); double gpa = g; int i = 0; int a =0; person = new Student[howManyKids]; for (i=0; i < howManyKids; ++i) person [i] = new Student(); answers = new Student[howManyAnswers]; for (a=0; a < howManyAnswers; ++a) answers [a] = new Student(); //populate (howManyKids); //populate (howManyAnswers); }// end of setter to setAllStudentFields public static void teacherTest(ArrayList questions) { boolean valid = false; ArrayList<Character> key = new ArrayList<Character>(); if ((one != 'T') || (one != 'F')) questions.add(new Character(one)); else { System.out.println("Not an accpetable answer! Only enter a T or F."); valid = false; while (valid == false) { System.out.println("(Only enter a T or F)"); System.out.println("Question number " + i + " -->"); one = Character.toUpperCase(GetInput.readLineNonwhiteChar()); if ((one != 'T') || (one != 'F')) { questions.add(new Character(one)); valid = true; }//end of if statement } } while (one != 'X') { key.add(new Character(one)); System.out.println("Enter the answer to question -->"); one = Character.toUpperCase(GetInput.readLineNonwhiteChar()); } } public static void testForOneStudent(ArrayList answers) { char one = ' '; Character torf; int i = 0; int correct = 0; boolean valid = false; for (i = 1; i <= 5; ++i) { System.out.println("(Only enter a T or F)"); System.out.println("Question number " + i + " -->"); one = Character.toUpperCase(GetInput.readLineNonwhiteChar()); if ((one != 'T') || (one != 'F')) answers.add(new Character(one)); else { System.out.println("Not an accpetable answer! Only enter a T or F."); valid = false; while (valid == false) { System.out.println("(Only enter a T or F)"); System.out.println("Question number " + i + " -->"); one = Character.toUpperCase(GetInput.readLineNonwhiteChar()); if ((one != 'T') || (one != 'F')) { answers.add(new Character(one)); valid = true; }//end of if statement }//end of while loop }//end of else path }// end of for loop }//end of public public String getName() { return name; } public String getID() { return id; } public double getGPA() { return gpa; } public void setName(String n) { name = n; } public void setID(String idnum) { id = idnum; } public void setGPA(double g) { gpa = g; } public Student[] getPersons() { return person; } public Student[] getAnswers() { return answers; } public String toPrintPersonArray() { String pOutput = new String(); for (int i = 0; i < person.length; i++) { pOutput += "The number of kids are " + (i + 1) + "\nand they are " + person[i].toString() + "\n"; } return pOutput; } public String toPrintAnswerArray() { String aOutput = new String(); for (int i = 0; i < answers.length; i++) { aOutput += "The number of answers received are " + (i + 1) + "\nand they are " + answers[i].toString() + "\n"; } return aOutput; } public String toString() { return ("\nName --> " + getName() + " \t Id Number --> " + getID() + " \t GPA --> " + getGPA() + "\n" + toPrintPersonArray() + toPrintAnswerArray()); } }
I'm creating a program that has a user input a teacher key and the student's answer to output both the key, the students answer, student name, id, and gpa. I'm in the process of writing a test class but need to figure out the errors to this one first. This needs to be array based as well.