0
Student.setFullName = ("Kevin Smith");

That statement assigns a String (to right of =) to the static variable: setFullName in the Student class.

Yeah that makes sense, but i cannot get it to work with the set/get methods.

currently it works like this:

Name = JOptionPane.showInputDialog("Enter First and Last Name:");
StudentID = JOptionPane.showInputDialog("Enter StudentID");
Address = JOptionPane.showInputDialog("Enter Adress"); 
Student person = new Student(Name, StudentID, Address);
StArray[index] = person;

But instead of creating a new "person" with (Name, StudentID, Address) can i somehow use my set/get methods in my student class to assign the values to the setName, setStudentID, setAddress?

and then instead of displaying the results like this in my Student.class:

public String display()
	{
	return Name + "\n" + StudentID +
	"\n" + Address + ".";
	}
	public String toString() {
    return ""+display()+"";
	}

Display it like

public String display()
	{
	return getName + "\n" + getStudentID +
	"\n" + getAddress + ".";
	}

because at the moment my code does not use the set/get methods at all. Still works the same even if i delete them out of my code

Edited by tleverington1: n/a

0

i cannot get it to work with the set/get methods.

Sorry, I don't see your set/get methods or where you are calling them.

instead of creating a new "person" with (Name, StudentID, Address) can i somehow use my set/get methods in my student class to assign the values to the setName, setStudentID, setAddress?

Why do you want to use set methods vs using the constructor?

These are unusual variable names:
setName, setStudentID and setAddress

Did you mean that or do you mean that they are the names of methods?
You do NOT assign values to methods. You call methods with values and methods can return a value.

Edited by NormR1: n/a

0

Sorry, I don't see your set/get methods or where you are calling them.


Why do you want to use set methods vs using the constructor?

These are unusual variable names:
setName, setStudentID and setAddress

Did you mean that or do you mean that they are the names of methods?
You do NOT assign values to methods. You call methods with values and methods can return a value.

My set/get methods:

//get methods
public String getName()
	{
	return Name;
	}
public String getStudentID()
	{
	return StudentID;
	}
public String getAddress()
	{
	return Address;
	}
	
//set  method
public void setName( String SName)
	{
	Name = SName;
	}

public void setCourse (String SID)
	{
	StudentID = SID;
	}

public void setAddress (String SAdd)
	{
	Address = SAdd;
	}

Yes i meant that they are names of methods. I wanted to assign a value to each of them and be able to call them but do not know how to do this.

I could keep using the constructors but my program needs to create an array, and then be able to add Students to the array and edit and delete them.

Is it a bad idea to have the Array initialised in the main program?

My question is would it be better to have 3 files, Student, StudentArray, and StudentInteract where interact would allow the user to add/remove/edit students. And StudentArray would keep the information about the Students. Not sure how i would go about this though I am more used to programs being only in one file i.e C programming.

Sorry for asking loads of questions you have been of great help

Edited by tleverington1: n/a

0

methods. I wanted to assign a value to each of them

You do NOT assign values to methods.
You can call a method and give it many values as arguments. The method can take those values and assign them to variables.

I could keep using the constructors but my program needs to create an array, and then be able to add Students

There is no problem adding an object like Student to an array. You can give the object ALL the data it needs when you use a constructor to create the object. There is no need to use set methods if you have all the data the object needs when you create it.
Please explain your problem.

0

You do NOT assign values to methods.
You can call a method and give it many values as arguments. The method can take those values and assign them to variables.


There is no problem adding an object like Student to an array. You can give the object ALL the data it needs when you use a constructor to create the object. There is no need to use set methods if you have all the data the object needs when you create it.
Please explain your problem.

Yeah that makes sense. At the moment I only have 2 files, Student.class which has a constructor for name, id, address. And a display method to display the contents.
In my main program I create an array, Ask the user if they want to Add people into the array which works fine. However as I need to be able to add/edit/delete certain things in the array, I'm not sure if i'm going about it the wrong way by having my Array in my program that interacts with the user.

0

Does the program work the way you want it to?
Later you can move data to other classes or create new classes to improve the design.

0

Does the program work the way you want it to?
Later you can move data to other classes or create new classes to improve the design.

Ok that makes more sense. Because otherwise my main program will become really long. I plan to make it so:

1.Add Students Too Array
2.Display the results
3.Edit or delete Students -> if yes then Edit or delete ( don't know if i'd have to have these in the main program or on separate files)
4.Go back to step 1, or quit program.

This is how i've planned it out but it seems like it will become hard to do if I have ways or editting and deleting Students in my main program as well as everyting else. At the moment I can only display/add students.

0

My program is coming along now!

Thanks very much for your help. Been great help to me

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.