Quote:
Originally Posted by Vatoreus update, we got the inputs to work, but that's it. It isn't saving any of the inputs or anything. |
No that's not the problem at all. She is saving the input, she isn't listing the input however.
First of all:
Code:
if (choice == 2) {
int position = WindhamProject3Class.START_POSITION;
next = assistant.getEntryAt(position);
}
The only thing that this piece of code is doing is the following:
It saves a reference pointing at position 1 (ALWAYS) into the "next" variable, meaning, she's only saving the result but she's not doing anything with it.
What she probably do want to do however is to start with the START_POSITION and then iterate over "collection" and print out all objects that it includes. This can be done with the following code (using her other class):
Code:
if (choice == 2){
int size = assistant.getNumberOfEntries() + 1;
for (int i=1;i < size ; i++){
System.out.println("[" +assistant.getEntryAt(i) + "]");
}
}
Same with:
Code:
if (choice == 3) {
System.out.print("Enter name to search for: ");
String searchName = keyboard.nextLine();
searchName = keyboard.nextLine();
assistant.onList(searchName);
}
She's doing everything right here, but she's not doing anything for the user to see that the program is actually working.
Since "assistant.onList(searchName)" returns a boolean, the only thing she needs to do is "System.out.println(assistant.onList(searchName));" and she'll get either a true or false on her search.
Code:
public String deleteEntry(String deleteName) {
int[] b = new int[3];
int i = 0;
int delete = 0;
int elementToDelete = 5;
while (i < entry.length && delete < b.length) {
if (i == elementToDelete) {
i++;
} else {
b[delete] = entry.length;
i++;
delete++;
}
return deleteName;
}
return null;
}
This one isn't really working correctly and she's complicating the matter in fact. She got a string array with all her customers, why not look at it properly?
Code:
public String deleteEntry(String deleteName) {
for (int i=0;i < entry.length;i++){
if (deleteName.equals(entry[i])){
entry[i] = null;
rebuildArray();
return deleteName;
}
}
return "User not found";
}
private void rebuildArray() {
// you just deleted one entry of your array, so you'll have to rebuild it with
String[] newEntry = new String[entry.length-1];
int entryPointer = 0;
int newEntryPointer = 0;
while (entryPointer < entry.length){
if (entry[entryPointer] != null){
newEntry[newEntryPointer] = entry[entryPointer];
entryPointer++;
newEntryPointer++;
}else{
// you found the null object, jump to next element
entryPointer++;
}
}
entry = newEntry;
}
Mind you, arrays are static and thus you will have to rebuild the array with the "rebuildArray" method I added (make it private).
She will have to decrease the size with one also (numberOFEntries--) and take the necesarry actions. Hope you get the idea.
Of course, this isn't very good looking or even good code, but I tried to make it as easy possible. She should however, unless it's part of the homework to use arrays, look into Vectors instead, which would make the task a lot easier.
Hope that makes sense....
If not, just reply and I'll try to be a bit more pedagogic.
PS! I would still advice her to use switch-statement instead of the if-else statement in the main class here, it would make the code a lot easier to read and this is a typical "switch-statement" case..