This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
-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.
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
Joined: Nov 05, 2009
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.