Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

DAVLEEN KAUR MATTA

BE4/B
ROLL NO-33

Shivani Rakesh Mehta


EXPERIMENT- BASIC CALCULATOR BE-3/A
Roll No.12

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class BasicCalculator extends MIDlet implements
CommandListener
{
Display d;
Form f;
TextField t1,t2;
Command add,sub,mul,div,exit;
public void startApp() {
d=Display.getDisplay(this);
f= new Form("Basic Calculator");
t1=new TextField("Number 1 : ","",100,TextField.NUMERIC);
t2=new TextField("Number 2 : ","",100,TextField.NUMERIC);
exit=new Command("EXIT",Command.EXIT,0);
add=new Command("Add",Command.OK,1);
sub=new Command("Subtract",Command.OK,2);
mul=new Command("Multiply",Command.OK,3);
div=new Command("Divide",Command.OK,4);
f.append(t1);
f.append(t2);
f.addCommand(add);
f.addCommand(sub);
f.addCommand(mul);
f.addCommand(div);
f.addCommand(exit);
f.setCommandListener(this);
d.setCurrent(f);
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c,Displayable d)
{
int a,b;
a=Integer.parseInt(t1.getString());
b=Integer.parseInt(t2.getString());
if(c==add)
{
f.append("Addition = "+(a+b)+"\n");
}
if(c==sub)
{
f.append("Subtraction = "+(a-b)+"\n");
}
if(c==mul)
{
f.append("Multiplication = "+(a*b)+"\n");
}
if(c==div)
{
f.append("Division = "+(a/b)+"\n");
}
if (c == exit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
Shivani Rakesh Mehta
BE-3/A
Roll No.12
Shivani Rakesh Mehta
BE-3/A
Roll No.12
DAVLEEN KAUR MATTA
BE4/B
ROLL NO-33

Shivani Rakesh Mehta


EXPERIMENT-LOAN EMI CALCULATOR BE-3/A
Roll No.12

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class LoanEMICalculator extends MIDlet implements
CommandListener
{
Display d;
Form f;
TextField t1,t2,t3;
Command calculate,exit;
public void startApp() {
d=Display.getDisplay(this);
f= new Form("Loan EMI Calculator");
t1=new TextField("Principal Amount :
","",100,TextField.NUMERIC);
t2=new TextField("Interest Rate (in ppa) :
","",100,TextField.NUMERIC);
t3=new TextField("Tenure (in months) :
","",100,TextField.NUMERIC);
exit=new Command("Exit",Command.EXIT,0);
calculate=new Command("Calculate",Command.OK,1);
f.append(t1);
f.append(t2);
f.append(t3);
f.addCommand(calculate);
f.addCommand(exit);
f.setCommandListener(this);
d.setCurrent(f);
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c,Displayable d)
{
if(c==calculate)
{
float principal,interest,tenure,emi;
principal=Float.parseFloat(t1.getString());
interest=Float.parseFloat(t2.getString());
tenure=Float.parseFloat(t3.getString());
emi=(principal*(1+((interest/100)*(tenure/12))))/tenure;
f.append("EMI = "+emi+"\n");
}
if (c == exit)
{
destroyApp(false);
notifyDestroyed();
Shivani Rakesh Mehta
BE-3/A
Roll No.12
DAVLEEN KAUR MATTA
BE-4/B
ROLL NO-33

EXPERIMENT-INCOME TAX CALCULATOR


Shivani Rakesh Mehta
EXPERIMENT- BE-3/A
Roll No. 12
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class IncomeTaxCalculator extends MIDlet implements
CommandListener
{
Display d;
Form f;
TextField t1;
Command calculate,exit;
public void startApp() {
d=Display.getDisplay(this);
f= new Form("Income Tax Calculator");
t1=new TextField("Annual Income :","",100,TextField.NUMERIC);
exit=new Command("Exit",Command.EXIT,0);
calculate=new Command("Calculate",Command.OK,1);
f.append(t1);
f.addCommand(calculate);
f.addCommand(exit);
f.setCommandListener(this);
d.setCurrent(f);
}
public void pauseApp() { }
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c,Displayable d)
{
if(c==calculate)
{
float income,tax;
income=Float.parseFloat(t1.getString());
f.append("Income Tax = "+(income*0.3)+"\n");
}
if (c == exit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
Shivani Rakesh Mehta
BE-3/A
Roll No.12
Shivani Rakesh Mehta
BE-3/A
Roll No.12

You might also like