Wrong Running Order

Discussion in 'Java' started by HeatR216, Mar 25, 2010.

  1. HeatR216

    HeatR216

    Joined:
    Mar 25, 2010
    Messages:
    1
    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);
    }

    }
    HeatR216, Mar 25, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Skating_vince
    Replies:
    2
    Views:
    398
    Skating_vince
    Aug 13, 2004
  2. Irishmaninusa

    Dropdown displaying data in the wrong order

    Irishmaninusa, Aug 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    438
    Irishmaninusa
    Aug 27, 2004
  3. Soren Kuula
    Replies:
    2
    Views:
    482
    Soren Kuula
    Feb 1, 2004
  4. cspoh
    Replies:
    0
    Views:
    234
    cspoh
    Jul 31, 2003
  5. Stephan Kämper
    Replies:
    2
    Views:
    227
    Stephan Kämper
    Jan 18, 2004
Loading...

Share This Page