File file = new File(fileName);
Scanner input = new Scanner(file);
//input.useDelimiter("\n");
double c;
int q;
String d ;
while(input.hasNextLine()){
c = input.nextDouble(); //get the double value cost
q = input.nextInt(); //get the integer value quantity
d = input.nextLine(); //get the String description
items[countItems] = new Item(d,c,q);
countItems++;
}
and it creates an array of Item class objects, then I can use a copy constructor and print the array and it's fields.
But when I want to add to the array, a new Item, I create the item
Item add = new Item(d,c,q);
and I want to check if there is already an item that matches the description of the new item
for(int i = 0; i<countItems; i++){
s1 = add.getDescription();
s2 = it[i].getDescription();
System.out.println(s1);
System.out.println(s2);
if(s1.equalsIgnoreCase(s2))
System.out.println("There is a match");
else
System.out.println("No match found");
}
When I print to the screen I see the string in s2 has a few space before it, therefore I never get a match on the s1 and s2 descriptions. I believe this is caused from using
q = input.nextInt(); //get the integer value quantity
d = input.nextLine(); //get the String description
but I'm not sure how to get around it.

New Topic/Question
Reply




MultiQuote








|