• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

method call not responding correctly

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 JButton("Finish and Save");

finish.addActionListener(
new ActionListener()
{

public void actionPerformed(ActionEvent event)
{
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()
{
return quantity;
}


public void setPricePerItem(double price)
{
pricePerItem = (price < 0.0) ? 0.0: price;
}

public double getPricePerItem()
{
return pricePerItem;
}

public double getPayAmount(int qty, double price)
{
return getQuantity() * getPricePerItem();
}

}



interface Payable
{
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?

Patty
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Patty Kingsmill
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that was the ticket.

Patty
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic