Q:

Java Need Help To Get Print To All String

guys i need help with this code 
i need to print all string by command (PrintAllStudents) i made the command but i didn't make it print all student it just print the lastest student added im learning java
here is my test class :
package com.tj;

public class Student {

    private int StudentId;
    private String StudentName;

    public void AddStudent(int StudentId, String StudentName){
    this.StudentId = StudentId;
    this.StudentName = StudentName;
    }
    public void PrintAllStudents() {
        System.out.println("Id : " + StudentId);
        System.out.println("StudentName : " + StudentName);

    }
}

and my test class : 
package com.tj;

public class Test {
    public static void main(String[] args) {
        Student s = new Student();
        s.AddStudent(1, "Walied");
        s.AddStudent(2, "Ayman");
        s.AddStudent(3, "Mostafa");
        s.PrintAllStudents();
    }

}

A:

I highly recommend renaming your variables and methods to lower Camel Case: studentName, studentId, printAllStudents() to avoid confusion with classes like Student, String.
http://java.about.com/od/javasyntax/a/nameconventions.htm
Currently your class Student holds two variables: 
private int StudentId;
private String StudentName;

Your method AddStudent(int StudentId, String StudentName) assigns new values to those two variables:
this.StudentId = StudentId;
this.StudentName = StudentName;

Each time you call AddStudent() you assign new values. That's why you only see the id and name of the last student.
What you could do is create multiple Student objects in your test class, each object will hold it's own id and name variables:
Student s1 = new Student();
s1.AddStudent(1, "Walied");

Student s2 = new Student();
s2.AddStudent(2, "Ayman");

Student s3 = new Student();
s3.AddStudent(3, "Mostafa");

s1.PrintAllStudents();
s2.PrintAllStudents();
s3.PrintAllStudents();

You could rename your methods so it would look a bit more understandable:
Student s1 = new Student();
s1.setData(1, "Walied");

Student s2 = new Student();
s2.setData(2, "Ayman");

Student s3 = new Student();
s3.setData(3, "Mostafa");

s1.printData();
s2.printData();
s3.printData();

In your test class you could save all of your Student objects in a List:
List<Student> studentList = new ArrayList<Student>();
studentList.add(s1);
studentList.add(s2);
studentList.add(s3);

Then loop through the list and print the data for each object:
for (Student s : studentList) {
   s.printData();
}

