Temporarily Storing data

I'm writing a program that reads input grades for different students, so far i've written the program to gather input for one student. Whats a good method to gather the same info on another student. Is there someway i can constantly change the variables as new data is input?

My program so far:

import java.util.*;

publicclass AssignmentFour

{

private String studentName;

privateint quizzesScore, midtermScore, finalScore;

privatedouble overallScore;

privatechar finalGrade;

publicvoid readInput()

{

Scanner keyboard =new Scanner(System.in);

System.out.println("What is the name of the student?");

studentName = keyboard.nextLine();

System.out.println("What is the student's score in quizzes? (worth 20% of overall grade)");

quizzesScore = keyboard.nextInt();

while (quizzesScore < 0)

{

System.out.println("Score cannot be negative. (worth 40% of overall grade)");

System.out.println("Reenter the score for quizzes");

quizzesScore = keyboard.nextInt();

}

System.out.println("What was the student's midterm score? (worth 40% of overall grade)");

midtermScore = keyboard.nextInt();

while (midtermScore < 0)

{

System.out.println("Score cannot be negative.");

System.out.println("Reenter the score for the midterm");

midtermScore = keyboard.nextInt();

}

System.out.println("What was the student's score on the final?");

finalScore = keyboard.nextInt();

while (finalScore < 0)

{

System.out.println("Score cannot be negative.");

System.out.println("Reenter the score for quizzes");

finalScore = keyboard.nextInt();

}

overallScore = (quizzesScore*.2)+(midtermScore*.4)+(finalScore*.4);

if (overallScore >= 90)

finalGrade ='A';

elseif (overallScore >= 80)

finalGrade ='B';

elseif (overallScore >= 70)

finalGrade ='C';

elseif (overallScore >= 60)

finalGrade ='D';

else

finalGrade ='E';

}

publicvoid set(String newName,int newQuizzes,int newMidterm,int newFinal,double newOverall,char newGrade)

{

newName = studentName;

newQuizzes = quizzesScore;

newMidterm = midtermScore;

newFinal = finalScore;

newOverall = overallScore;

newGrade = finalGrade;

}

public String getName()

{

return studentName;

}

publicint getQuiz()

{

return quizzesScore;

}

publicint getMid()

{

return midtermScore;

}

publicint getFinal()

{

return finalScore;

}

publicdouble getOverall()

{

return overallScore;

}

publicchar getGrade()

{

return finalGrade;

}

publicvoid writeOutput()

{

System.out.println("The student's name is: " + studentName);

System.out.println("The student's quiz grade is: " + quizzesScore);

System.out.println("The student's midterm grade is: " + midtermScore);

System.out.println("The student's final exam grade is: " + finalScore);

System.out.println("The student's overall score is: " + overallScore);

System.out.println("The student's grade is: " + finalGrade);

}

}

[6234 byte] By [thecynicle1a] at [2007-10-3 9:28:13]
# 1
You could create a Student class and have that method return a new Student object.
CaptainMorgan08a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 2
I forgot to mention im already using another class to run this class.
thecynicle1a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 3
>You could create a Student class and have that method return a new Student object.Would that work for more than 2 students?
thecynicle1a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 4

> Would that work for more than 2 students?

Yes, just create a new Student object for each student. You would need to change your method to something like this:

public Student readInput()

{

...

return new Student(...);

}

Then in your main method:

Student student1 = readInput();

Student student2 = readInput();

Does that make sense?

CaptainMorgan08a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 5
I think i understand, but what if i don't know how many students they are inputting. can i do a 'do-while' on the read input somehow when i ask if they want to enter another student. And when that happens, have the program add a student?
thecynicle1a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 6
You could store the Students into an ArrayList. Or you could ask the user ahead of time how many students there are, then create an array of Students with that many Students in it.
CaptainMorgan08a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 7

I don't think i should use an array wer haven't gone over that in class and, yeah that wouldn't look great.

this is what i added to my Demo class i just put the do-while in but now i need to add multiple students, is there anyway i can use the for statement?:

import java.util.*;

public class GraderDemo

{

public static void main(String[] args)

{

AssignmentFour grader = new AssignmentFour();

int newQuizzes, newMidterm, newFinal;

double newOverall;

char newGrade;

String answer;

do

{

grader.readInput();

Scanner keyboard = new Scanner(System.in);

System.out.println("Would you like to enter another student?");

answer = keyboard.nextLine();

}while (answer.equalsIgnoreCase("yes"));

grader.writeOutput();

newQuizzes = grader.getQuiz();

newMidterm = grader.getMid();

newFinal = grader.getFinal();

newOverall = grader.getOverall();

newGrade = grader.getGrade();

}

}

thecynicle1a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 8
Ok i thought i could do it that way but ive completely confused myself. Now i really need help.Message was edited by: thecynicle1
thecynicle1a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...
# 9
Is there anyway to use a mutator to accomplish this?
thecynicle1a at 2007-7-15 4:42:36 > top of Java-index,Java Essentials,Java Programming...