You are on page 1of 22

Pune District Education Association’s

INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

A MICRO-PROJECT REPORT
ON

“Mcq Quiz Using Java”

Course Name : Advance Java Programming


Course Code : 22517

DEPARTMENT OF COMPUTER ENGINEERING

(2022-2023)

ROLL NO. NAME OF STUDENTS


35 Siddhesh Maindkar
36 Pratik Gade

UNDER THE GUIDANCE OF


Dumbre S.A
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
Micro–Project Proposal

“Mcq Quiz using java”

1) Aim Benefits of the micro-project

1. To make a Mcq Quiz using Advance Java Programming.


2. To make a Quiz program using Frame and Swing components.

2) Course Outcomes

1) Develop Program using GUI Framework (AWT and Swing).


2) Handle events of AWT and Swing Components.
3) Develop Programs to handle events in java Programming.

3) Proposed Methodology

We develop a project on Simple MCQ Quiz under the subject Advance JAVA
Programming. We make this projects for user entertainment purpose. We start the
program code with the used of import java.awt.event.* of this java package. Here
we use Swing components to create our project. For some condition expressions
we used if else statement in our program. Our Quiz consist of serval number of
MCQ we can give answer of them among provided Four options .
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

INDEX

Sr.no. Contents
1. Rational
2. Aim Benefits of Micro-Project
3. Course Outcomes Addressed
4. Literature Review
5. Actual Methodology Followed
6. Resources Required
7. Shill Developed/Learning outcome of Micro-Project
8. Application of Micro-Project
9. Information Description
 Source Code
 Output of Micro-Project
 Conclusion
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

Micro–Project Report
“ MCQ Quiz using java”

1.0) Rational :

Java technology is widely used for web applications development. Based on the
object oriented concepts and core Java concepts, this course will equip the students
with the required knowledge and skill of object oriented programming approach
needed for the development of robust, powerful web applications. Through this
course students will get hands-on experience on GUI Technologies viz. AWT and
Swings, event handling mechanisms and network programming. The course also
gives coverage to various web applications aspects like Database
Interaction, server side components and servlets.

2.0) Aim Benefits of the micro-project

1. To make a MCQ Quiz using Advance Java Programming.


2. To make a Quiz program using Frame and Swing components.

3.0) Course Outcomes Addressed

4) Develop Program using GUI Framework (AWT and Swing).


5) Handle events of AWT and Swing Components.
6) Develop Programs to handle events in java Programming.
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
4.0) Literature Review
In this project, the focus is on a discussion of previous research studies
related to CPU scheduling in different methods and its effect on processes.
This chapter will focus on SJF two methods (preemptive and
nonpreemptive). It will also introduce the operating systems – CPU
scheduling, brief history of the operating system and CPU scheduling
concepts.
5.0) Actual Methodology Followed

Firstly, we select microproject title


And we research on it
Collecting information from sites and reference books
We write program in visual studio
We create Mcq Quiz in Java and try to output actually we need And
we create small report on it and present.

6.0) Resources Required

S. Name of Specification Qty.


No. Resources/Material
1. Compute system Ryzen 5 5600H 8GB RAM 512GB 1
SSD 1TB HDD
2. Software Visual Studio 1
3. Operating System Windows 11 1
4. Printer 1
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
.

7.0) Skill Developed/Learning outcome of this Micro-project

We created a MCQ Quiz for simple java Questions .

8.0) Application of the microproject

1. It simulates the MCQ test environment


Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

(INFORMATION DESCRIPTION)

• java.awt.event.*; :-
The java.awt.event package defines classes and interfaces used for
event handling in the AWT and Swing. The members of this package fall into three
categories: Events. The classes with names ending in "Event" represent specific
types of events, generated by the AWT or by one of the AWT or Swing
components.

• Javax.Swing.* ; :-

Java Swing is a part of Java Foundation Classes (JFC) that is used to create
windowbased applications. It is built on the top of AWT (Abstract Windowing
Toolkit) API and entirely written in java.

Unlike AWT, Java Swing provides platform-independent and lightweight


components.

The javax.swing package provides classes for java swing API such as JButton,
JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.

• java.util.*; :-
The java.util.* package Contains the collections framework, some
internationalization support classes, a service loader, properties, random
number generation, string parsing and scanning classes, base64 encoding
and decoding, a bit array, and several miscellaneous utility classes. This
package also contains legacy collection classes and legacy date and time
classes.
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

• Java ActionListener Interface :-


The Java ActionListener is notified whenever you click on the button or
menu item. It is notified against ActionEvent . The ActionListener interface is
found in java.awt.event package. It has only one method: actionPerformed().

