I am working on a school assignment and I have run into an issue where I am creating 4 objects and in each object I have to get a total price of all the items in the order. So I create 4 order objects and I fill it with information, one of the items is "final price" and for the first object everything is fine the total keeps going up as needed, but when the loop is done and a new object is created the new object keeps the "final price" value and does not reset back to zero. I thought when a new object was created it would go back to zero and start a new final price value. Can anyone take a look at this file and see if I am doing something wrong (which I am sure I am)
If you want the other files to do this here they are:
It would help if you could point to a line of code or an output that shows your error. Otherwise, to help you, I first have to figure out what you mean by "when the loop is done" and where you're creating this object and what evidence you have that the amount is incorrect.
Ralph Cook wrote:It would help if you could point to a line of code or an output that shows your error. Otherwise, to help you, I first have to figure out what you mean by "when the loop is done" and where you're creating this object and what evidence you have that the amount is incorrect.
I have updated the file with some comments on what is going on in the GadetOrderTake file, and below is the output when I try to do the orders...
12.99Quantity is: 1
7.55Quantity is: 1
9.99Quantity is: 1
6.89Quantity is: 1
Above is the first object and I just have system outs showing the price of the item orders, the quantity and the total price at that time, as you can see I am entering just 1 of the item and the total price is going up fine, but below is where the new object is created (so it asks for a new customer name and address) and then the total price just keeps going up where I would expect instead of 47.41 I would see 9.99
At the top of your class you've got a bunch of working variables, some of which are declared as static. You might want to think about why you've made some of them class (static) variables, and some instance variables, and what the difference is between those.
(You might also ask yourself which of those variables should really be declared at the class level and which should be local to the main method.)
I just want to say thanks guys...I went back and reviewed static variables and from what I understand now is that because they where static it was only making one variable and all the objects I was making where accessing the one variable. I say this only because maybe I am still wrong, but once I read that I cleaned up the top of my file and moved the variables to a different spot and it now works