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
Re: urgent simple help for a very simple program
Quote:
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.
Re: urgent simple help for a very simple program
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 :(
Re: urgent simple help for a very simple program
Quote:
loop of text field does not display
That's ok, loops don't normally display.