File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes file i/o Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "file i/o" Watch "file i/o" New topic

file i/o

mike hengst
Ranch Hand

Joined: Oct 19, 2002
Posts: 43
Ok I have worked this to being pretty colse to what I need. The only problem left(Ihope) is that not everything I want to be outputted to the orderout file is showing up. The data must be being passed to the super class because the output I am getting hs been calculated, which is done in the super class(Order). I am only getting the extended price with the handling charge added on. What am I not doing that is causing this???HELP. Here is the code for the two classes in question. I think it may have to do with the toString() itself and will keep working on it, bu tI would appreciate a second(or more) set of eyes to look at it...Thanks

Thank you Oh Lord<br />For the white blind light<br />A city rises from the sea<br />I had a splitting headache<br />from which the future's made<br />--morrisson
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Usually when you're continuing a previous topic, it's best to put your new post as an "Add" to the existing topic, rather than as a separate topic. The old topic will appear "new" once it has a new post in it (i.e. the date/time appearing next to the topic will be the date/time of the most recent post, and the topic will appear at the top of the topic list until something even newer is posted). By adding to the previous post, you make it easier for everyone to have the complete context of your problem. And you prevent anyone from wasting their time responding to the original post if you've already solved some of the problems (as in this case) - they can see the most recent version of your code in the same thread, without having to search elsewhere. Which is usually easier for all of us. Anyway...
I think your primary problem right now is in the OrderWithCharge toString() method. You call super.toString() - but you don't do anything with the String that this method returns. I think you want to append this to your StringBuffer somewhere, e.g.:

Some other observations...
In class ProcessOrders:
The various private static arrays aren't used for anything, are they? If you do need to save the order info for use later, I'd use either a single OrderWithCharge[] array, or a Collection such as ArrayList containing OrderWithCharge elements.
Initializing all your array lengths to 4 seems questionable - what if this number needs to change later? I'd replace each 4 with a variable (probably static and final), such as MAX_RECORD_COUNT. Then it's easy to change later if you need to. OF course, if you use some sort of Collection you probably won't need to specify a maximum size anyway - the Collection will simply grow as you add elements to it.
Inside the processOrder() method, there seems to be a lot of redundant stuff. The OrderWithCharge constructor appears to set name,id,qt,prc,item - there's no need to set these again immediately after using owc.setCustName(name) etc.
In class OrderWithCharge:
Again, the static arrays are pretty suspicious looking - why are they needed? It seems that all the data you need are already declared as instance (non-static) fields of either Order or OrderWithCharge - just use these fields.
It looks like your computeCharges() method is doing a lot more work than it needs to - for each individual order, it's rereading the quantities and recalculating the charges for all the orders. Why? It seems that quantities have already been read from the orderin.txt file - are the quantities in charges.dat different? If they are, then you shoudl probably use different names to distinguish the two types of quantitites. In any event, if you need to read the file charges.dat in addition to orderin.txt, just do it once, in a static method somewhere - and put the data you've read into the appropriate fields in your array/Collection or OrderWithCharge objects.
Hope that helps. Good luck...
[ December 15, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: file i/o
jQuery in Action, 3rd edition