Source:
// Question 12.8
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class q128 extends Applet implements ActionListener
{
private Label SalaryLbl;
private TextField SalaryTxt;
int salary;
float tax;
public void init()
{
SalaryLbl = new Label ("Enter your salary");
add (SalaryLbl);
SalaryTxt = new TextField (10);
SalaryTxt.addActionListener (this);
add (SalaryTxt);
}
public void paint (Graphics g)
{
tax = findTax (salary);
g.drawString ("The tax you have to pay is RM" + tax,
30, 60);
}
public void actionPerformed (ActionEvent e)
{
salary = Integer.parseInt (SalaryTxt.getText());
repaint();
}
private float findTax(int income)
{
int taxable = 0;
if (income <= 10000)
return 0;
else
{
taxable = income - 10000;
float tax = (float) taxable * 33 / 100;
return Math.round (tax);
}
}
}