I've been coding one of my final school projects related to a text file based on weddings. I am trying to code a method that will return a wedding object,
(NOTE: weeding object consists of a brideName, groomName, weddingDate, Venue, number of Guests).
In a normal method using Strings. For example, I would merely type
String temp = "";
run a loop to loop through my array. if statement
temp = temp + arr[loop].toString();
return temp;
But now dealing with a wedding object when I declare it:
Wedding temp; - (As i cant initialize it as there is no brideName etc.)
run loop
if statement
temp = temp + array[loop];
return temp;
Here is where i get the error of temp may not have been initialized.
Could anyone help with a suggestion of how to fix this? Thank you so much Here is what the actual method looks like
public Wedding getWeddingsOnDay(String date, String venue)
{
Wedding temp;
for (int loop = 0; loop < counter; loop++)
{
if (wedArr[loop].getWeddingDate().equals(date) && wedArr[loop].getVenue().equals(venue))
temp = wedArr[loop];
else
temp = null;
}
return temp;
}