This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Bug in code, need an outside perspective - cannot figure it out. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Bug in code, need an outside perspective - cannot figure it out." Watch "Bug in code, need an outside perspective - cannot figure it out." New topic
Author

Bug in code, need an outside perspective - cannot figure it out.

Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
hey, basically i have programmed a nextFit algorithm that is a cable ordering system. the user orders a length and type of cable and the program processes the order cutting the cable that is required at the required length. the orders are generated using a seperate class and are passed as a parameter to the algorithm to be processed.
i have this code working; however - it works only for the first run of each type of cable.

e.g.

-programme starts
-one order gets processed for 28m of aluminium,
-there is no aluminium in the store so more is ordered (a random integer between 100 and 200 used to represent the length ordered)
-the 28m gets taken of the ordered aluminium, say 190m was ordered from the store, the remaining aluminium after this has been processed is 168m

then after this one run, when another order of aluminium is processed, it does not take the value off the remaining aluminium variable.

i dont know if this is something to do with using the same object to process all the data?? but it should work. i cannot see the bug anywhere and have been looking for hours to no avail. the code for the class with the bug is below. any help much appreciated.


~ Jeff Yan ~
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
anybody?
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
You only check if the orderlength is greater than the remaining aluminium length. But what is if it is NOT greater?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Jeff Yan wrote:anybody?

PatienceIsAVirtue.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Jeff Yan wrote:anybody?

You waited like 30 minutes--not long enough--so you get code comments.

- The use of non-standard Java naming conventions will slow down some Java developers (like me) as they read over your code: in general, member variables should be named starting with a lower-case letter.
- Access should always be specified instead of using the default.
- The initialization you *think* you doing in your constructor isn't; those are local to the constructor.
- The class is a jumble of concerns and functionality--not necessarily an issue, but even something this short becomes more difficult than necessary to understand and debug.
- Along with that, make sure that duplicated code is identified and removed as early in the process as possible.
- Notably, the block of code for ordering copper and ordering aluminium are essentially identical: in this case, that indicates something funky in the design process.
- Note that OrderProcess is recursive: I can think of no good reason to make it so.
- Be wary of making things instance variables that don't need to be: relying on side effects can make debugging... troublesome.
- You spelled aluminum wrong. (Okay, I'm kidding with that one
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
sorry for the impatience, i was getting stressed about it! and the code is just a basic outline it needs refinement, but the first answer hit the nail on the head, so thank you for that. problem resolved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bug in code, need an outside perspective - cannot figure it out.