And a new suggestion if you can't get you code to work.
I find your solution very confusing and not object oriented. I believe that you problem is that when it comes to time you return values from the array, but when it comes to name you declare an array but you use a single String variable which you set and return. Therefor all the times will have the same name from the method "getName".
Shouldn't you have a method that depending on the time or its position you set the at the appropriate position the name at the StringArray?
I don't know your whole logic but you can try this:
// SINGLE CLASS WITH JUST PROPERTIES
public class Appointment {
private int time = 0;
private String name = "";
public Appointment() {
}
// add get,set methods
}
Then have a class like this:
public class AppointmentBook {
private int position = 0;
private int max = 0;
private Appointment [] appointments = null;
public Appointment(int max) {
// this.max is the global
// max is the local from the argument
this.max = max;
//appointments is the global
appointments = new Appointment[max];
}
// create methods that add and get appointments to the array by increasing the position variable
// also check the value of position in case you have too much appointment
// add whatever functionality you want
}
examle:
Appointment ap = new Appointment();
ap.setName("Name");
ap.setTime(200);
Appointment [] appointS = new Appointment[5];
appointS[0] = ap;
// OR
appointS[1] = new Appointment();
appointS[1].setName("Name 2");
appointS[1].setTime(300);
Remember when you declare an array its elements are undeclared.
This:
Appointment [] appointS = new Appointment[5]; will create an array but its elements (appointS[0], ... ) are null. You need to give them values like at the example