import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class itax extends MIDlet implements CommandListener
{
private Display display;
private Form main;
private Form main1;
private Command exit;
private Command calculate;
private Command back;
private Command reset;
private TextField tname;
private TextField tage;
private TextField tmin;
private TextField tperks;
private TextField tded;
private TextField tmedi;
private TextField tihsg;
private TextField ttax;
private TextField ttaxinc;
private ChoiceGroup gender;
private int currentgender;
public itax()
{
display=Display.getDisplay(this);
exit =new Command("Exit",Command.EXIT,1);
calculate =new Command("Calculate",Command.SCREEN,1);
back =new Command("Back",Command.SCREEN,1);
reset =new Command("reset",Command.SCREEN,1);
tname = new TextField("name","",30,TextField.ANY);
tage = new TextField("age","",3,TextField.NUMERIC);
tmin = new TextField("Monthly Income","",10,TextField.NUMERIC);
tperks = new TextField("Perks","",10,TextField.NUMERIC);
tded = new TextField("Deductions (80c)","",10,TextField.NUMERIC);
tmedi = new TextField("Mediclaims","",5,TextField.NUMERIC);
tihsg = new TextField("Interest on housin loan","",10,TextField.NUMERIC);
ttax = new TextField("TAX","",30,TextField.ANY);
ttaxinc = new TextField("TAXABLE INCOME","",30,TextField.ANY);
gender =new ChoiceGroup("Select your gender",Choice.EXCLUSIVE);
gender.append("Male",null);
gender.append("Female",null);
main = new Form("Main");
main1 =new Form("MAIN1");
main.append(tname);
main.append(tage);
main.append(tmin);
main.append(tperks);
main.append(gender);
main.append(tded);
main.append(tmedi);
main.append(tihsg);
main1.append(ttaxinc);
main1.append(ttax);
main.addCommand(exit);
main.addCommand(calculate);
main.addCommand(back);
main.addCommand(reset);
main1.addCommand(exit);
main1.addCommand(calculate);
main1.addCommand(back);
main1.addCommand(reset);
main.setCommandListener(this);
main1.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(main);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void commandAction(Command command,Displayable displayable)
{
try
{
if(command==exit)
{
destroyApp(true);
}
else
if(command==calculate)
{
display.setCurrent(main1);
currentgender= gender.getSelectedIndex();
String same =tname.getString();
String sgender=gender.getString(currentgender);
String smin =tmin.getString();
double imin=getNumber(smin);
String sperks =tperks.getString();
double iperks=getNumber(sperks);
String sded =tded.getString();
double ided=getNumber(sded);
String smedi =tmedi.getString();
double imedi=getNumber(smedi);
String sihsg =tihsg.getString();
double iihsg=getNumber(sihsg);
if(iihsg>150000)
iihsg=150000;
if(ided>100000)
ided=100000;
if(imedi>15000)
imedi=15000;
double taxableincome=(12*imin)+iperks-iihsg-ided-imedi;
double tax=0;
if(sgender=="Male" )
{
if(taxableincome>150000 & taxableincome<=200000)
tax =taxableincome*0.10;
if(taxableincome>200000 & taxableincome<=300000)
tax =taxableincome*0.20;
if(taxableincome>300000)
tax =taxableincome*0.30;
}
else
if(sgender=="Female")
{
if(taxableincome>175000 & taxableincome<=200000)
tax =taxableincome*0.10;
if(taxableincome>200000 & taxableincome<=300000)
tax =taxableincome*0.20;
if(taxableincome>300000)
tax =taxableincome*0.30;
}
String s="";
s=s+tax;
ttax.setString(s);
s="";
s=s+taxableincome;
ttaxinc.setString(s);
}
if(command ==reset)
{
tname.setString("");
tage.setString("");
tmin.setString("");
tded.setString("");
tperks.setString("");
tmedi.setString("");
tihsg.setString("");
}
if(command== back)
{
display.setCurrent(main);
}
}
catch(Exception e)
{
}}
private double getNumber(String str)throws NumberFormatException
{
double val=Double.parseDouble(str);
return val;
}}
Output