Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Wrong Running Order

Reply
Thread Tools

Wrong Running Order

 
 
HeatR216 HeatR216 is offline
Junior Member
Join Date: Mar 2010
Posts: 1
 
      03-25-2010
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[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);
}

}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
Firefox URL list in the wrong order?? MIke Friedman Firefox 0 01-06-2005 10:45 PM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM
In which order are files looked for when loaded/requierd - and what'sthe order of suffixes? Stephan Kämper Ruby 2 01-18-2004 02:07 PM
How to Display DropDownList with preserved order (custom order) cspoh ASP .Net Web Controls 0 07-31-2003 09:19 AM



Advertisments