0% found this document useful (0 votes)
232 views5 pages

Quiz Program in J2ME

This document defines a Java ME quiz application with the following: 1. It imports necessary packages and defines a MIDlet class to implement the quiz. 2. The MIDlet initializes forms to display questions, answers, and results. It tracks the user's score. 3. Methods handle starting the app, pausing, destroying, and responding to user commands to navigate between forms and check answers. 4. The quiz presents 5 multiple choice questions, tracks the score, and displays a results form with feedback based on the final score.

Uploaded by

Bruce Arnold
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
232 views5 pages

Quiz Program in J2ME

This document defines a Java ME quiz application with the following: 1. It imports necessary packages and defines a MIDlet class to implement the quiz. 2. The MIDlet initializes forms to display questions, answers, and results. It tracks the user's score. 3. Methods handle starting the app, pausing, destroying, and responding to user commands to navigate between forms and check answers. 4. The quiz presents 5 multiple choice questions, tracks the score, and displays a results form with feedback based on the final score.

Uploaded by

Bruce Arnold
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

import

import
import
import
import
import
import

javax.microedition.lcdui.Command;
javax.microedition.lcdui.CommandListener;
javax.microedition.lcdui.Display;
javax.microedition.lcdui.Displayable;
javax.microedition.lcdui.Form;
javax.microedition.lcdui.TextField;
javax.microedition.midlet.*;

public class quiz extends MIDlet implements CommandListener {


int score=0;
private Display display;
private Form inputpage;
String lastscore = (new Integer(score)).toString();
private TextField username;
private Command startgame;
//form1 intialize
private Form form1;
String q1 ="What is MN?\n";
private String q1ans1="1. a\n";
private String q1ans2="2. b\n";
private String q1ans3="3. All of the above\n";
private Command q1ans11;
private Command q1ans12;
private Command q1ans13;
//form2
private Form form2;
String q2 ="J2me course started by?\n";
private String q2ans1="1. a\n";
private String q2ans2="2. b\n";
private String q2ans3="3. None of the above\n";
private Command q2ans11;
private Command q2ans12;
private Command q2ans13;
//form3
private Form form3;
String q3 ="Mobile C Text Book Author\n";
private String q3ans1="1. a\n";
private String q3ans2="2. b\n";
private String q3ans3="3. None of the above\n";
private Command q3ans11;
private Command q3ans12;
private Command q3ans13;
//form4
private Form form4;
String q4 ="Which software is used to make javaME applications?\n";
private String q4ans1="1. Internetbeans\n";
private String q4ans2="2. Netbeans\n";
private String q4ans3="3. Nobeans\n";

private Command q4ans11;


private Command q4ans12;
private Command q4ans13;
//form5
private Form form5;
String q5 ="Best feature of GSM?\n";
private String q5ans1="1. Gifts\n";
private String q5ans2="2. Vidoe call\n";
private String q5ans3="3. None of above\n";
private Command q5ans11;
private Command q5ans12;
private Command q5ans13;
//form6
private Form form6;
String q6 ="Congrats \n";
public quiz (){
display = Display.getDisplay(this);
inputpage = new Form("username");
username =new TextField("Enter Your name;", "", 50, TextField.ANY);
inputpage.append(username);
startgame = new Command("Start game", 1, 1);
inputpage.addCommand(startgame);
inputpage.setCommandListener(this);
//form1 declaration
form1 = new Form("Welcome to 1st question");
q1ans11 = new Command("1", 1, 1);
q1ans12 = new Command("2", 1, 2);
q1ans13 = new Command("3", 1, 3);
form1.append(q1);
form1.append(q1ans1);
form1.append(q1ans2);
form1.append(q1ans3);
form1.addCommand(q1ans11);
form1.addCommand(q1ans12);
form1.addCommand(q1ans13);
form1.setCommandListener(this);
//form2
form2 = new Form("Welcome to 2nd question");
q2ans11 = new Command("1", 1, 1);
q2ans12 = new Command("2", 1, 2);
q2ans13 = new Command("3", 1, 3);
form2.append(q2);

form2.append(q2ans1);
form2.append(q2ans2);
form2.append(q2ans3);
form2.addCommand(q2ans11);
form2.addCommand(q2ans12);
form2.addCommand(q2ans13);
form2.setCommandListener(this);
//form3
form3 = new Form("Welcome to 3rd question");
q3ans11 = new Command("1", 1, 1);
q3ans12 = new Command("2", 1, 2);
q3ans13 = new Command("3", 1, 3);
form3.append(q3);
form3.append(q3ans1);
form3.append(q3ans2);
form3.append(q3ans3);
form3.addCommand(q3ans11);
form3.addCommand(q3ans12);
form3.addCommand(q3ans13);
form3.setCommandListener(this);
//form4
form4 = new Form("Welcome to 4th question");
q4ans11 = new Command("1", 1, 1);
q4ans12 = new Command("2", 1, 2);
q4ans13 = new Command("3", 1, 3);
form4.append(q4);
form4.append(q4ans1);
form4.append(q4ans2);
form4.append(q4ans3);
form4.addCommand(q4ans11);
form4.addCommand(q4ans12);
form4.addCommand(q4ans13);
form4.setCommandListener(this);
//form5
form5 = new Form("Welcome to 5th question");
q5ans11 = new Command("1", 1, 1);
q5ans12 = new Command("2", 1, 2);
q5ans13 = new Command("3", 1, 3);
form5.append(q5);
form5.append(q5ans1);
form5.append(q5ans2);
form5.append(q5ans3);
form5.addCommand(q5ans11);
form5.addCommand(q5ans12);
form5.addCommand(q5ans13);
form5.setCommandListener(this);
//form6

form6 = new Form("Congrats : ");


form6.append(q6);
}
public void startApp() {
display.setCurrent(inputpage);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
//form1 actions
if (c==startgame)
{
score= score;
display.setCurrent(form1);
}
if (c==q1ans13 || c==q1ans12 || c==q1ans11)
{
if(c==q1ans13)
score= score+1;
display.setCurrent(form2);
}
if (c==q2ans11 || c==q2ans12 || c==q2ans13)
{
if (c==q2ans11)
score= score+1;
display.setCurrent(form3);
}
if (c==q3ans12 || c==q3ans13 || c==q3ans11)
{
if (c==q3ans12)
score= score+1;
display.setCurrent(form4);
}
if (c==q4ans12 || c==q4ans13 || c==q4ans11)
{
if (c==q4ans12)
score= score+1;
display.setCurrent(form5);

}
if (c==q5ans11 || c==q5ans12 || c==q5ans13)
{
if (c==q5ans11)
score=score+1;
String congrats="\nYour total points is:";
String us=username.getString();
String aa="\n\nwow you have scored 100%, you are genious..";
String aaa="\n\nyou have scored more than 60%.. you have greate IQ level
";
String aaaa="\n\nyou are in need to develope your IQ";
lastscore = (new Integer(score)).toString();
form6.append(us);
form6.append(congrats);
form6.append(lastscore);
if(score==5)
form6.append(aa);
else if(score>=3)
form6.append(aaa);
else
form6.append(aaaa);
display.setCurrent(form6);
}
}
}

You might also like