INDEX Sr. No. Practical Signature 1 Write a program in J2ME to perform the simple calculator operations such as: a. Addition b. Subtraction c. Multiplication d. Division 2 Write a program in J2ME to create a simple Quiz which content 3 to 4 questions and also display the score. 3 Write a program in J2ME to create a currency converter and also display the result. 4 Write a program in J2ME to generate a calendar. 5 Write a program in J2ME to demonstrate simple animation through snake movement. 6 Write a program in J2ME to create a simple application with an address book with the help of Record Store. 7 Write a program in J2ME to create a simple database application with an address book with the following operations: a. Insert b. Delete c. Update d. Retrieve 8 Program in J2MEto perform the following tasks: a. Create a form1 that contain Label & TextBox,Next Button. b.Create a form2 that contain checkBox, radioButton ,TextArea& Next, Back Button. c.Create a form3 that contains Display of all above forms. 9 Write a ticker program to continuously scroll a message on the mobile screen. PRACTICAL No. 1 AIM:Write a program in J2ME to perform the simple calculator operations such as - a. Addition b. Subtraction c. Multiplication d. Division Program: import javax.microedition.lcdui.*; import javax.microedition.midlet.*; import java.io.*; public class calculator extends MIDlet implements CommandListener { private Form form; private Display display; private TextField input1, input2; private Command add, sub, mul,div; private StringItem item; public calculator() { } public void startApp() { display = Display.getDisplay(this); Form form = new Form("Calculator"); form.append("Hello everybody"); item = new StringItem("Result", ""); input1 = new TextField("First Number:", "", 30, TextField.NUMERIC); input2 = new TextField("Second Number", "", 30, TextField.NUMERIC); form.append(input1); form.append(input2); add = new Command("Addition", Command.OK, 1); sub = new Command("Subtraction", Command.OK, 1); mul = new Command("Multiplication", Command.OK, 1); div = new Command("Division", Command.OK, 1); form.addCommand(add); form.addCommand(sub); form.addCommand(mul); form.addCommand(div); form.append(item); form.setCommandListener(this); display.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean uncondn) { notifyDestroyed(); } private void calculate() { int one=Integer.parseInt(input1.getString()); int two= Integer.parseInt(input2.getString()); int result=one+two; item.setText( result + "" ); } private void calculate1() { int one = Integer.parseInt(input1.getString()); int two = Integer.parseInt(input2.getString()); int result = one - two; item.setText(result + ""); } private void calculate2() { int one = Integer.parseInt(input1.getString()); int two = Integer.parseInt(input2.getString()); int result = one * two; item.setText(result + ""); } private void calculate3() { int one = Integer.parseInt(input1.getString()); int two = Integer.parseInt(input2.getString()); int result = one / two; item.setText(result + ""); } public void commandAction(Command c, Displayable d) { String label = c.getLabel(); if (label.equals("Addition")) { calculate(); } else if (label.equals("Subtraction")) { calculate1(); } else if (label.equals("Multiplication")) { calculate2(); form.append("The Answer is:"); } else if (label.equals("Division")) { calculate3(); form.append("The Answer is:"); } } } Output: PRACTICAL No. 2 Write a program in J2ME to create a simple Quiz which content 3 to 4 questions and also display the score. Program: import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class QuizMidlet extends MIDlet implements CommandListener { private Display display; private Form form1,form2,form3,form4,form5; private ChoiceGroup ch1,ch2,ch3,ch4; private Command next; private Command back; private Command ok; private Command exit; private StringItem st; int count=0; public QuizMidlet() { display=Display.getDisplay(this); next=new Command("Next",Command.OK,1); back=new Command("Back",Command.BACK,1); st=new StringItem("Total correct answers","0"); form1=new Form("1.J2ME is?"); ch1=new ChoiceGroup("",Choice.EXCLUSIVE); ch1.append("mobile java", null); ch1.append("java automatic", null); ch1.append("standard java", null); ch1.append("for serverside", null); form1.append(ch1); form1.addCommand(next); form1.setCommandListener(this); form2=new Form("2.What is JAVA?"); ch2=new ChoiceGroup("",Choice.EXCLUSIVE); ch2.append("Object Oriented Program",null); ch2.append("Assembly Language",null); ch2.append("Modeling Language",null); ch2.append("System Software",null); form2.append(ch2); form2.addCommand(next); form2.addCommand(back); form2.setCommandListener(this); form3=new Form("3.Root of 625?"); ch3=new ChoiceGroup("",Choice.EXCLUSIVE); ch3.append("15", null); ch3.append("35", null); ch3.append("45", null); ch3.append("25", null); form3.append(ch3); form3.addCommand(next); form3.addCommand(back); form3.setCommandListener(this); form4=new Form("4.Class is a collection of ?"); ch4=new ChoiceGroup("",Choice.EXCLUSIVE); ch4.append("variables", null); ch4.append("objects ", null); ch4.append("operations", null); ch4.append("interfaces", null); form4.append(ch4); form4.addCommand(next); form4.addCommand(back); form4.setCommandListener(this); form5=new Form("Score"); exit=new Command("Exit",Command.SCREEN,1); ok=new Command("Submit",Command.OK,2); form5.addCommand(ok); form5.addCommand(exit); form5.setCommandListener(this); } public void startApp() { display.setCurrent(form1); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command cmd,Displayable displayable) { if(displayable==form1) { if(cmd==next) display.setCurrent(form2); } else if(displayable==form2) { if(cmd==next) display.setCurrent(form3); else if(cmd==back) display.setCurrent(form1); } else if(displayable==form3) { if(cmd==next) display.setCurrent(form4); else if(cmd==back) display.setCurrent(form2); } else if(displayable==form4) { if(cmd==next) { if(ch1.getSelectedIndex()==0) count++; if(ch2.getSelectedIndex()==0) count++; if(ch3.getSelectedIndex()==3) count++; if(ch4.getSelectedIndex()==1) count++; st.setText(String.valueOf(count)); form5.append(st); display.setCurrent(form5); } } else if(displayable==form5) { if(cmd==ok) { display.setCurrent(form5); } else if(cmd==exit) { destroyApp(false); notifyDestroyed(); } } } } Output: PRACTICAL No. 3 Write a program in J2ME to create a currency converter and also display the result. Program: import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class currency extends MIDlet implements CommandListener { private Display display; private Form Input; private TextField inr; private Command convert; public currency() { display = Display.getDisplay(this); Input = new Form("INR to USD Converter"); inr = new TextField("Enter INR:", null, 10, TextField.DECIMAL); convert = new Command("Convert", Command.SCREEN, 1); Input.append(inr); Input.addCommand(convert); Input.setCommandListener(this); } public void startApp() { /* Display form */ display.setCurrent(Input); } public void pauseApp() { /* pass */ } public void destroyApp(boolean unconditional) { /* pass */ } public void commandAction(Command c, Displayable d) { String text = null; long rs = 0; int paise = 0; long dollor = 0; long cent = 0; String final_dollar = null; if (c == convert) { text = inr.getString(); paise = text.indexOf('.'); if (paise == -1) { rs = Long.parseLong(text) * 100; } else { rs = Long.parseLong(text.substring(0, paise)) * 100; paise = Integer.parseInt(text.substring((paise+1), text.length())); rs = rs + paise; } dollor = rs * 100 / 4470; cent = dollor % 100; dollor = dollor / 100; final_dollar = String.valueOf(dollor) + "." + String.valueOf(cent); Alert alert = new Alert("US Dollor", final_dollar + "$", null,AlertType.INFO); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } } } Output: PRACTICAL No. 4 Write a program in J2ME to generate a calendar. Program: import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; import java.util.Date; import java.util.TimeZone; public class calender extends MIDlet { private Form form; private Display display; private DateField calender; private static final int DATE = 0; public calender(){ calender = newDateField("DateIn:",DateField.DATE,TimeZone.getTimeZone("GMT")); } public void startApp() { display = Display.getDisplay(this); Form form = new Form("Calender"); form.append(calender); display.setCurrent(form); } public void pauseApp(){} public void destroyApp(boolean destroy) { notifyDestroyed(); } } Output: PRACTICAL No. 5 Write a program in J2ME to demonstrate simple animation through snake movement. Program: import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class MySnake extends MIDlet implements CommandListener { DrawSnake ds; Display dis; public MySnake() { dis=Display.getDisplay(this); ds=new DrawSnake(); } public void startApp() { dis.setCurrent(ds); } public void commandAction(Command c,Displayable d) {} public void pauseApp() {} public void destroyApp(boolean unconditional) {} } class DrawSnake extends Canvas implements Runnable, CommandListener { int x,y,dir; Thread th; Command quit; public DrawSnake() { x=0; y=0; dir=0; quit=new Command("QUIT",Command.SCREEN,1); addCommand(quit); setCommandListener(this); th=new Thread(this); th.start(); } public void commandAction(Command c,Displayable d) { if(c==quit){} //notifyDestroyed(); } public void keyPressed(int cd) { switch(getGameAction(cd)) { case Canvas.UP: y-=5;