so I've been having an issue with equalsIgnoreCase() in java where it is given two strings that should be entirely identical, but not returning my expected result.
I'll just start with my code here:
public void readBunnyFile(String fileIn) throws FileNotFoundException {
Scanner fileScanner = new Scanner(new File(fileIn));
listName = fileScanner.nextLine().trim();
while (fileScanner.hasNext()) {
String type = fileScanner.next().trim() + " " + fileScanner.next().trim();
if (type.equalsIgnoreCase("pet bunny")) {
Scanner lineScanner = new Scanner(fileScanner.nextLine());
lineScanner.useDelimiter(",");
String name = lineScanner.next().trim();
String breed = lineScanner.next().trim();
double weight = Double.parseDouble(lineScanner.next());
PetBunny pB = new PetBunny(name, breed, weight);
addBunny(pB);
}
if (type.equalsIgnoreCase("house bunny")) {
Scanner lineScanner = new Scanner(fileScanner.nextLine());
lineScanner.useDelimiter(",");
String name = lineScanner.next().trim();
String breed = lineScanner.next().trim();
double weight = Double.parseDouble(lineScanner.next());
double wearAndTear = Double.parseDouble(lineScanner.next());
HouseBunny hB = new HouseBunny(name, breed, weight, wearAndTear);
addBunny(hB);
}
if (type.equalsIgnoreCase("jumping bunny")) {
Scanner lineScanner = new Scanner(fileScanner.nextLine());
lineScanner.useDelimiter(",");
String name = lineScanner.next().trim();
String breed = lineScanner.next().trim();
double weight = Double.parseDouble(lineScanner.next());
double trainingCost = Double.parseDouble(lineScanner.next());
JumpingBunny jB = new JumpingBunny(name, breed, weight, trainingCost);
addBunny(jB);
}
if (type.equalsIgnoreCase("show bunny")) {
Scanner lineScanner = new Scanner(fileScanner.nextLine());
lineScanner.useDelimiter(",");
String name = lineScanner.next().trim();
String breed = lineScanner.next().trim();
double weight = Double.parseDouble(lineScanner.next());
double groomingCost = Double.parseDouble(lineScanner.next());
ShowBunny sB = new ShowBunny(name, breed, weight, groomingCost);
addBunny(sB);
}
else {
Scanner lineScanner = new Scanner(fileScanner.nextLine());
lineScanner.useDelimiter(",");
addExcludedRecord(type + lineScanner.nextLine());
}
}
The file that this is reading looks like the following:
Bunny Collection
Pet bunny, Floppy, Holland Lop, 3.5
house Bunny, Spot, Really Mixed, 5.8, 0.15
mouse Bunny, Spots, Mixed, 0.8, 0.15
Jumping Bunny, Speedy, English, 6.3, 25.0
fighting bunny, Slugger, Big Mixed, 16.5, 21.0
Show bunny, Bigun, Flemish Giant, 14.6, 22.0
I've watched my debugger go down countless times with a type value of "Pet bunny" yet it never steps into the if statement, and only goes to the else statement. Is there something I'm logically doing wrong here? "Pet bunny" should be equal to "pet bunny" since I am using .equalsIgnoreCase, right?