Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
I have created a submit button sButton; that should take all totals from 3 boxes and if that total is greater than 1, then it should be subtracted from 1 and the remainder is suppose to be displayed as change...this is what i have
Java
if(evt.getSource()==sButton)
{
   change.setText(---'I DON'T KNOW WHAT TO PUT HERE')
   selections.setText('Vending....');
}


and in another class to add up the 3 totals i have

Java
public String total5()
{
    total5=total+total2+total3+total4;
    String blank =new String();
    blank=''+total5;
    return blank;
}

so my question is how do i use the total5 to compare if it's over 1 or less and display if it's over in the "change.setText( )"; text box?
Posted
Updated 2-Nov-10 6:45am
v2
Comments
Nagy Vilmos 2-Nov-10 12:45pm    
Updated with pre-tags

1 solution

If you change total method to return a number:
Java
double getTotal()
{
   return (total+total2+total3+total4);
}


You can then use it in your event handler:
Java
if(evt.getSource()==sButton)
{
   double total = obj.getTotal();
   if (total < 1)
   {
      change.setText("Not enough");
      return;
   }

   change.setText("Change $" + (total-1);
   selections.setText("Vending....");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900