My method readDataFromFile()
can read text files like:
Bird Golden Eagle Eddie
Mammal Tiger Tommy
Mammal Lion Leo
Bird Parrot Polly
Reptile Cobra Colin
The first column is the 'Type' of animal, second column is 'Species' and third is 'Name'.
Current Output:
Bird Golden Eagle < (Golden and Eagle count as different substrings).
Mammal Tiger Tommy
Mammal Lion Leo
Bird Parrot Polly
Reptile Cobra Colin
- How would I use the
useDelimiter
method to make 'Golden Eagle' count as one species?
Current 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) );
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…