aspose file tools
The moose likes Beginning Java and the fly likes Can't find my error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Can Watch "Can New topic
Author

Can't find my error

Ryan Mat
Greenhorn

Joined: Jan 11, 2009
Posts: 2
Sorry if this is a bad question for posting.. but I'm confused as to where I'm going wrong. The assignment is to read in different shapes from a text file and put them in a linked list.

I put here the two classes in the program that I think are relevant. The issue I'm having is that the program seems to be reading each shape in twice, so for example when I print the list I am somehow adding two of each shape rather than one. I have figured out that I can add an extra line of code somewhere, for example in the getShape() method in the Input class I can add another call of readInput(); and it will only add one of each shape to the linked list. Similarly in the ShapeDriver constructor while loop I can say i.getShape(); and it will also add each shape only once. I feel like these aren't really solutions to my error, though, just coverups.

I'm just not seeing why it seems to be reading and adding each shape twice.

In case it helps the input text file looks something like this

Circle
4.0
Square
2.2
2.2
2.2
2.2
Rectangle
3.0
2.0
3.0
2.0




Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16687
    
  19


Here are a few hints...

What happens when readInput() encounters an error condition? Does it report anything? Or does it ignore it?

What happens to getShape() when readInout() returns? Does it return the actual value from readInput? Even when readInput() encounters an error?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ryan Mat
Greenhorn

Joined: Jan 11, 2009
Posts: 2
Thanks for the response.

As far as readInput() encountering errors, it's been stated in the assignment requirements that that won't happen. I.E. there will always be the correct number of sides for each shape. In the event that a side has length zero or less than zero, that error is handled in the individual shape's class.

getShape() just calls readInput(), and readInput() simply stores the new shape it creates in the protected _shape object. That _shape object is then returned when getShape() is called.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't find my error
 
Similar Threads
Restriction on parent class
How interfaces are used for code reusability
Spring factory not creating new objects
Calling methods using dynamic binding
polymorphism