Member Avatar for soUPERMan

I want to create an array of the object student, and be able to add a student, delete a student and change the student attributes. Please help. I need to add and do all these things using an interactive user input (Scanner).

here's the student class i created.

public class student
{
	private String name;
	private int age;
	private char grade;
	
	// constructor
	
	public student(String nameIn, int ageIn, char gradeIn)
	{
		name = nameIn;
		age = ageIn;
		grade = gradeIn;
	}
	
	// Methods
	// Getter Methods
	
	public String getName()
	{
		return name;
	}
	
	public int getAge()
	{
		return age;
	}
	
	public char getGrade()
	{
		return grade;
	}
	
	// Setter methods
	
	public void setName(String nameIn)
	{
		name = nameIn;
	}
	
	public void setAge(int ageIn)
	{
		age = ageIn;
	}
	
	public void setGrade(char gradeIn)
	{
		grade = gradeIn;
	}
	
	// to String
	
	public String toString()
	{
		return "Student " + getName() + " aged " + getAge() + " has grade: " + getGrade();
		
	}
	
}

Ok. So you are going to need another class such as this

public class StudentDriver{
static int STUDENT_SIZE = 20;
student[] students = new student[STUDENT_SIZE];
int length = 0; //the current size of the array
}

Then you're going to need an add() method, a remove() method, a get(int index) method, a get(student st) method, etc. Start implementing the class and let me know what you have trouble with. Btw your "student" class should really be called "Student". Java classes start with uppercase letters by convention.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.