• Java AWT | Canvas Class :-


Canvas class is a part of Java AWT. Canvas is a blank rectangular area
where the user can draw or trap input from the user. Canvas class inherits
the Component class.
Constructor of the Canvas class are :
1. Canvas(): Creates a new blank canvas.
2. Canvas(GraphicsConfiguration c): Creates a new canvas with a specified
graphics configuration.
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

 SOURCE CODE :-

import java.awt.*;
import
java.awt.event.*;
import javax.swing.*;
import java.util.*;

class Quiz extends JFrame implements ActionListener {


JPanel panel;
JRadioButton choice1;
JRadioButton choice2;
JRadioButton choice3;
JRadioButton choice4;
ButtonGroup bg;
JLabel lblmess;
JButton btnext;
String[][] qpa;
String[][] qca;
int qaid;
HashMap<Integer, String> map;

Quiz() { initializedata();
setTitle("Quiz Program");
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
setDefaultCloseOperation(EXIT_ON_CLOS
E);

setSize(430, 350);
setLocation(300, 100);
setResizable(false);
Container cont = getContentPane(); cont.setLayout(null);
cont.setBackground(Color.GRAY); bg = new ButtonGroup();
choice1 = new JRadioButton("Choice1",
true); choice2 = new
JRadioButton("Choice2", false); choice3 =
new JRadioButton("Choice3", false);
choice4 = new JRadioButton("Choice4", false);
bg.add(choice1); bg.add(choice2);
bg.add(choice3); bg.add(choice4);
lblmess = new JLabel("Choose a correct
answer");
lblmess.setForeground(Color.BLUE);
lblmess.setFont(new Font("Arial", Font.BOLD,
11)); btnext = new JButton("Next");
btnext.setForeground(Color.BLUE);
btnext.addActionListener(this); panel = new
JPanel();
panel.setBackground(Color.LIGHT_GRAY);
panel.setLocation(10, 10); panel.setSize(400,
300); panel.setLayout(new GridLayout(6,
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
2)); panel.add(lblmess);
panel.add(choice1); panel.add(choice2);

panel.add(choice3); panel.add(choice4);
panel.add(btnext); cont.add(panel);
setVisible(true); qaid = 0;
readqa(qaid);
}

public void
actionPerformed(ActionEvent e) { if
(btnext.getText().equals("Next")) {
if (qaid < 9) { map.put(qaid,
getSelection()); qaid++;
readqa(qaid);
} else
{ map.put(qaid,
getSelection());
btnext.setText("Show answers");
}
}
else if (btnext.getText().equals("Show
answers")) { new Report();
}
}

public void initializedata() {


Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
//qpa stores pairs of question and its possible
answers qpa = new String[10][5];

qpa[0][0] = "How to run Java program on the command


prompt?"; qpa[0][1] = "javac JavaProgram";
qpa[0][2] = "java JavaProgram"; qpa[0][3] = "javac
JavaProgram.java"; qpa[0][4] = "None of the above";

qpa[1][0] = "What is the use of the println method?";


qpa[1][1] = "It is used to print text on the screen."; qpa[1]
[2] = "It is used to print text on the screen with the line
break."; qpa[1][3] = "It is used to read text from
keyboard.";
qpa[1][4] = "It is used to read text from a file.";

qpa[2][0] = "How to read a character from the


keyboard?"; qpa[2][1] = "char c=System.read()";
qpa[2][2] = "char c=System.in.read()"; qpa[2][3]
= "char c=(char)System.read()"; qpa[2][4] =
"char c=(char)System.in.read()";

qpa[3][0] = "Which one would be


an int?"; qpa[3][1] = "X";
qpa[3][2] = "2"; qpa[3][3] =
"5.324"; qpa[3][4] = "Hello";
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
qpa[4][0] = "How do you declare an integer
variable x?"; qpa[4][1] = "int x"; qpa[4][2]

= "x as Integer"; qpa[4][3] = "Int[] x";


qpa[4][4] = "None of the above";

qpa[5][0] = "How do you convert a string of number to a


number?"; qpa[5][1] = "int
num=Integer.parseInt(str_num)"; qpa[5][2] = "int
num=str_num.toInteger()"; qpa[5][3] = "int
num=(int)str_num"; qpa[5][4] = "int
num=(Integer)str_num";

qpa[6][0] = "What is the value of x? int x=3>>2";


qpa[6][1] = "1";
qpa[6][2] = "0";
qpa[6][3] = "3";
qpa[6][4] = "-3";

qpa[7][0] = "How to do exit a


loop?"; qpa[7][1] = "Using
exit"; qpa[7][2] = "Using
break"; qpa[7][3] = "Using
continue"; qpa[7][4] = "Using
terminate";
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
qpa[8][0] = "What is the correct way to allocate one-
dimensional array?"; qpa[8][1] = "int[size] arr=new int[]";

qpa[8][2] = "int arr[size]=new int[]"; qpa[8][3] = "int[size]


arr=new int[size]"; qpa[8][4] = "int[] arr=new int[size]";

qpa[9][0] = "What is the correct way to allocate two-


dimensional array?"; qpa[9][1] = "int[size][] arr=new int[][]";
qpa[9][2] = "int arr=new int[rows][cols]"; qpa[9][3] = "int
arr[rows][]=new int[rows][cols]"; qpa[9][4] = "int[][] arr=new
int[rows][cols]";

//qca stores pairs of question and its correct


answer qca = new String[10][2];

qca[0][0] = "How to run Java program on the command


prompt?"; qca[0][1] = "java JavaProgram";

qca[1][0] = "What is the use of the println method?";


qca[1][1] = "It is used to print text on the screen with the
line break."; qca[2][0] = "How to read a character from the
keyboard?"; qca[2][1] = "char c=(char)System.in.read()";

qca[3][0] = "Which one would be an int";


qca[3][1] = "2";
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

qca[4][0] = "How do you declare an integer variable


x?"; qca[4][1] = "int x";

qca[5][0] = "How do you convert a string of number to a


number?"; qca[5][1] = "int num=Integer.parseInt(str_num)";

qca[6][0] = "What is the value of x? int x=3>>2";


qca[6][1] = "0";

qca[7][0] = "How to do exit a loop?";


qca[7][1] = "Using break";

qca[8][0] = "What is the correct way to allocate one-


dimensional array?"; qca[8][1] = "int[] arr=new int[size]";

qca[9][0] = "What is the correct way to allocate two-


dimensional array?"; qca[9][1] = "int[][] arr=new int[rows]
[cols]";

//create a map object to store pairs of question and selected


answer map = new HashMap<>();
}

public String getSelection() {


String selectedChoice = null;
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.

Enumeration<AbstractButton> buttons = bg.getElements();


while (buttons.hasMoreElements()) {
JRadioButton temp = (JRadioButton)
buttons.nextElement(); if (temp.isSelected()) {
selectedChoice = temp.getText();
}
}
return (selectedChoice);
}

public void readqa(int qid)


{ lblmess.setText(" " + qpa[qid][0]);
choice1.setText(qpa[qid][1]);
choice2.setText(qpa[qid][2]);
choice3.setText(qpa[qid][3]);
choice4.setText(qpa[qid][4]);
choice1.setSelected(true);
}

public void reset() {


qaid = 0;
map.clear();
readqa(qaid);
btnext.setText("Next");
}
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
public int calCorrectAnswer() {
int qnum = 10; int count = 0;
for (int qid = 0; qid < qnum; qid++)
{ if (qca[qid]
[1].equals(map.get(qid))) {
count++;
}
}
return count;
}

public class Report extends JFrame


{ Report() { setTitle("Answers");
setSize(850, 550);
setBackground(Color.WHITE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
reset();
}
});
Draw d = new
Draw(); add(d);
setVisible(true);
}
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
class Draw extends Canvas {
public void paint(Graphics g) {
int qnum = 10; int x
= 10; int y = 20;
for (int i = 0; i < qnum; i++) {
//print the 1st column
g.setColor(Color.BLUE);
g.setFont(new Font("Arial", Font.BOLD, 12));
g.drawString(i + 1 + ". " + qca[i]
[0], x, y); y += 30;
g.setFont(new Font("Arial", Font.PLAIN, 12));
g.drawString(" Correct answer:" + qca[i]
[1], x, y); y += 30;
g.drawString(" Your answer:" +
map.get(i), x, y); y += 30;
//print the 2nd
column if (y > 400)
{ y = 20;
x = 450;
}
}
//show number of correct
answers int numc =
calCorrectAnswer();
g.setColor(Color.BLUE);
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
g.setFont(new Font("Arial", Font.BOLD, 14));
g.drawString("Number of correct answers:" + numc, 300,
500);
}
}
}
}

public class QuizProgram


{ public static void main(String
args[]) { new Quiz();
}
}
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
 Outputs of the Micro-project:-
1)
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
2)

3)
Pune District Education Association’s
INSTITUTE OF TECHNOLOGY, HADAPSAR, PUNE.
4)

 CONCLUSION
The MCQ Quiz is developed using java Programming . we have use java AWT and
Swing package to create the interface of our project where we provided Ten
different java MCQ to solve and at end we have provided the answers of theses
questions and your score.

You might also like