File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

duplicate item

 
Shananne DuFrame
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
wondering if anyone could help me out. Been trying this one out for awhile. I am trying to get the following to work:

macaroni was duplicated in the list.

This is suppose to be one of my first output lines.
I already have the Exception line working.
I have tried to code the duplicated item several times. Any help in the right direction would be appreciated.

I bolded where I believe my problem is.



This is my results:
Enter the input file name: C:\\TestFile5.txt

InvalidAisleException: Aisle must be 1-5: turkey shows aisle 9

The file C:\\TestFile5.txt contains the following items:
macaroni in aisle 3
chips in aisle 2
macaroni in aisle 3
salsa in aisle 1

The list print by item is:
chips in aisle 2
macaroni in aisle 3
macaroni in aisle 3
salsa in aisle 1

The list printed by aisle is:


----jGRASP: operation complete.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47222
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you aren't getting the Exception where you think you are.
You have indented your code incorrectly, which leads you to believe that "if(aisle > 5)" is part of the if(item.compareTo . . .) block. It isn't. It is independent.
Check carefully what you have in the text file against "turkey."

BTW: How are you working out your elements.getItem()? A compareTo doesn't give -1 when there is a duplicate. I think you are actually using your Grocery class as a Collection and you want a contains() method in it.

Find a copy of Deitel's book and you will see that every } is followed by a trailing comment. A useful habit to get into. Most people think that a programmer's text editor is a word processor, and you enter an "if" block like this:
Stage 1Stage 2Stage 3Stage 4But you shouldn't. You should do it like this:
Stage 1Stage 2Stage 3stage 4Two benefits:
  • Less risk of compiler errors because you have unbalanced {}s.
  • A comment which reminds you which block ends where.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic