My project was already due, and incomplete but I would still like to better understand a few things.
I have three classes. A Photo Class, PhotoAlbum Class, and a CommandLineMenu class.
Each photo has a subject, location, date, and path.
the PhotoAlbum is an array of different photo objects. I needed to make a method to search for photos by location and return an array of 0 or more photos.
the only way I could get it to even search for the word was writing the Album data to a file and then reading that file. This didnt even return a photo object but only the line of the file where the string was found.
How can I achieve to return a photo?
Search method:
public void findByLocation()
{
Scanner instream = new Scanner(System.in);
System.out.println("find by location");
System.out.print("Enter Location: ");
String locale = instream.next();
try {
BufferedReader bf = new BufferedReader(new FileReader("photos" + "/" + "album.dat"));
int linecount = 0;
String line;
System.out.println("Searching for " + locale + " in file...");
while (( line = bf.readLine()) != null)
{
// Increment the count and find the index of the word
linecount++;
int indexfound = line.indexOf(locale);
// If greater than -1, means we found the word
if (indexfound > -1) {
String strung = "File found on line " + linecount;
System.out.println (strung);
}
}
// Close the file after done searching
bf.close();
}
catch (IOException e) {
System.out.println("IO Error Occurred: " + e.toString());
}
}