Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: urgent simple help for a very simple program

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy urgent simple help for a very simple program

    Hi all
    i hope everyone is doing well

    before i start, i would like to let you know that i am so beginner in Java, i have a homework to do about writing student names and grades, the number of students in given by the user, i tried my best to solve this homework but there is something wrong in my program where i could move further

    can you please take a look at my code and tell me what is the problem (i think the problem is to define and initialization method, but i do not know how?

    please replay and let me how can i continue my homework

    regards

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;

    public class students_grades extends Applet implements ActionListener {
    Label title = new Label("<{This program calculate students grades in 6 subjects}>");
    Label number_of_students = new Label("<{Inter the number of the students}>");
    TextField number_of_students_ = new TextField(5);
    Button View_Table = new Button ("View Table");


    public void init( ) {
    //setLayout();
    add (title);
    add (number_of_students);
    add (number_of_students_);
    add (View_Table);
    number_of_students_.addActionListener(this);
    View_Table.addActionListener(this);

    }
    public void actionPerformed(ActionEvent event) {

    // to get the number of students entered by user
    // String titles [8] = [No. , Student Name, Math, Comp, Salam, Arab, MGT, ORG];
    String number_of_students_text = number_of_students_.getText();
    int number_of_students_int = Integer.parseInt(number_of_students_text);

    // define two arrays of textfield
    TextField txtname []= new TextField [number_of_students_int];
    TextField txtgrade [][] = new TextField [number_of_students_int][6];

    // define two arrays ===> one for student names, and the other one for students grade
    String students_names [] = new String [number_of_students_int];
    float students_grades [][] = new float [number_of_students_int][6];

    // add name text fields
    for (int i=0; i<number_of_students_int; i++)
    {
    this.add (txtname[i]);
    }
    // add grade text fields in 2D array
    for (int i=0; i<number_of_students_int ;i++)
    {
    for (int j=0; j<6 ; j++)
    {
    add (txtgrade[i][j]);
    }
    }

    // get text from text fields and save it in the array
    for (int i=0; i<number_of_students_int; i++)
    {
    students_names [i] = txtname[i].getText();
    }

    for (int i=0; i<number_of_students_int ;i++)
    {
    for (int j=0; j<6 ; j++)
    {
    String Container = txtgrade[i][j].getText();
    int intContainer = Integer.parseInt(Container);
    students_grades[i][j] = intContainer;
    }
    }


    } // action performed
    } // class


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: urgent simple help for a very simple program

    what is the problem
    Why do you think there is a problem? Do you get error messages? If so please copy and paste them here.
    If the output is not what you want, show it and explain why its wrong and what you want to see.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: urgent simple help for a very simple program

    Cross posted

  4. #4
    Junior Member
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: urgent simple help for a very simple program

    it gets compiled, but when i run the applet, it shows only the labels and the button, the loop of text field does not display

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: urgent simple help for a very simple program

    loop of text field does not display
    That's ok, loops don't normally display.

Similar Threads

  1. simple program
    By Memb in forum Paid Java Projects
    Replies: 0
    Last Post: March 17th, 2010, 01:47 PM
  2. Simple Program for Cash
    By javastudent in forum Paid Java Projects
    Replies: 9
    Last Post: December 1st, 2009, 07:25 AM
  3. Error of data types and type casting in java program
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 2nd, 2009, 10:22 AM
  4. PLEASE HELP!!!! simple java program...
    By parvez07 in forum Object Oriented Programming
    Replies: 5
    Last Post: August 26th, 2009, 06:38 AM
  5. help with simple java program
    By parvez07 in forum Java Theory & Questions
    Replies: 4
    Last Post: August 25th, 2009, 07:19 AM