Wrong Running Order

Joined
Mar 25, 2010
Messages
1
Reaction score
0
I am trying to get this program to ask for the student names and then do the midterm and final grades for student #1 and then the same for student #2 and so on. Right now it asks for the midterm of student #1 and then the midterm of student #2 and the same for the final grade. How do I reorder my code to get it to be in the proper order (or at least the order I need)?

import javax.swing.JOptionPane;
public class helper {
static final int MAX = 30;
public static void main (String [] args)
{
String [] studentNames;
int [] studentMidterm;
int [] studentFinal;

int numStudents;

numStudents = howMany();

studentNames = enterNames(numStudents);
studentMidterm = enterMidterm(numStudents, studentNames);
studentFinal = enterFinal(numStudents, studentNames);

summary (studentNames, studentMidterm, studentFinal, numStudents, averageMidterm(numStudents, studentMidterm), averageFinal(numStudents, studentFinal));
}

private static int howMany()
{
int num;
do {
num = Integer.parseInt(JOptionPane.showInputDialog("How many students in the class?"));
} while (num < 1 || num > MAX);

return num;
}

private static String [] enterNames (int num)
{
String [] names = new String [MAX];
for (int i = 0; i < num; i++)
names = JOptionPane.showInputDialog("Enter name of student #"+(i+1)+" : ");
return names;
}

private static int [] enterMidterm (int num, String [] names)
{
int [] scores = new int [MAX];
for (int i = 0; i < num; i++)
scores = Integer.parseInt(JOptionPane.showInputDialog
("Enter Midterm Score for "+names+" : "));
return scores;
}
private static int [] enterFinal (int num, String [] names)
{
int [] scores = new int [MAX];
for (int i = 0; i < num; i++)
scores = Integer.parseInt(JOptionPane.showInputDialog
("Enter Final Score for "+names+" : "));
return scores;
}

private static int averageMidterm (int num, int[] scores)
{
int total = 0;
for (int i = 0; i < num; i++)
total += scores;
return total/num;
}
private static int averageFinal (int num, int[] scores)
{
int total = 0;
for (int i = 0; i < num; i++)
total += scores;
return total/num;
}

private static void summary(String [] names, int [] scoresMidterm, int [] scoresFinal, int n, int avgMidterm, int avgFinal)
{
String output = "Individual Student Scores:";
for (int i =0; i < n; i++)
output += "\n "+names+" "+scoresMidterm+" "+scoresFinal;
output += "\n\nMidterm Average: "+avgMidterm + "\n\nFinal Average: " +avgFinal;
JOptionPane.showMessageDialog(null,output);
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top