I have 2 classes: MyZoo & Animal.
With my current code, I am focusing on my method readDataFromFile() which reads tab separated
text files like this:
Bird Golden Eagle Eddie
Mammal Tiger Tommy
Mammal Lion Leo
Bird Parrot Polly
Reptile Cobra Colin
With my current scanner method, I have split each column up so that I can call individually..The issue is that the first line contains 'Golden Eagle' which are both separated by a Tab, so that the scanner picks up 'Golden Eagle as 2 separate words instead of 1 for species
. The Current Output:
Bird Golden Eagle <---- (Missing Eddie)
Mammal Tiger Tommy
Mammal Lion Leo
Bird Parrot Polly
Reptile Cobra Colin
How would I go about using a 'useDelimiter()'
method to fix this?
My Code:
while(scanner.hasNextLine())
{
String type = scanner.next();
String species = scanner.next();
String name = scanner.next();
System.out.println(type + " " + species + " " + name);
scanner.nextLine();
addAnimal( new Animal(species, name, this) );
}