I have this method created to ask a user to input job details, and save to an array:
public static void addJob() { currentJobIndex = 0;
jobs[currentJobIndex] = new Job();
jobs[currentJobIndex].getInformation();
jobs[currentJobIndex].calculateCost();
jobs[currentJobIndex].display();
jobs[currentJobIndex].getCostTotal();
currentJobIndex++;
I have this method to display all jobs saved in the array:
public static void showAllJobs() {
for (Job job : jobs) {
if (job != null) {
job.display();
}
}
}
It is only showing the last entered job and I cant figure out why, any assistance would be appreciated!
addJob()method you havecurrentJobIndex = 0;so items will only ever be inserted al position 0 (and will overwrite anything else that was there). You need to increment this number and ensure that your array has space. You should probably be using an ArrayList that already has an add method.