Results 1 to 1 of 1
Thread: Wrong Order in Program Run
- 03-25-2010, 08:41 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
Wrong Order in Program Run
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 atleast 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[i] = 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[i] = Integer.parseInt(JOptionPane.showInputDialog
("Enter Midterm Score for "+names[i]+" : "));
return scores;
}
private static int [] enterFinal (int num, String [] names)
{
int [] scores = new int [MAX];
for (int i = 0; i < num; i++)
scores[i] = Integer.parseInt(JOptionPane.showInputDialog
("Enter Final Score for "+names[i]+" : "));
return scores;
}
private static int averageMidterm (int num, int[] scores)
{
int total = 0;
for (int i = 0; i < num; i++)
total += scores[i];
return total/num;
}
private static int averageFinal (int num, int[] scores)
{
int total = 0;
for (int i = 0; i < num; i++)
total += scores[i];
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[i]+" "+scoresMidterm[i]+" "+scoresFinal[i];
output += "\n\nMidterm Average: "+avgMidterm + "\n\nFinal Average: " +avgFinal;
JOptionPane.showMessageDialog(null,output);
}
}
Similar Threads
-
Payroll Program exits at wrong time
By jsand2 in forum Java AppletsReplies: 13Last Post: 01-26-2009, 03:10 AM -
What's wrong in my program...?
By Annatar in forum Java SoftwareReplies: 3Last Post: 10-31-2008, 06:03 AM -
Need help with "a simple order entry program"
By sentica in forum New To JavaReplies: 6Last Post: 10-17-2008, 05:38 AM -
Simple Addition Program Outputting Wrong Value
By carlodelmundo in forum New To JavaReplies: 4Last Post: 08-05-2008, 03:37 AM -
what is wrong with this program ?
By Poor Bee in forum New To JavaReplies: 1Last Post: 05-07-2008, 07:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks