Hi.
My problem is, I'm trying to match up objects which are exactly the same in two different arrays.
Before you see the code, you should understand that a client instance holds a reference to a vacation instance.
I'm trying to see how many other lients have a refernce to the same vacation instance.
--------------------Method to match objects----------------
public void addClientToVacation(int index) throws IOException, ClassNotFoundException
{
System.out.println("Vacations to chose from:\n"
;
for (int i = 0;i < vacationArray.nextFreeLocation;i++)
{
System.out.print("-------------------------------------------\n"
+ i + ": " + vacationArray.vacations.getHolType() + " in "
+ vacationArray.vacations.getArea() + " during the "
+ vacationArray.vacations.getTimeOfYear()
+ "\n-------------------------------------------\n\n"
;
}
System.out.print("Vacation to assign to client \""
+ tempArray.clients[index].getSurname() + "\": "
;
int option = 0;
option = Integer.parseInt(input.readLine());
tempArray.clients[index].setDestination(vacationArray.vacations[option]);
writeIt();
System.out.print("\n\n"
;
clear(50);
System.out.println("Client: " + "\"" + tempArray.clients[index].getSurname() + "\""
+ "is going " + vacationArray.vacations[option].getHolType() + " in "
+ vacationArray.vacations[option].getArea() + " during the "
+ vacationArray.vacations[option].getTimeOfYear());
System.out.println("\nOther people going on this vacation are:"
;
String output = "";
for (int i = 0;i < tempArray.nextFreeLocation;i++)
{ //destination in client constructor is made to null
System.out.println("place 1 " + i);
if (tempArray.clients.getDestination() == null)
{
System.out.println("place 2 " + i);
continue;
}
System.out.println("place 3 " + i + "destination = " + tempArray.clients.getDestination());
if (tempArray.clients.getDestination().equals(vacationArray.vacations[option])) {
System.out.println("place 4 " + i);
output = output + tempArray.clients.getSurname() + "\n";
}
System.out.println("place 5 " + i);
}
System.out.print(output);
clear(5);
mainMenu();
return;
}
----------------------------------------------------------
It's the " if (tempArray.clients.getDestination().equals(vacationArray.vacations[option])) " bit towards the bottom that reffuses to match up objects.
I do know that Object.equals() when comparing objects, is the most strict method, but why is it not matching???
Here's the output I get:
--------------------Output------------------------------
Client: "Burt"is going Hiking in New Hampshire during the Autumn
Other people going on this vacation are:
place 1 0
place 3 0destination = Area: New Hampshire
Holiday Type: Hiking
Minimum Cost: £200
Maximum Cost: £300
Time Of Year: Autumn
place 5 0
place 1 1
place 2 1
place 1 2
place 2 2
place 1 3
place 3 3destination = Area: New Hampshire
Holiday Type: Hiking
Minimum Cost: £200
Maximum Cost: £300
Time Of Year: Autumn
place 4 3
place 5 3
place 1 4
place 2 4
place 1 5
place 2 5
Burt
--------------------------------------------------------
"Burt" is the actual output I would expect the method to produce, since this is the client I set the specific vacation to, but I would like to point out that place x is the flag so I can see how far each iteration goes, the number after that is the array index of the customers.
It should pick up that array element '3' holds exactly the same instance and place Wardell before "Burt".
Anyway, If anyone understood that I'd just like to see what anyone thinks is the problem?? or if there's another way to do it...
Cheers every1.
Oxi we are all of us living in the gutter.
But some of us are looking at the stars.
My problem is, I'm trying to match up objects which are exactly the same in two different arrays.
Before you see the code, you should understand that a client instance holds a reference to a vacation instance.
I'm trying to see how many other lients have a refernce to the same vacation instance.
--------------------Method to match objects----------------
public void addClientToVacation(int index) throws IOException, ClassNotFoundException
{
System.out.println("Vacations to chose from:\n"
for (int i = 0;i < vacationArray.nextFreeLocation;i++)
{
System.out.print("-------------------------------------------\n"
+ i + ": " + vacationArray.vacations.getHolType() + " in "
+ vacationArray.vacations.getArea() + " during the "
+ vacationArray.vacations.getTimeOfYear()
+ "\n-------------------------------------------\n\n"
}
System.out.print("Vacation to assign to client \""
+ tempArray.clients[index].getSurname() + "\": "
int option = 0;
option = Integer.parseInt(input.readLine());
tempArray.clients[index].setDestination(vacationArray.vacations[option]);
writeIt();
System.out.print("\n\n"
clear(50);
System.out.println("Client: " + "\"" + tempArray.clients[index].getSurname() + "\""
+ "is going " + vacationArray.vacations[option].getHolType() + " in "
+ vacationArray.vacations[option].getArea() + " during the "
+ vacationArray.vacations[option].getTimeOfYear());
System.out.println("\nOther people going on this vacation are:"
String output = "";
for (int i = 0;i < tempArray.nextFreeLocation;i++)
{ //destination in client constructor is made to null
System.out.println("place 1 " + i);
if (tempArray.clients.getDestination() == null)
{
System.out.println("place 2 " + i);
continue;
}
System.out.println("place 3 " + i + "destination = " + tempArray.clients.getDestination());
if (tempArray.clients.getDestination().equals(vacationArray.vacations[option])) {
System.out.println("place 4 " + i);
output = output + tempArray.clients.getSurname() + "\n";
}
System.out.println("place 5 " + i);
}
System.out.print(output);
clear(5);
mainMenu();
return;
}
----------------------------------------------------------
It's the " if (tempArray.clients.getDestination().equals(vacationArray.vacations[option])) " bit towards the bottom that reffuses to match up objects.
I do know that Object.equals() when comparing objects, is the most strict method, but why is it not matching???
Here's the output I get:
--------------------Output------------------------------
Client: "Burt"is going Hiking in New Hampshire during the Autumn
Other people going on this vacation are:
place 1 0
place 3 0destination = Area: New Hampshire
Holiday Type: Hiking
Minimum Cost: £200
Maximum Cost: £300
Time Of Year: Autumn
place 5 0
place 1 1
place 2 1
place 1 2
place 2 2
place 1 3
place 3 3destination = Area: New Hampshire
Holiday Type: Hiking
Minimum Cost: £200
Maximum Cost: £300
Time Of Year: Autumn
place 4 3
place 5 3
place 1 4
place 2 4
place 1 5
place 2 5
Burt
--------------------------------------------------------
"Burt" is the actual output I would expect the method to produce, since this is the client I set the specific vacation to, but I would like to point out that place x is the flag so I can see how far each iteration goes, the number after that is the array index of the customers.
It should pick up that array element '3' holds exactly the same instance and place Wardell before "Burt".
Anyway, If anyone understood that I'd just like to see what anyone thinks is the problem?? or if there's another way to do it...
Cheers every1.
Oxi we are all of us living in the gutter.
But some of us are looking at the stars.