Introduction




Name of Experiment: To Implement If Else Conditional Statement on NOKIA ASHA 501

Exp No: 6

Background: Student should have a basic knowledge of Java Programming.

Summary: After going through this experiment, student should be able to implement if else conditional statement on NOKIA Asha 501 device.

Learning Objective: Here, Student should learn the procedure to to implement if else conditional statement on NOKIA Asha 501 device. After, doing this experiment user himself will be able to make an app to able to implement if else conditional statement on NOKIA Asha 501 device.

Target

Target Platform:This experiment is tested on Nokia Asha Device 501.

Procedure

SourceCode

Source Code:

importjavax.microedition.lcdui.Alert;
importjavax.microedition.lcdui.Command;
importjavax.microedition.lcdui.CommandListener;
importjavax.microedition.lcdui.Display;
importjavax.microedition.lcdui.Displayable;
importjavax.microedition.lcdui.Form;
importjavax.microedition.lcdui.TextField;
importjavax.microedition.midlet.MIDlet;
importjavax.microedition.midlet.MIDletStateChangeException;

publicclassAge_testextendsMIDletimplementsCommandListener {
Form age;
TextFieldinputage;
Alert alert;
Command displayage;
publicAge_test() {
// TODO Auto-generated constructor stub
age = new Form("AGE TEST");
inputage = newTextField("ENTER YOUR AGE : ", "", 3, TextField.NUMERIC);
displayage = new Command("ok",Command.OK , 0);
String name="\nNicyKaurTaneja Roll no. 22\n VandanaKumari Roll no. 33";
age.append(name);
age.append(inputage);
age.addCommand(displayage);
age.setCommandListener(this);
}
protectedvoiddestroyApp(boolean arg0) throwsMIDletStateChangeException {
// TODO Auto-generated method stub
}
protectedvoidpauseApp() {
// TODO Auto-generated method stub
}
protectedvoidstartApp() throwsMIDletStateChangeException {
// TODO Auto-generated method stub
Display.getDisplay(this).setCurrent(age);
}
publicvoidcommandAction(Command c, Displayable d) {
int age1 = Integer.parseInt(inputage.getString());
if(c == displayage)
{
if(age1 <= 16)
{
alert = new Alert("You are a child");
Display.getDisplay(this).setCurrent(alert);
}
elseif((age1 > 16) && (age1 < 60))
{alert = new Alert("You are an adult");
Display.getDisplay(this).setCurrent(alert);
}
elseif((age1 > 60) && (age1 < 200))
{ alert = new Alert("You are old");
Display.getDisplay(this).setCurrent(alert);
}
else { alert = new Alert("INVALID AGE");
Display.getDisplay(this).setCurrent(alert);
}
}}}

Snapshots



This is how the output appears on the emulator of NOKIA Asha SDK 1.0 on successful compilation of source code.

Observation

Observation: In this program we perform the conditional program, which check for the condition and give output according to the condition. In this program we took the case of age which display according to condition. We also use command button by implementing command action and if condition does not satisfy, display an alert.

Video Link

Download