• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java swing applet calculations wrong  RSS feed

 
Lauren McCabe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay so this is code I wrote for an applet that is for a user buying a computer and can purchase extra items (peripherals).  Then they select a shipping type and hit a button to calculate the total cost with or without shipping.  When I run the program and select peripherals, a shipping type, and hit either calculate button, it merely outputs the cost of the computer+added peripherals. No shippnig or discount is taken into account despite the methods I have written.  Does anyone see what might be causing this?

P.S. I attached a photo of what the applet window looks like for better understanding.
Thank you in advance!

midterm-pic.png
[Thumbnail for midterm-pic.png]
applet preview
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any examples of incorrect data, versus the correct data which you expected. It was also difficult for me to associate the variables in your code with the data in your screenshot. For example there's a variable named "quantity" but I didn't see anything in the screenshot which I could construe as a quantity. So I just scanned the code looking for unusual things. For example, line 143 is an if-condition which can only be true when quantity=1000, and when quantity is greater than 1000 then discountedPrice is zero, which I don't think is what you wanted.
 
Lauren McCabe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I don't see any examples of incorrect data, versus the correct data which you expected. It was also difficult for me to associate the variables in your code with the data in your screenshot. For example there's a variable named "quantity" but I didn't see anything in the screenshot which I could construe as a quantity. So I just scanned the code looking for unusual things. For example, line 143 is an if-condition which can only be true when quantity=1000, and when quantity is greater than 1000 then discountedPrice is zero, which I don't think is what you wanted.


Paul, sorry I should have explained better.  I am outputting the costs of fixed quantities by 100s up to 1000.  Since I am only going up to 1000,  quantities greater than 1000 won't be used.  I am using variable quantity in calcWithoutShippingButtonActionPerformed and calcWithShippingButtonActionPerformed.  I have a loop that will add 100 to the quantity and return the cost until the quantity reaches 1000.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to say, it's extremely hard on the brain to look at code with apparently random indentation. Makes it very hard to find things in the code. It would be much better if your code was indented in a standard way.

And you still haven't provided any examples of what you see versus what you expect to see.

However if you want the lines with quantity 100, 200, 300, and so on to have different costs, you ought to do the cost calculation for each of those lines.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!