Hi
I am trying to learn java, because my company is moving to java, and I wrote simple applet that will take an integer multiply it by 2 and send the output to a textbox. This works great, but I cannot find anywhere, how I would do this if it was a float; like if I was computing the tax on an amount Exp. 2 * 1.08 then the textbox would get 2.16. What would I need to change in the program below to do this? Any ideas would really be appreciated.
Thank You
here is the code that I have to handle the Integer.
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class taxTotal extends Applet implements ActionListener
{
int amt;
TextField inputAmt;
TextField OutPut;
Label amtlbl;
Label total;
Button Enter;
public void init()
{
amtlbl = new Label("Enter the total without tax");
add(amtlbl);
inputAmt = new TextField( 10 );
add(inputAmt);
total = new Label("total with tax");
add(total);
OutPut = new TextField( 10 );
OutPut.setEditable( false );
add(OutPut);
Enter = new Button("Enter");
Enter.addActionListener(this);
add(Enter);
}
public void actionPerformed(ActionEvent e )
{
computAmt();
}
public void computAmt()
{
int Subtot;
int sum;
sum = Integer.parseInt(inputAmt.getText());
Subtot = sum * 2;
OutPut.setText(Integer.toString(Subtot));
}
}
I am trying to learn java, because my company is moving to java, and I wrote simple applet that will take an integer multiply it by 2 and send the output to a textbox. This works great, but I cannot find anywhere, how I would do this if it was a float; like if I was computing the tax on an amount Exp. 2 * 1.08 then the textbox would get 2.16. What would I need to change in the program below to do this? Any ideas would really be appreciated.
Thank You
here is the code that I have to handle the Integer.
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class taxTotal extends Applet implements ActionListener
{
int amt;
TextField inputAmt;
TextField OutPut;
Label amtlbl;
Label total;
Button Enter;
public void init()
{
amtlbl = new Label("Enter the total without tax");
add(amtlbl);
inputAmt = new TextField( 10 );
add(inputAmt);
total = new Label("total with tax");
add(total);
OutPut = new TextField( 10 );
OutPut.setEditable( false );
add(OutPut);
Enter = new Button("Enter");
Enter.addActionListener(this);
add(Enter);
}
public void actionPerformed(ActionEvent e )
{
computAmt();
}
public void computAmt()
{
int Subtot;
int sum;
sum = Integer.parseInt(inputAmt.getText());
Subtot = sum * 2;
OutPut.setText(Integer.toString(Subtot));
}
}