This week's book giveaway is in the
We're giving away four copies of a choice of
"Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac"
and have Joe Kissell on-line!
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Take Control of Upgrading to Yosemite
Take Control of Automating Your Mac
this week in the
method call not responding correctly
Joined: Nov 20, 2005
Dec 11, 2005 10:47:00
I can't believe this isn't working!
I am building a GUI which includes the following code (I will just post the pertinent lines):
Invoice invoices = new Invoice();
finish = new
("Finish and Save");
public void actionPerformed(
int quantity = catalogItems.getSelectedIndices().length;
double price = 10.00;
JOptionPane.showMessageDialog(null, "quantity: " + catalogItems.getSelectedIndices().length);
JOptionPane.showMessageDialog(null, "Thank you for your order. Your total is " + invoices.getPayAmount(quantity, price));
class Invoice implements Payable
private int quantity;
private double pricePerItem;
public void setQuantity(int count)
quantity = (count < 0) ? 0: count;
public int getQuantity()
public void setPricePerItem(double price)
pricePerItem = (price < 0.0) ? 0.0: price;
public double getPricePerItem()
public double getPayAmount(int qty, double price)
return getQuantity() * getPricePerItem();
double getPayAmount(int qty, double price);
There are no compiling errors but the result of the getPayAmount() is always 0. I have tried passing (4, 10.00) - answer is still 0.
I need to be hit with a clue-by-four - what am I not seeing?
Joined: Mar 22, 2005
Dec 11, 2005 11:07:00
At least in the code you posted, you never set the quantity and pricePerItem fields of Invoice, so they keep their default values of zero.
Ping & DNS
- my free Android networking tools app
Joined: Nov 20, 2005
Dec 11, 2005 11:15:00
Thanks, that was the ticket.
subject: method call not responding correctly
Customer Order project
ManyToMany relationship with extra field in the joinTable
Keep getting ioexception...please help
Trying to figure out what those mean
parameter passing (very beginner)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014