Page 1 of 2 12 LastLast
Results 1 to 20 of 29
  1. #1
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Post Help with 2 classes on this project plzzz

    Hi I'm having a few issues with making this program work. I am currently stuck on two classes: FillArray, where it takes Setparam's data to generate students IDs and quizzes with the grades using Random. also the Display results class needs to be in Jtable and it must show the Students ID then number of quizzes and the answer underneath
    ex: Student ID Quiz 1 Quiz 2 Quiz 3
    75678 89 90 82
    75679 100 92 96
    75680 40 23 16

    please refer to the comments of the FillArray class and Display class
    Thanks in advance!

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.Scanner;
    import java.awt.event.*;
    import javax.swing.JOptionPane;
    import java.util.Random;
     
    public class Final extends JFrame
     
    {
        private int numberOfStudents;
        private int quizesPerStudent;
        private int[][] data = new int[numberOfStudents][quizesPerStudent];
        private int data1[];
        private int data2[];
     
        public Final() 
        {
     
            // CREATES BUTTONS
            JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
            JButton Help = new JButton("HELP");
            JButton SetP = new JButton("SET PARAMETERS");
            JButton Fill = new JButton("FILL ARRAY");
            JButton Disp = new JButton("DISPLAY RESULTS");
            JButton Quit = new JButton("QUIT");
     
            // CREATES DESCRIPTIONS FOR BUTTONS
            Help.setToolTipText("Displays Instructions on how to use this program.");
            SetP.setToolTipText("Promps user for number of students and quizzes.");
            Fill.setToolTipText("Inserts Values pre-set in SET PAREMETERS.");
            Disp.setToolTipText("Displays the Results");
            Quit.setToolTipText("Close Program");
     
            // ADDS BUTTONS TO JFRAME
            p1.add(Help);
            p1.add(SetP);
            p1.add(Fill);
            p1.add(Disp);
            p1.add(Quit);
            p1.setBorder(new TitledBorder("Grade Compiling Program"));
     
            // ADJUSTS THE FONT AND BORDER OPTIONS FOR JFRAME
            Font largeFont = new Font("TimesRoman", Font.BOLD, 20);
            Border lineBorder = new LineBorder(Color.BLACK, 2);
     
            // ADDS ALL OF THE ABOVE INTO GUI FIELD
            add(p1);
     
            // REGISTERS EVENT LISTENERS WITH ALL 5 BUTTONS
            Help.addActionListener(new HelpButtonListener());
            SetP.addActionListener(new SetPButtonListener());
            Fill.addActionListener(new FillButtonListener());
            Disp.addActionListener(new DispButtonListener());
            Quit.addActionListener(new QuitButtonListener());
        }
        public static void main(String[] args) 
        {
            // CREATES JFRAME AND PAREMETERS FOR JFRAME
            JFrame frame = new Final();
            frame.setTitle("College Final Project");
            frame.setSize(750, 500);
            frame.setLocationRelativeTo(null); // Center the frame
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
        // PROGRAMMING FOR WHEN THE "HELP BUTTON" IS PRESSED
        private class HelpButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e)
            {
     
                System.out.println();
                String output = "\n______________________HELP MENU__________________________"
                        + // /This is the output that will be diplayed when the HELP
                            // button is pressed
                        "\n Welcome to the Help Menu, here you will find tips to using this program."
                        + "\n"
                        + "\n The first step is to click the 'SET PARAMETERS' button. Here you will   "
                        + "\n input the number of students (up to 50) and number of quizzes for each  "
                        + "\n student (up to 5.) "
                        + "\n "
                        + "\n Next you will select the 'FILL ARRAY' button. This button will open up"
                        + "\n the menu to select the ID numbers and quiz grades for each student and "
                        + "\n quiz, then store them within the paremeters set in 'SET PARAMETERS'."
                        + "\n "
                        + "\n Finally you will click the 'DISPLAY' button. This button will compile all"
                        + "\n the data you entered in the last two sections and display the results."
                        + "\n This program computes and displays the lowest, highest, average, and"
                        + "\n medium for each grade of each set of quizzes."
                        + "\n "
                        + "\n As an added note if you wish to quit this program at any time, simply"
                        + "\n press the 'QUIT' button and the program will close";
     
                JOptionPane.showMessageDialog(null, output); // Dispays the above
                                                                // information for
                                                                // the user in a
                                                                // seperate window
                                                                // that closes when
                                                                // OK is pressed.
            }
        }
        // PROGRAMMING FOR WHEN THE "SET PARAMETERS BUTTON" IS PRESSED
        private class SetPButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {
                String studentString = JOptionPane
                        .showInputDialog("Enter number of students (up to 50)");
                if (studentString != null) 
                {
                    numberOfStudents = Integer.parseInt(studentString);
                }
     
                String numString = JOptionPane
                        .showInputDialog("Enter number of quizzes for each student (up to 5)");
                if (numString != null) 
                {
                    quizesPerStudent = Integer.parseInt(numString);
                }
            }
        }
        // PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED
        private class FillButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {  
                //this part would be where student's ID = 75678 and for every number of student the last digit increase by 1. ex: 3 students ID would be 75678,75679,75680.
            
            Random rmg = new Random();
    			
    	quizesPerStudent  
            randomNumbers.nextInt(100);
            //this part takes the number of quizzes and generates quiz grades.
            
             String output = "\n DATA INPUT COMPLETE FOR QUIZ " + y;
                JOptionPane.showMessageDialog(null, output);
            }
        }
        // PROGRAMMING FOR WHEN THE "DISPLAY BUTTON" IS PRESSED
        private class DispButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {
                //help with Jtable for displaying the students IDs then quizzes across the table and list the grades underneath.
            }
        }
        // PROGRAMMING FOR WHEN THE "QUIT BUTTON" IS PRESSED
        private class QuitButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {
                System.out.println();
                String output = "\n Bye";
                JOptionPane.showMessageDialog(null, output);
                System.exit(0);
            }
        }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    Do you have any specific questions or problems?
    Please ask them.

  3. #3
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    Do you have any specific questions or problems?
    Please ask them.
    for the Fill Array class i'm having problems with how to start out.
    i know that: longID = 75678
    for (int = 0, i<data //stuck right here; i++)
    {

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    You need to read the syntax for the for statement.
    Start here:
    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

  5. #5
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    i understand the syntax, it's the codes that i need help with. the students ID must increment by 1. and quizzes generated using quizperstudent and randomNumbers.nextInt(100)

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    Sorry, your posted for loop was not syntactically correct.
    Try writing some pseudo code to define the loop and its controls and what you want to do in the loop that depends on the value of the loop index variable.

  7. #7
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    Sorry, your posted for loop was not syntactically correct.
    Try writing some pseudo code to define the loop and its controls and what you want to do in the loop that depends on the value of the loop index variable.
    well i have something like this when i am not using joptionpane or gui,

    Java Code:
    public void FillArray()
    {
    Random rmg = new Random();
    LongID=75678
    for (int i=0; i<students; i++)
    {
    Quizarray[i][0]= ID;
    ID++
    }

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    That's mostly correct except for a few undefined variables.
    You have not specified what your problem is.

  9. #9
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    That's mostly correct except for a few undefined variables.
    You have not specified what your problem is.
    now my code is in joptions and gui, i need help with coding the lines in the Fillarray class from my first post :/

    Java Code:
      // PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED
        private class FillButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {  
                //this part would be where student's ID = 75678 and for every number of student the last digit increase by 1. ex: 3 students ID would be 75678,75679,75680.
             
            Random rmg = new Random();
                 
        quizesPerStudent  
            randomNumbers.nextInt(100);
            //this part takes the number of quizzes and generates quiz grades.
             
             String output = "\n DATA INPUT COMPLETE FOR QUIZ " + y;
                JOptionPane.showMessageDialog(null, output);
            }
        }

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    i need help with coding the lines in the Fillarray class
    You need to describe what you want to do in that class.

    Try writing some pseudo code to define the loop and its controls and what you want to do in the loop that depends on the value of the loop index variable.

  11. #11
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    the class must be invoked after SetParams. the program will check for this and if the option is exercised before SetParams, the program must provide informational warning to the user, wait for the user to read the message, and the allow the user to click OK, where the program goes back to the gui menu. once option SetParams is exercised, the program will fill the array with the following constraints: Student ID is a five digit integer value starting at 75678 and increments by one for each student in the class, and the scores in each quiz is an integer number, randomly generated by the program in ranges 0 to 100. once the task is completed, the program will issue the message "data entry completed.." and allows the user to read the message and click OK

    trying to be as descriptive as i can..
    Last edited by stan989; 12-08-2011 at 04:12 AM.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    Make a list of simple things that the class and its method is supposed to do.
    Start with the first one, design the code to do that step, write the code, compile it. If you have problems post them here.
    If possible execute the code to see if it does what you want. Use printlns to print out the values of variables so you can see if the code is doing what you want it to do.

    After you get one of the simple things done, move to the next one and work on it as above.

  13. #13
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    i declared longID var at the beginning of the code and at the fillarray i put that for now. hmmmm

    Java Code:
    private class FillButtonListener implements ActionListener 
    	 {
          public void actionPerformed(ActionEvent e) 
    		{
     			Random rmg = new Random();
    			longID = 75678;
    			
    			for (int i = 0; i<quizesPerstudents; i++)
    			{
    			ID++

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    You should organize your thoughts and do some design work BEFORE trying to write code.

  15. #15
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    this is what i have so far. i defined:
    Java Code:
    int FIRSTSID = 75678;
    	 int longID, nS, nQ;
    	 long[] sIDs;
    	 int[][] sQScores;

    Java Code:
    // PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED
        private class FillButtonListener implements ActionListener 
    	 {
          public void actionPerformed(ActionEvent e) 
    		{
    			int i;
    			int j;
    			int FIRSTSID = 75678;
    
    			for (i = 0; i < nS; i++) 
    			{
    				(sIDs)[i] = FIRSTSID + i;
    				for (j = 0; j < nQ; j++)
    				(sQScores)[i][j] = (int) (((float) rand()) / 324.5);
    			}
    
    		}
    
    		private float rand() 
    		{
    			Random rand = new Random();
    			int number = 0;
    			{
    				for (int counter = +1; counter <= 1; counter++) 
    				{
    				number = rand.nextInt(100);
    				System.out.println(number);
    				}
    			}
    			return number;
    		}
    	}

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    Have you tested what you have so far and does it do what you want?

  17. #17
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    Have you tested what you have so far and does it do what you want?
    As of right now when i compile the codes the program runs but after i click on the fillarray a box should pop up saying "DATA INPUT COMPLETE FOR QUIZ"

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.Scanner;
    import java.awt.event.*;
    import javax.swing.JOptionPane;
    import java.util.Random;
    
    public class Final extends JFrame
     
    {
        private int numberOfStudents;
        private int quizesPerStudent;
        private int[][] data = new int[numberOfStudents][quizesPerStudent];
        private int data1[];
        private int data2[];
    	 int FIRSTSID = 75678;
    	 int longID, nS, nQ;
    	 long[] sIDs;
    	 int[][] sQScores;
     
        public Final() 
        {
     
            // CREATES BUTTONS
            JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 10));
            JButton Help = new JButton("HELP");
            JButton SetP = new JButton("SET PARAMETERS");
            JButton Fill = new JButton("FILL ARRAY");
            JButton Disp = new JButton("DISPLAY RESULTS");
            JButton Quit = new JButton("QUIT");
     
            // CREATES DESCRIPTIONS FOR BUTTONS
            Help.setToolTipText("Displays Instructions on how to use this program.");
            SetP.setToolTipText("Promps user for number of students and quizzes.");
            Fill.setToolTipText("Inserts Values pre-set in SET PAREMETERS.");
            Disp.setToolTipText("Displays the Results");
            Quit.setToolTipText("Close Program");
     
            // ADDS BUTTONS TO JFRAME
            p1.add(Help);
            p1.add(SetP);
            p1.add(Fill);
            p1.add(Disp);
            p1.add(Quit);
            p1.setBorder(new TitledBorder("Grade Compiling Program"));
     
            // ADJUSTS THE FONT AND BORDER OPTIONS FOR JFRAME
            Font largeFont = new Font("TimesRoman", Font.BOLD, 20);
            Border lineBorder = new LineBorder(Color.BLACK, 2);
     
            // ADDS ALL OF THE ABOVE INTO GUI FIELD
            add(p1);
     
            // REGISTERS EVENT LISTENERS WITH ALL 5 BUTTONS
            Help.addActionListener(new HelpButtonListener());
            SetP.addActionListener(new SetPButtonListener());
            Fill.addActionListener(new FillButtonListener());
            Disp.addActionListener(new DispButtonListener());
            Quit.addActionListener(new QuitButtonListener());
        }
        public static void main(String[] args) 
        {
            // CREATES JFRAME AND PAREMETERS FOR JFRAME
            JFrame frame = new Final();
            frame.setTitle("College Final Project");
            frame.setSize(750, 500);
            frame.setLocationRelativeTo(null); // Center the frame
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
        // PROGRAMMING FOR WHEN THE "HELP BUTTON" IS PRESSED
        private class HelpButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e)
            {
     
                System.out.println();
                String output = "\n______________________HELP MENU__________________________"
                        + // /This is the output that will be diplayed when the HELP
                            // button is pressed
                        "\n Welcome to the Help Menu, here you will find tips to using this program."
                        + "\n"
                        + "\n The first step is to click the 'SET PARAMETERS' button. Here you will   "
                        + "\n input the number of students (up to 50) and number of quizzes for each  "
                        + "\n student (up to 5.) "
                        + "\n "
                        + "\n Next you will select the 'FILL ARRAY' button. This button will open up"
                        + "\n the menu to select the ID numbers and quiz grades for each student and "
                        + "\n quiz, then store them within the paremeters set in 'SET PARAMETERS'."
                        + "\n "
                        + "\n Finally you will click the 'DISPLAY' button. This button will compile all"
                        + "\n the data you entered in the last two sections and display the results."
                        + "\n This program computes and displays the lowest, highest, average, and"
                        + "\n medium for each grade of each set of quizzes."
                        + "\n "
                        + "\n As an added note if you wish to quit this program at any time, simply"
                        + "\n press the 'QUIT' button and the program will close";
     
                JOptionPane.showMessageDialog(null, output); // Dispays the above
                                                                // information for
                                                                // the user in a
                                                                // seperate window
                                                                // that closes when
                                                                // OK is pressed.
            }
        }
        // PROGRAMMING FOR WHEN THE "SET PARAMETERS BUTTON" IS PRESSED
        private class SetPButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {
                String studentString = JOptionPane
                        .showInputDialog("Enter number of students (up to 50)");
                if (studentString != null) 
                {
                    numberOfStudents = Integer.parseInt(studentString);
                }
     
                String numString = JOptionPane
                        .showInputDialog("Enter number of quizzes for each student (up to 5)");
                if (numString != null) 
                {
                    quizesPerStudent = Integer.parseInt(numString);
                }
            }
        }
        // PROGRAMMING FOR WHEN THE "FILL ARRAY BUTTON" IS PRESSED
        private class FillButtonListener implements ActionListener 
    	 {
          public void actionPerformed(ActionEvent e) 
    		{
    			int i;
    			int j;
    			int FIRSTSID = 75678;
    
    			for (i = 0; i < nS; i++) 
    			{
    				(sIDs)[i] = FIRSTSID + i;
    				for (j = 0; j < nQ; j++)
    				(sQScores)[i][j] = (int) (((float) rand()) / 324.5);
    			}
    
    		}
    
    		private float rand() 
    		{
    			Random rand = new Random();
    			int number = 0;
    			{
    				for (int counter = +1; counter <= 1; counter++) 
    				{
    				number = rand.nextInt(100);
    				System.out.println(number);
    				String output = "\n DATA INPUT COMPLETE FOR QUIZ ";
                    JOptionPane.showMessageDialog(null, output);
    				}
    			}
    			return number;			
    		}
    	}
    			
        // PROGRAMMING FOR WHEN THE "DISPLAY BUTTON" IS PRESSED
        private class DispButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {
                System.out.println();
                String output = "\n Students and Grades\n "
                        + data[numberOfStudents][quizesPerStudent];
                JOptionPane.showMessageDialog(null, output);
            }
        }
        // PROGRAMMING FOR WHEN THE "QUIT BUTTON" IS PRESSED
        private class QuitButtonListener implements ActionListener 
        {
            public void actionPerformed(ActionEvent e) 
            {
                System.out.println();
                String output = "\n Bye";
                JOptionPane.showMessageDialog(null, output);
                System.exit(0);
            }
        }
    }

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default Re: Help with 2 classes on this project plzzz

    after i click on the fillarray a box show pop up saying "Data entry completed!"
    Is that good or bad? Please explain if it is a problem.

    I do NOT see where that message comes from in your code.
    Is there more code that you have not posted that outputs that message?

  19. #19
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by Norm View Post
    Is that good or bad? Please explain if it is a problem.

    I do NOT see where that message comes from in your code.
    Is there more code that you have not posted that outputs that message?
    Sorry just edited my previous post. I'm trying to make is display a box saying data entry is done after fillarray is excuted

  20. #20
    stan989 is offline Member
    Join Date
    Dec 2011
    Posts
    20
    Rep Power
    0

    Default Re: Help with 2 classes on this project plzzz

    Quote Originally Posted by stan989 View Post
    Sorry just edited my previous post. I'm trying to make is display a box saying data entry is done after fillarray is excuted
    line 155: String output = "\n DATA INPUT COMPLETE FOR QUIZ ";
    JOptionPane.showMessageDialog(null, output);

Page 1 of 2 12 LastLast

Similar Threads

  1. Java project with multiple classes
    By trakke in forum New To Java
    Replies: 1
    Last Post: 04-28-2011, 09:16 PM
  2. Replies: 23
    Last Post: 04-18-2011, 07:54 PM
  3. need help plzzz for my question
    By yasmin mohamed in forum New To Java
    Replies: 3
    Last Post: 05-20-2010, 03:12 AM
  4. Replies: 5
    Last Post: 12-05-2009, 11:45 PM
  5. Replies: 1
    Last Post: 07-29-2008, 04:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •