MCQ Exam Sys and Source Code

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

A

SYNOPSIS REPORT ON

Title of the Project


MCQ EXAM SYSTEM

SUBMITTED BY NAME OF STUDENT

Kaushal Ulhas Patil

UNDER THE GUIDANCE OF


NAME OF GUIDE Prof. Nishant Pachpor

IN PARTIAL FULFILMENT OF
Award of the Degree of
MASTER OF COMPUTER APPLICATION

SUBMITTED TO

SAVITRIBAI PHULE PUNE UNIVERSITY

THROUGH

YASHASWI EDUCATION SOCIETY’S INTERNATIONAL INSTITUTE OF MANAGEMENT


SCIENCE
CHINCHWAD, PUNE ACADEMIC YEAR 2021-2022
INDEX

Sr. No. Chapter

1. Title of the Project

2. Abstract of the Project

3. Problem Statement

4. Scope of the Project

5. Objectives

6. Technology used

7. Conclusion

8. Bibliography
MCQ EXAM SYSTEM

Abstract of the Project

MCQ Exam System is a complete system that is beneficial for both teachers
and students. With this site, an administrator can allow authorized access to users
that include faculty and students. Faculties are those who register on the site and
take exams in their respective courses on time. teachers can add questions to the
exam by selecting the available settings.

The tests added by faculties are available to students who can attempt the test and
get scores then and there. The aim of the system is to provide a system that saves
both the effort and time of the teachers and the students.

MCQ Exam System is a web application software that establishes a network


between faculty and students. These questions are displayed as a test for eligible
students. The answers entered by the students are then evaluated and their marks
are calculated and saved in the database. This score can be accessed by faculty and
administrators to evaluate their performance.

The system named MCQ Exams System is application software, which aims to
provide services to institutions and provide them with an option to self-select
eligible students.
Problem Statement

The recent shutdown has created a challenging situation for educational


institutions. All students and institute staff are under lockdown. Technologies such
as online conferencing and video-based learning can be helpful in continuing a
student's education. However, managing the examination process is a challenging
matter considering the lockdown situation. Without academic exams, it is
impossible to complete the academic cycle.

MCQ exam procedure can be an effective means of shifting the traditional


examination procedure to MCQ mode. The problem with the manual examination
system is that it is a time-consuming and inefficient waste of valuable resources.
Manual examination systems are also very slow to generate reports. In a manual
examination system, the chances of records are high and it is also difficult to find
records. The aim of this project is to provide a fast, immediate test method.

The MCQ exam system can automatically add the marks allotted to each question to
determine the total marks for the question. A time limit may be fixed for the
examination. It also allows going to specific questions based on previous answers. It
is an easy and convenient way to conduct and attend exams which saves a lot of
time and effort.
Scope

 Faculties Maintaining all students’ records.


 Many Faculties add test in particular course
 Students attends Many MCQ Question.
 Accessibility and flexibility by conducting exams anywhere

Objectives

 This MCQ Examination system is to enable user with its functionality of user-
friendly dashboard.
 Multiple Type Questions in many formats.
 Examiner analysis all student result in one dashboard.
 The important objective of this software is to allow student take the exam at
their own place.
 This Project is saved papers and save teaches and student times and it’s cost
saving system.

System Configuration

Software Requirements

OS : MS WINDOWS XP / 7 / 8 / 10 / 11
Environment : Java Runtime Environment 1.5
Front end : Java, swing
Back end : Excel Database

Hardware Requirements

Processor : Intel Pentium IV 2.4 GHZ or above


Clock speed : 500 MHZ
System bus : 32 bits
RAM : 256MB of RAM
HDD : 40 GB or higher
Monitor : SVGA COLOR
Source Code
OES.java
package com.oes.runner;

import com.oes.app.Application;

public class OES {

public static void main(String args[]) {


Application.getInstance().lauchApp();

Application.java

package com.oes.app;

import java.util.List;
import java.util.Optional;

import com.oes.data.StudentData;
import com.oes.pages.LoginPage;
import com.oes.pojos.Student;

public class Application {

private static Application app;


private Student loggedInStudent;
private boolean isLoggedIn;
private StudentData studentData;

private Application() {
studentData = new StudentData();
}

public static Application getInstance() {


if(app == null) {
app = new Application();
}
return app;
}

public void lauchApp() {


LoginPage.getInstance().open();
}

public boolean login(String email, String password) {


List<Student> students = studentData.getAllStudents();
System.out.println("Checking login --- users are ---" + students);
Optional<Student> matchingStudent = students.stream()
.filter(
(student) ->
student.getEmail().equalsIgnoreCase(email) && student.getPassword().equals(password)
)
.findFirst();
if(matchingStudent.isPresent()) {
isLoggedIn = true;
loggedInStudent = matchingStudent.get();
return true;
}else {
return false;
}
}

public void logout() {


loggedInStudent = null;
isLoggedIn = false;
}

public Student getLoggedInStudent() {


return loggedInStudent;
}

public void setLoggedInStudent(Student loggedInStudent) {


this.loggedInStudent = loggedInStudent;
}

public boolean isLoggedIn() {


return isLoggedIn;
}

public void setLoggedIn(boolean isLoggedIn) {


this.isLoggedIn = isLoggedIn;
}

ErrorMessage.java

package com.oes.constants;

public class ErrorMessages {

public static final String REGISTRATION_SUCCESSFUL =


"Registration Successful.";
public static final String REGISTRATION_FAILURE = "Something
went wrong, couldn't register the user. Please try some time
later.";
}

FilePaths.java
package com.oes.constants;

import java.io.File;

public class FilePaths {

public static String BASE_DIR =


System.getProperty("user.dir");
public static String RESOURCES_DIR = BASE_DIR +
File.separator + "src" + File.separator + "main" + File.separator
+ "resources";
public static String DATA_DIR = RESOURCES_DIR +
File.separator + "data";
public static String OES_XLS_FILE = DATA_DIR + File.separator
+ "oes.xlsx";

}
ResultStatus.java

package com.oes.constants;

public enum ResultStatus {


PASS, FAIL
}

QuestionsData.java

package java.lang;

import java.lang.annotation.Native;
import java.lang.invoke.MethodHandles;
import java.lang.constant.Constable;
import java.lang.constant.ConstantDesc;
import java.util.Objects;
import java.util.Optional;

import jdk.internal.misc.CDS;
import jdk.internal.misc.VM;
import jdk.internal.vm.annotation.IntrinsicCandidate;

import static java.lang.String.COMPACT_STRINGS;


import static java.lang.String.LATIN1;
import static java.lang.String.UTF16;

@jdk.internal.ValueBased
public final class Integer extends Number
implements Comparable<Integer>, Constable, ConstantDesc {

@Native public static final int MAX_VALUE = 0x7fffffff;

@SuppressWarnings("unchecked")
public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
static final char[] digits = {
'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z'
};

public static String toString(int i, int radix) {


if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
radix = 10;

/* Use the faster version */


if (radix == 10) {
return toString(i);
}

if (COMPACT_STRINGS) {
byte[] buf = new byte[33];
boolean negative = (i < 0);
int charPos = 32;

if (!negative) {
i = -i;
}

while (i <= -radix) {


buf[charPos--] = (byte)digits[-(i % radix)];
i = i / radix;
}
buf[charPos] = (byte)digits[-i];

if (negative) {
buf[--charPos] = '-';
}

return StringLatin1.newString(buf, charPos, (33 - charPos));


}
return toStringUTF16(i, radix);
}

private static String toStringUTF16(int i, int radix) {


byte[] buf = new byte[33 * 2];
boolean negative = (i < 0);
int charPos = 32;
if (!negative) {
i = -i;
}
while (i <= -radix) {
StringUTF16.putChar(buf, charPos--, digits[-(i % radix)]);
i = i / radix;
}
StringUTF16.putChar(buf, charPos, digits[-i]);
if (negative) {
StringUTF16.putChar(buf, --charPos, '-');
}
return StringUTF16.newString(buf, charPos, (33 - charPos));
}

public static String toUnsignedString(int i, int radix) {


return Long.toUnsignedString(toUnsignedLong(i), radix);
}

public static String toHexString(int i) {


return toUnsignedString0(i, 4);
}

public static String toOctalString(int i) {


return toUnsignedString0(i, 3);
}

public static String toBinaryString(int i) {


return toUnsignedString0(i, 1);
}

private static String toUnsignedString0(int val, int shift) {


// assert shift > 0 && shift <=5 : "Illegal shift value";
int mag = Integer.SIZE - Integer.numberOfLeadingZeros(val);
int chars = Math.max(((mag + (shift - 1)) / shift), 1);
if (COMPACT_STRINGS) {
byte[] buf = new byte[chars];
formatUnsignedInt(val, shift, buf, chars);
return new String(buf, LATIN1);
} else {
byte[] buf = new byte[chars * 2];
formatUnsignedIntUTF16(val, shift, buf, chars);
return new String(buf, UTF16);
}
}

private static void formatUnsignedInt(int val, int shift, byte[] buf, int len) {
int charPos = len;
int radix = 1 << shift;
int mask = radix - 1;
do {
buf[--charPos] = (byte)Integer.digits[val & mask];
val >>>= shift;
} while (charPos > 0);
}

private static void formatUnsignedIntUTF16(int val, int shift, byte[] buf, int len) {
int charPos = len;
int radix = 1 << shift;
int mask = radix - 1;
do {
StringUTF16.putChar(buf, --charPos, Integer.digits[val & mask]);
val >>>= shift;
} while (charPos > 0);
}

static final byte[] DigitTens = {


'0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
'2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
'3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
'4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
'5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
'6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
'7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
'8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
'9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
};

static final byte[] DigitOnes = {


'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
};

@IntrinsicCandidate
public static String toString(int i) {
int size = stringSize(i);
if (COMPACT_STRINGS) {
byte[] buf = new byte[size];
getChars(i, size, buf);
return new String(buf, LATIN1);
} else {
byte[] buf = new byte[size * 2];
StringUTF16.getChars(i, size, buf);
return new String(buf, UTF16);
}
}

public static String toUnsignedString(int i) {


return Long.toString(toUnsignedLong(i));
}

static int getChars(int i, int index, byte[] buf) {


int q, r;
int charPos = index;

boolean negative = i < 0;


if (!negative) {
i = -i;
}

// Generate two digits per iteration


while (i <= -100) {
q = i / 100;
r = (q * 100) - i;
i = q;
buf[--charPos] = DigitOnes[r];
buf[--charPos] = DigitTens[r];
}

// We know there are at most two digits left at this point.


q = i / 10;
r = (q * 10) - i;
buf[--charPos] = (byte)('0' + r);

// Whatever left is the remaining digit.


if (q < 0) {
buf[--charPos] = (byte)('0' - q);
}

if (negative) {
buf[--charPos] = (byte)'-';
}
return charPos;
}

// Left here for compatibility reasons, see JDK-8143900.


static final int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
99999999, 999999999, Integer.MAX_VALUE };
static int stringSize(int x) {
int d = 1;
if (x >= 0) {
d = 0;
x = -x;
}
int p = -10;
for (int i = 1; i < 10; i++) {
if (x > p)
return i + d;
p = 10 * p;
}
return 10 + d;
}

if (s == null) {
throw new NumberFormatException("Cannot parse null string");
}

if (radix < Character.MIN_RADIX) {


throw new NumberFormatException("radix " + radix +
" less than Character.MIN_RADIX");
}

if (radix > Character.MAX_RADIX) {


throw new NumberFormatException("radix " + radix +
" greater than Character.MAX_RADIX");
}

boolean negative = false;


int i = 0, len = s.length();
int limit = -Integer.MAX_VALUE;

if (len > 0) {
char firstChar = s.charAt(0);
if (firstChar < '0') { // Possible leading "+" or "-"
if (firstChar == '-') {
negative = true;
limit = Integer.MIN_VALUE;
} else if (firstChar != '+') {
throw NumberFormatException.forInputString(s, radix);
}

if (len == 1) { // Cannot have lone "+" or "-"


throw NumberFormatException.forInputString(s, radix);
}
i++;
}
int multmin = limit / radix;
int result = 0;
while (i < len) {
// Accumulating negatively avoids surprises near MAX_VALUE
int digit = Character.digit(s.charAt(i++), radix);
if (digit < 0 || result < multmin) {
throw NumberFormatException.forInputString(s, radix);
}
result *= radix;
if (result < limit + digit) {
throw NumberFormatException.forInputString(s, radix);
}
result -= digit;
}
return negative ? result : -result;
} else {
throw NumberFormatException.forInputString(s, radix);
}
}

public static int parseInt(CharSequence s, int beginIndex, int endIndex, int radix)
throws NumberFormatException {
Objects.requireNonNull(s);
Objects.checkFromToIndex(beginIndex, endIndex, s.length());

if (radix < Character.MIN_RADIX) {


throw new NumberFormatException("radix " + radix +
" less than Character.MIN_RADIX");
}
if (radix > Character.MAX_RADIX) {
throw new NumberFormatException("radix " + radix +
" greater than Character.MAX_RADIX");
}

boolean negative = false;


int i = beginIndex;
int limit = -Integer.MAX_VALUE;

if (i < endIndex) {
char firstChar = s.charAt(i);
if (firstChar < '0') { // Possible leading "+" or "-"
if (firstChar == '-') {
negative = true;
limit = Integer.MIN_VALUE;
} else if (firstChar != '+') {
throw NumberFormatException.forCharSequence(s, beginIndex,
endIndex, i);
}
i++;
if (i == endIndex) { // Cannot have lone "+" or "-"
throw NumberFormatException.forCharSequence(s, beginIndex,
endIndex, i);
}
}
int multmin = limit / radix;
int result = 0;
while (i < endIndex) {
// Accumulating negatively avoids surprises near MAX_VALUE
int digit = Character.digit(s.charAt(i), radix);
if (digit < 0 || result < multmin) {
throw NumberFormatException.forCharSequence(s, beginIndex,
endIndex, i);
}
result *= radix;
if (result < limit + digit) {
throw NumberFormatException.forCharSequence(s, beginIndex,
endIndex, i);
}
i++;
result -= digit;
}
return negative ? result : -result;
} else {
throw NumberFormatException.forInputString("", radix);
}
}
public static int parseInt(String s) throws NumberFormatException {
return parseInt(s,10);
}

public static int parseUnsignedInt(String s, int radix)


throws NumberFormatException {
if (s == null) {
throw new NumberFormatException("Cannot parse null string");
}

int len = s.length();


if (len > 0) {
char firstChar = s.charAt(0);
if (firstChar == '-') {
throw new
NumberFormatException(String.format("Illegal leading minus sign " +
"on unsigned string %s.", s));
} else {
if (len <= 5 || // Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits
(radix == 10 && len <= 9) ) { // Integer.MAX_VALUE in base 10 is 10 digits
return parseInt(s, radix);
} else {
long ell = Long.parseLong(s, radix);
if ((ell & 0xffff_ffff_0000_0000L) == 0) {
return (int) ell;
} else {
throw new
NumberFormatException(String.format("String value %s exceeds " +
"range of unsigned int.", s));
}
}
}
} else {
throw NumberFormatException.forInputString(s, radix);
}
}

public static int parseUnsignedInt(CharSequence s, int beginIndex, int endIndex, int radix)
throws NumberFormatException {
Objects.requireNonNull(s);
Objects.checkFromToIndex(beginIndex, endIndex, s.length());

int start = beginIndex, len = endIndex - beginIndex;

if (len > 0) {
char firstChar = s.charAt(start);
if (firstChar == '-') {
throw new
NumberFormatException(String.format("Illegal leading minus sign " +
"on unsigned string %s.", s));
} else {
if (len <= 5 || // Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits
(radix == 10 && len <= 9)) { // Integer.MAX_VALUE in base 10 is 10 digits
return parseInt(s, start, start + len, radix);
} else {
long ell = Long.parseLong(s, start, start + len, radix);
if ((ell & 0xffff_ffff_0000_0000L) == 0) {
return (int) ell;
} else {
throw new
NumberFormatException(String.format("String value %s exceeds " +
"range of unsigned int.", s));
}
}
}
} else {
throw new NumberFormatException("");
}
}

public static int parseUnsignedInt(String s) throws NumberFormatException {


return parseUnsignedInt(s, 10);
}

public static Integer valueOf(String s) throws NumberFormatException {


return Integer.valueOf(parseInt(s, 10));
}

private static class IntegerCache {


static final int low = -128;
static final int high;
static final Integer[] cache;
static Integer[] archivedCache;

static {
// high value may be configured by property
int h = 127;
String integerCacheHighPropValue =
VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
try {
h = Math.max(parseInt(integerCacheHighPropValue), 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(h, Integer.MAX_VALUE - (-low) -1);
} catch( NumberFormatException nfe) {
// If the property cannot be parsed into an int, ignore it.
}
}
high = h;

// Load IntegerCache.archivedCache from archive, if possible


CDS.initializeFromArchive(IntegerCache.class);
int size = (high - low) + 1;

// Use the archived cache if it exists and is large enough


if (archivedCache == null || size > archivedCache.length) {
Integer[] c = new Integer[size];
int j = low;
for(int i = 0; i < c.length; i++) {
c[i] = new Integer(j++);
}
archivedCache = c;
}
cache = archivedCache;
// range [-128, 127] must be interned (JLS7 5.1.7)
assert IntegerCache.high >= 127;
}

private IntegerCache() {}
}

@IntrinsicCandidate
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}

private final int value;


@Deprecated(since="9", forRemoval = true)
public Integer(int value) {
this.value = value;
}

@Deprecated(since="9", forRemoval = true)


public Integer(String s) throws NumberFormatException {
this.value = parseInt(s, 10);
}

public byte byteValue() {


return (byte)value;
}

public short shortValue() {


return (short)value;
}

@IntrinsicCandidate
public int intValue() {
return value;
}

public long longValue() {


return (long)value;
}

public float floatValue() {


return (float)value;
}

public double doubleValue() {


return (double)value;
}

public String toString() {


return toString(value);
}

@Override
public int hashCode() {
return Integer.hashCode(value);
}

public static int hashCode(int value) {


return value;
}

public boolean equals(Object obj) {


if (obj instanceof Integer) {
return value == ((Integer)obj).intValue();
}
return false;
}

public static Integer getInteger(String nm) {


return getInteger(nm, null);
}

public static Integer getInteger(String nm, int val) {


Integer result = getInteger(nm, null);
return (result == null) ? Integer.valueOf(val) : result;
}

public static Integer getInteger(String nm, Integer val) {


String v = null;
try {
v = System.getProperty(nm);
} catch (IllegalArgumentException | NullPointerException e) {
}
if (v != null) {
try {
return Integer.decode(v);
} catch (NumberFormatException e) {
}
}
return val;
}

public static Integer decode(String nm) throws NumberFormatException {


int radix = 10;
int index = 0;
boolean negative = false;
int result;

if (nm.isEmpty())
throw new NumberFormatException("Zero length string");
char firstChar = nm.charAt(0);
// Handle sign, if present
if (firstChar == '-') {
negative = true;
index++;
} else if (firstChar == '+')
index++;

// Handle radix specifier, if present


if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
index += 2;
radix = 16;
}
else if (nm.startsWith("#", index)) {
index ++;
radix = 16;
}
else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
index ++;
radix = 8;
}

if (nm.startsWith("-", index) || nm.startsWith("+", index))


throw new NumberFormatException("Sign character in wrong position");

try {
result = parseInt(nm, index, nm.length(), radix);
result = negative ? -result : result;
} catch (NumberFormatException e) {
// If number is Integer.MIN_VALUE, we'll end up here. The next line
// handles this case, and causes any genuine format error to be
// rethrown.
String constant = negative ? ("-" + nm.substring(index))
: nm.substring(index);
result = parseInt(constant, radix);
}
return result;
}

public int compareTo(Integer anotherInteger) {


return compare(this.value, anotherInteger.value);
}

public static int compare(int x, int y) {


return (x < y) ? -1 : ((x == y) ? 0 : 1);
}

public static int compareUnsigned(int x, int y) {


return compare(x + MIN_VALUE, y + MIN_VALUE);
}

public static long toUnsignedLong(int x) {


return ((long) x) & 0xffffffffL;
}

public static int remainderUnsigned(int dividend, int divisor) {


// In lieu of tricky code, for now just use long arithmetic.
return (int)(toUnsignedLong(dividend) % toUnsignedLong(divisor));
}

// Bit twiddling
public static int highestOneBit(int i) {
return i & (MIN_VALUE >>> numberOfLeadingZeros(i));
}

@IntrinsicCandidate
public static int numberOfLeadingZeros(int i) {
// HD, Count leading 0's
if (i <= 0)
return i == 0 ? 32 : 0;
int n = 31;
if (i >= 1 << 16) { n -= 16; i >>>= 16; }
if (i >= 1 << 8) { n -= 8; i >>>= 8; }
if (i >= 1 << 4) { n -= 4; i >>>= 4; }
if (i >= 1 << 2) { n -= 2; i >>>= 2; }
return n - (i >>> 1);
}

@IntrinsicCandidate
public static int numberOfTrailingZeros(int i) {
// HD, Count trailing 0's
i = ~i & (i - 1);
if (i <= 0) return i & 32;
int n = 1;
if (i > 1 << 16) { n += 16; i >>>= 16; }
if (i > 1 << 8) { n += 8; i >>>= 8; }
if (i > 1 << 4) { n += 4; i >>>= 4; }
if (i > 1 << 2) { n += 2; i >>>= 2; }
return n + (i >>> 1);
}

@IntrinsicCandidate
public static int bitCount(int i) {
// HD, Figure 5-2
i = i - ((i >>> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i >>> 4)) & 0x0f0f0f0f;
i = i + (i >>> 8);
i = i + (i >>> 16);
return i & 0x3f;
}

public static int rotateLeft(int i, int distance) {


return (i << distance) | (i >>> -distance);
}

public static int rotateRight(int i, int distance) {


return (i >>> distance) | (i << -distance);
}

public static int reverse(int i) {


// HD, Figure 7-1
i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;

return reverseBytes(i);
}

public static int signum(int i) {


// HD, Section 2-7
return (i >> 31) | (-i >>> 31);
}

@IntrinsicCandidate
public static int reverseBytes(int i) {
return (i << 24) |
((i & 0xff00) << 8) |
((i >>> 8) & 0xff00) |
(i >>> 24);
}

public static int sum(int a, int b) {


return a + b;
}

public static int max(int a, int b) {


return Math.max(a, b);
}

public static int min(int a, int b) {


return Math.min(a, b);
}

@Override
public Optional<Integer> describeConstable() {
return Optional.of(this);
}

@Override
public Integer resolveConstantDesc(MethodHandles.Lookup lookup) {
return this;
}

@java.io.Serial
@Native private static final long serialVersionUID = 1360826667806852920L;
}

ResultData.java

package com.oes.data;

import java.util.Map;

import org.apache.commons.collections4.map.HashedMap;

import com.oes.app.Application;
import com.oes.constants.FilePaths;
import com.oes.pojos.Result;
import com.oes.pojos.Student;

public class ResultsData {

XlsWriter xlsWriter;
public ResultsData() {
xlsWriter = new XlsWriter(FilePaths.OES_XLS_FILE, "results");
}

public boolean uploadResultToXls(Result result) {


try {
Map<Integer, String> resultData = new HashedMap<>();
Student student = Application.getInstance().getLoggedInStudent();
resultData.put(0, student.getFirstName());
resultData.put(1, String.valueOf(result.getPercent()));
resultData.put(2, String.valueOf(result.getStatus()));
xlsWriter.addRow(resultData);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}

StudentData.java

package com.oes.data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections4.map.HashedMap;
import com.oes.constants.FilePaths;
import com.oes.pojos.Student;

public class StudentData {

XlsReader oesXlsReader;
XlsWriter xlsWriter;
public StudentData() {
oesXlsReader = new XlsReader(FilePaths.OES_XLS_FILE, "student");
xlsWriter = new XlsWriter(FilePaths.OES_XLS_FILE, "student");
}

public List<Student> getAllStudents() {


Map<Integer, Map<Integer, String>> data = oesXlsReader.getAllData();
Set<Integer> rows = data.keySet();
List<Student> list = new ArrayList<Student>();
for (Integer row : rows) {
if(row == 0) continue;
Map<Integer, String> rowData = data.get(row);
Set<Integer> cols = rowData.keySet();
Student student = new Student();
for (Integer col : cols) {
String value = rowData.get(col);
switch (col) {
case 0:
student.setId((int)Double.parseDouble(value));
break;
case 1:
student.setFirstName(value);
break;
case 2:
student.setLastName(value);
break;
case 3:
student.setQualification(value);
break;
case 4:
student.setMobile(value);
break;
case 5:
student.setEmail(value);
break;
case 6:
student.setPassword(value);
break;
default:
break;
}
}
list.add(student);

}
return list;
}
/**
* @author Kaushal
* @param student - object of Student class (the student to be added to XLS file)
* @return true - if student is added to XLS data successfully,
* false - if error while adding the student data
*/
public boolean addStudent(Student student) {
Map<Integer, String> studentData = new HashedMap<Integer, String>();
studentData.put(0, String.valueOf(getAllStudents().size() + 1));
studentData.put(1, student.getFirstName());
studentData.put(2, student.getLastName());
studentData.put(3, student.getQualification());
studentData.put(4, student.getMobile());
studentData.put(5, student.getEmail());
studentData.put(6, student.getPassword());

boolean isAdded = xlsWriter.addRow(studentData);


return isAdded;
}

XlsReader.java

package com.oes.data;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;

import org.apache.commons.collections4.map.HashedMap;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class XlsReader {

XSSFWorkbook workbook;
XSSFSheet sheet;
String filePath;
String sheetName;

public XlsReader(String filePath, String sheetName) {


this.filePath = filePath;
this.sheetName = sheetName;
loadUpdatedData();
}
private void loadUpdatedData() {
try {
workbook = new XSSFWorkbook(new FileInputStream(filePath));
} catch (IOException e) {
e.printStackTrace();
}
this.sheet = workbook.getSheet(sheetName);
}

public Map<Integer, Map<Integer, String>> getAllData() {


loadUpdatedData();
Map<Integer, Map<Integer, String>> data = new HashedMap<Integer,
Map<Integer,String>>();
int lastRow = sheet.getLastRowNum();
int lastCol = sheet.getRow(0).getLastCellNum();

for(int row = 0; row <= lastRow; row++) {


Map<Integer, String> rowData = new HashedMap<Integer, String>();
for(int col = 0; col < lastCol; col++) {
Cell currentCell = sheet.getRow(row).getCell(col);
String value = getCellValue(currentCell);
rowData.put(col, value);
}
data.put(row, rowData);
}
return data;
}

private String getCellValue(Cell cell) {


CellType type = cell.getCellType();

switch (type) {
case NUMERIC:
return String.valueOf(cell.getNumericCellValue());
case STRING:
return cell.getStringCellValue();
default:
return "Unsupported Cell Type";
}
}

public String getData(int row, int col) {


Cell cell = sheet.getRow(row).getCell(col);
return cell.getStringCellValue();
}

XlsWriter.java

package com.oes.data;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class XlsWriter {

XSSFWorkbook workbook;
XSSFSheet sheet;
String filePath;
String sheetName;

public XlsWriter(String filePath, String sheetName) {


try {
workbook = new XSSFWorkbook(new FileInputStream(filePath));
} catch (IOException e) {
e.printStackTrace();
}
this.filePath = filePath;
this.sheetName = sheetName;
this.sheet = workbook.getSheet(sheetName);
}

public boolean addRow(Map<Integer, String> rowData) {


int currentRow = sheet.getLastRowNum();
Row row = sheet.createRow(currentRow + 1);
for (Integer col : rowData.keySet()) {
Cell cell = row.createCell(col);
cell.setCellValue(rowData.get(col));
}
return writeData();
}

private boolean writeData() {


try
{
//Write the workbook in file system
FileOutputStream out = new FileOutputStream(new File(filePath));
workbook.write(out);
out.close();
System.out.println(filePath + " is written successfully.");
return true;
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}

ExamPage.java

package com.oes.pages;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
import com.oes.data.ResultsData;
import com.oes.pojos.Exam;
import com.oes.pojos.Option;
import com.oes.pojos.Question;
import com.oes.pojos.Result;

public class ExamPage extends Page {

private static ExamPage examPage;


private Question currentQuestion;
private JRadioButton optionA, optionB, optionC, optionD;
private Exam exam;
private JLabel currentQuestionLabel;
private JLabel optionALabel, optionBLabel, optionCLabel, optionDLabel ;
private ButtonGroup options;

private ExamPage() {
super();
exam = new Exam();
name = "OES - Online Exam";
width = 400;
height = 400;
panel = new JPanel();
optionA = new JRadioButton("a");
optionB = new JRadioButton("b");
optionC = new JRadioButton("c");
optionD = new JRadioButton("d");

currentQuestion = exam.getCurrentQuestion();
init();
}

public static ExamPage getInstance() {


if(examPage == null)
examPage = new ExamPage();
return examPage;
}

private void init() {


initUI();
}

private void initUI() {


panel.setLayout(new BorderLayout(20, 15));
panel.add(getEndExamButtonPanel(), BorderLayout.NORTH);
panel.add(getQuestionWithOptionsPanel(), BorderLayout.CENTER);
panel.add(getNavButtonPanel(), BorderLayout.SOUTH);
panel.setBorder(new EmptyBorder(10, 10, 20, 10));
addListenersToRadioButtons();
}

private JPanel getQuestionWithOptionsPanel() {


JPanel qoPanel = new JPanel();
qoPanel.setLayout(new BorderLayout(10, 10));
qoPanel.add(getQuestionPanel(), BorderLayout.NORTH);
qoPanel.add(getOptionsPanel(), BorderLayout.CENTER);

return qoPanel;
}

private JPanel getQuestionPanel() {


JPanel qPanel = new JPanel();
qPanel.setLayout(new FlowLayout());
String index = "Que " + (exam.getCurrentQuestionIndex() + 1) + ". ";
currentQuestionLabel = new JLabel(index + currentQuestion.getQuestion());
qPanel.add(currentQuestionLabel);

return qPanel;
}

private JPanel getOptionsPanel() {


JPanel oPanel = new JPanel();
oPanel.setLayout(new GridLayout(4,1));
options = new ButtonGroup();
options.add(optionA);
options.add(optionB);
options.add(optionC);
options.add(optionD);

for (Option option : currentQuestion.getOptions()) {


oPanel.add(getOPanel(option));
}
return oPanel;
}
private JPanel getOPanel(Option option) {
JPanel optionPanel = new JPanel();
switch (option.getName().toLowerCase()) {
case "a":
optionPanel.add(optionA);
optionALabel = new JLabel(option.getValue());
optionPanel.add(optionALabel);
break;
case "b":
optionPanel.add(optionB);
optionBLabel = new JLabel(option.getValue());
optionPanel.add(optionBLabel);
break;
case "c":
optionPanel.add(optionC);
optionCLabel = new JLabel(option.getValue());
optionPanel.add(optionCLabel);
break;
case "d":
optionPanel.add(optionD);
optionDLabel = new JLabel(option.getValue());
optionPanel.add(optionDLabel);
break;
default:
break;
}
return optionPanel;
}

private JPanel getEndExamButtonPanel() {


JPanel endButtonPanel = new JPanel();
endButtonPanel.setLayout(new BorderLayout());
JButton endButton = new JButton("End Exam");
endButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
endExamButtonPressed();
}
});

endButtonPanel.add(endButton, BorderLayout.LINE_END);
return endButtonPanel;
}

private JPanel getNavButtonPanel() {


JButton prevBtn = new JButton("<-");
JButton nextBtn = new JButton("->");

JPanel buttonPanel = new JPanel();


buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(prevBtn);
buttonPanel.add(nextBtn);

prevBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
prevButtonPressed();
}
});

nextBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
nextButtonPressed();

}
});

return buttonPanel;
}

private void endExamButtonPressed() {


Result result = exam.generateResult();
boolean isUploaded = new ResultsData().uploadResultToXls(result);
if(isUploaded) {
//show user a message - Upload successful
System.out.println("Results updated to xls successfully");
}else {
//show user a message - something went wrong
System.out.println("�omething went wrong while adding results to xls
file.");
}
System.out.println("--------------------------------------");
System.out.println("Ohooo, here are your Results:");
System.out.println("--------------------------------------");
System.out.println(result);
System.out.println("--------------------------------------");
close();
ResultPage.getInstance().setResult(result);
ResultPage.getInstance().open();
examPage = null;
}

private void prevButtonPressed() {


int currentQueIndex = exam.getCurrentQuestionIndex();
if(currentQueIndex > 0) {
exam.setCurrentQuestionIndex(currentQueIndex - 1);
}
System.out.println("Previous button pressed." + currentQueIndex);
updateQuestion();
}

private void nextButtonPressed() {


int currentQueIndex = exam.getCurrentQuestionIndex();
if(currentQueIndex < exam.getQuestions().size() - 1) {
exam.setCurrentQuestionIndex(currentQueIndex + 1);
}
System.out.println("next button pressed." + currentQueIndex +
exam.getCurrentQuestion());
updateQuestion();
}

private void updateQuestion() {


options.clearSelection();
//Question
String index = "Que " + (exam.getCurrentQuestionIndex() + 1) + ". ";
String question = index + exam.getCurrentQuestion().getQuestion();
currentQuestionLabel.setText(question);

//options
exam.getCurrentQuestion().getOptions().forEach( option -> updateOPanel(option));
updateRadioButtonSelection();

private void updateOPanel(Option option) {

switch (option.getName().toLowerCase()) {
case "a":
optionALabel.setText(option.getValue());
break;
case "b":
optionBLabel.setText(option.getValue());
break;
case "c":
optionCLabel.setText(option.getValue());
break;
case "d":
optionDLabel.setText(option.getValue());
break;
default:
break;
}
}

private void updateRadioButtonSelection() {


System.out.println("isAnswered --- "+ exam.getCurrentQuestion().isAnswered());

if(exam.getCurrentQuestion().isAnswered()) {
switch (exam.getCurrentQuestion().getUserSelectedOption().getName()) {
case "a":
optionA.setSelected(true);
break;
case "b":
optionB.setSelected(true);
break;
case "c":
optionC.setSelected(true);
break;
case "d":
optionD.setSelected(true);
break;
default:
break;
}
}
}

private void addListenersToRadioButtons() {


optionA.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("Option A --- selected.");
exam.getCurrentQuestion().setUserSelectedOption(getOption("a"));
}
});

optionB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("Option B --- selected.");
exam.getCurrentQuestion().setUserSelectedOption(getOption("b"));
}
});

optionC.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("Option C --- selected.");
exam.getCurrentQuestion().setUserSelectedOption(getOption("c"));
}
});

optionD.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("Option D --- selected.");
exam.getCurrentQuestion().setUserSelectedOption(getOption("d"));
}
});
}

private Option getOption(String name) {


return new Option(name, "");
}

LoginPage.java

package com.oes.pages;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.oes.app.Application;

public class LoginPage extends Page {

private static LoginPage loginPage;


private JTextField usernameInput;
private JPasswordField passwordInput;
private JButton loginBtn;
private JButton registerBtn;

private LoginPage() {
super();
name = "OES - Login";
width = 400;
height = 200;
panel = new JPanel();
usernameInput = new JTextField(10); // accepts upto 10 characters
passwordInput = new JPasswordField(10);
loginBtn = new JButton("Login");
registerBtn = new JButton("Sign up");
init();
}

public static LoginPage getInstance() {


if(loginPage == null)
loginPage = new LoginPage();
return loginPage;
}

private void init() {


updateUI();
loginBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String username = usernameInput.getText();
String password = String.valueOf(passwordInput.getPassword());
if(validate(username, password)) {
boolean isAuthenticated =
Application.getInstance().login(username, password);
if(isAuthenticated) {
usernameInput.setText("");
passwordInput.setText("");
close();
WelcomePage.getInstance().open();
}else {
display("Username or password is wrong, please try
again.");
}
}
}
});

registerBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
close();
RegisterPage.getInstance().open();
}
});
}

private boolean validate(String username, String password) {


if(!emailValidate(username)) {
display("please enter valid email id");
return false;
}
return true;

private boolean emailValidate(String email) {


Matcher matcher = Pattern.compile("^([\\w-\\.]+){1,64}@([\\w&&[^_]]+){2,255}(.[a-z]
{2,3})+$|^$", Pattern.CASE_INSENSITIVE).matcher(email);
return matcher.find();
}

private void display(String msg) {


JOptionPane.showMessageDialog(panel, msg);
}

private void updateUI() {


JLabel usernameLabel = new JLabel("Enter Username");
JLabel passwordLabel = new JLabel("Enter Password");

panel.add(usernameLabel); // Components Added using Flow Layout


panel.add(usernameInput);
panel.add(passwordLabel);
panel.add(passwordInput);

panel.add(loginBtn);
panel.add(registerBtn);
panel.setLayout(new GridLayout(3,2, 20, 30));
panel.setBorder(new EmptyBorder(10, 10, 20, 10));
}

Page.java

package com.oes.pages;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Page {

protected JFrame frame;


protected int width;
protected int height;
protected String name;
protected JPanel panel;

public Page() {
}

public void open() {


frame = new JFrame(name);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
Point center = new Point(dim.width/2 - frame.getSize().width/2, dim.height/2 -
frame.getSize().height/2);
frame.setLocation(center);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.setVisible(true);
}

public void close() {


frame.setVisible(false);
}

public void showMsg(String msg) {


JOptionPane.showMessageDialog(panel, msg);
}
}

RegisterPage.java

package com.oes.pages;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import com.oes.constants.ErrorMessages;
import com.oes.data.StudentData;
import com.oes.pojos.Student;

public class RegisterPage extends Page {

private static RegisterPage registerPage;


private JTextField firstNameInput;
private JTextField lastNameInput;
private JTextField qualificationInput;
private JTextField mobileInput;
private JTextField emailInput;
private JTextField passwordInput;
private JButton registerBtn;
private JButton cancelBtn;
private StudentData studentData;

private RegisterPage() {
super();
name = "OES - Register";
width = 400;
height = 500;
panel = new JPanel();
panel = new JPanel();
firstNameInput = new JTextField(10);
lastNameInput = new JTextField(10);
qualificationInput = new JTextField(20);
mobileInput = new JTextField(10);
emailInput = new JTextField(20);
passwordInput = new JTextField(10);
cancelBtn = new JButton("Cancel");
registerBtn = new JButton("Register");
studentData = new StudentData();
init();
}

public static RegisterPage getInstance() {


if(registerPage == null)
registerPage = new RegisterPage();
return registerPage;
}

private void init() {


updateUI();
registerBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String firstName = firstNameInput.getText();
String lastName = lastNameInput.getText();
String qualification = qualificationInput.getText();
String mobile = mobileInput.getText();
String email = emailInput.getText();
String password = passwordInput.getText();

Student studentToRegister = new Student(0, firstName, lastName,


qualification, mobile, email, password);

System.out.println("Register button pressed - " + studentToRegister);

boolean isAdded = studentData.addStudent(studentToRegister);

if(isAdded) {
display(ErrorMessages.REGISTRATION_SUCCESSFUL);
close();
LoginPage.getInstance().open();
}else {
display(ErrorMessages.REGISTRATION_FAILURE);
}

}
});

cancelBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//TODO: cancel the student registration
close();
LoginPage.getInstance().open();
}
});
}

private void display(String msg) {


JOptionPane.showMessageDialog(panel, msg);
}

public void updateUI() {

JLabel firstNameLabel = new JLabel("First Name");


JLabel lastNameLabel = new JLabel("Last Name");
JLabel qualitificationLabel = new JLabel("Qualification");
JLabel mobileLabel = new JLabel("Mobile");
JLabel emailLabel = new JLabel("Email");
JLabel passwordLabel = new JLabel("Password");

panel.add(firstNameLabel); // Components Added using Flow Layout


panel.add(firstNameInput);

panel.add(lastNameLabel);
panel.add(lastNameInput);

panel.add(qualitificationLabel);
panel.add(qualificationInput);

panel.add(mobileLabel);
panel.add(mobileInput);

panel.add(emailLabel);
panel.add(emailInput);
panel.add(passwordLabel);
panel.add(passwordInput);

panel.add(registerBtn);
panel.add(cancelBtn);

panel.setLayout(new GridLayout(7,2, 20, 30));


panel.setBorder(new EmptyBorder(10, 10, 20, 10));
}

ResultPage.java

package com.oes.pages;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.oes.app.Application;
import com.oes.pojos.Result;

public class ResultPage extends Page {

private static ResultPage resultPage;


private JButton logoutBtn;
JTextField nameTextField, percentTextField, statusTextField;
Result result;

private ResultPage() {
super();
name = "OES - Results";
width = 400;
height = 400;
panel = new JPanel();
logoutBtn = new JButton("Logout");
init();
}

public static ResultPage getInstance() {


if(resultPage == null)
resultPage = new ResultPage();
return resultPage;
}

private void init() {


initUI();
logoutBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
close();
LoginPage.getInstance().open();
}
});
}

private JPanel getResultPanel() {


JPanel resultPanel = new JPanel();
resultPanel.setLayout(new GridLayout(3, 2, 10, 10));
//name, percent, status
JLabel nameLabel = new JLabel("Name");
JLabel percentLabel = new JLabel("Percent");
JLabel statusLabel = new JLabel("Status");

nameTextField = new JTextField(20);


percentTextField = new JTextField(20);
statusTextField = new JTextField(20);

nameTextField.setEditable(false);
percentTextField.setEditable(false);
statusTextField.setEditable(false);

resultPanel.add(nameLabel);
resultPanel.add(nameTextField);

resultPanel.add(percentLabel);
resultPanel.add(percentTextField);

resultPanel.add(statusLabel);
resultPanel.add(statusTextField);

return resultPanel;
}

private void initUI() {


panel.setLayout(new BorderLayout(20, 15));

JLabel resultLabel = new JLabel("Result");

panel.add(resultLabel, BorderLayout.NORTH);
panel.add(getResultPanel(), BorderLayout.CENTER);
panel.add(logoutBtn, BorderLayout.SOUTH);

panel.setBorder(new EmptyBorder(10, 10, 20, 10));


}

public Result getResult() {


return result;
}

public void setResult(Result result) {


this.result = result;
updateResult();
}

private void updateResult() {

nameTextField.setText(Application.getInstance().getLoggedInStudent().getFirstName());
percentTextField.setText(result.getPercent()+"%");
statusTextField.setText(result.getStatus().toString());
}

WelcomePage.java

package com.oes.pages;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.oes.app.Application;

public class WelcomePage extends Page {

private static WelcomePage welcomePage;


private JButton startExamBtn;

private WelcomePage() {
super();
name = "OES - Welcome";
width = 400;
height = 400;
panel = new JPanel();
startExamBtn = new JButton("Start Exam");
init();
}

public static WelcomePage getInstance() {


if(welcomePage == null)
welcomePage = new WelcomePage();
return welcomePage;
}

private void init() {


updateUI();
startExamBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
close();
ExamPage.getInstance().open();
}
});
}

private void updateUI() {


panel.setLayout(new BorderLayout(20, 15));

String formatedName =
getFormatedName(Application.getInstance().getLoggedInStudent().getFirstName());
String welcomeMessage = formatedName;
JLabel welcomeLabel = new JLabel(welcomeMessage);

panel.add(welcomeLabel, BorderLayout.NORTH);
panel.add(getExamRulesPanel(), BorderLayout.CENTER);
panel.add(startExamBtn, BorderLayout.SOUTH);

panel.setBorder(new EmptyBorder(10, 10, 20, 10));


}

private JPanel getExamRulesPanel() {


JPanel rulePanel = new JPanel();
rulePanel.setLayout(new BorderLayout());
String ruleText = "This is a simple user friendly software developed using Java. "
+ "It can be applied to schools ,colleges etc to conduct exams. "
+ "The procedure for using this software is very easy. "
+ "Select one of the exams listed in the menu."
+ "After selecting the choice the exam will be started by clicking
continue button. "
+ "The questions and options are displayed on the screen. "
+ "We can choose one of the answer. "
+ "After completing the exam the results are displayed on the
screen.";
ruleText = "<html><body><div style=\" padding: 3px;\"><p style=\" border: 1px
solid black; padding: 4px; \">" + ruleText + "</p></div></body></html>";
JLabel ruleLabel = new JLabel(ruleText);

rulePanel.add(ruleLabel, BorderLayout.CENTER);

return rulePanel;
}

private String getFormatedName(String name) {


return "<html> <font color=\"#6C07F3\"> Welcome, " + name + "</font></html>";
}
}

Exam.java

package com.oes.pojos;
import java.util.List;
import java.util.stream.Collectors;

import com.oes.data.QuestionData;

public class Exam {

Student student;
List<Question> questions;
Question currentQuestion;
int currentQuestionIndex;
int totalQuestionCount;
int attemptedQuestionCount;
int passedQuestionCount;

public Exam() {
this(new QuestionData().getAllQuestions());
}

public Exam(List<Question> questions) {


super();
currentQuestionIndex = 0;
this.questions = questions;
}

public Student getStudent() {


return student;
}

public void setStudent(Student student) {


this.student = student;
}

public List<Question> getQuestions() {


return questions;
}

public void setQuestions(List<Question> questions) {


this.questions = questions;
}

public int getCurrentQuestionIndex() {


return currentQuestionIndex;
}

public void setCurrentQuestionIndex(int currentQuestionIndex) {


this.currentQuestionIndex = currentQuestionIndex;
}

public int getTotalQuestionCount() {


return totalQuestionCount;
}

public void setTotalQuestionCount(int totalQuestionCount) {


this.totalQuestionCount = totalQuestionCount;
}

public int getAttemptedQuestionCount() {


return attemptedQuestionCount;
}

public void setAttemptedQuestionCount(int attemptedQuestionCount) {


this.attemptedQuestionCount = attemptedQuestionCount;
}

public int getPassedQuestionCount() {


return passedQuestionCount;
}

public void setPassedQuestionCount(int passedQuestionCount) {


this.passedQuestionCount = passedQuestionCount;
}

public Question getCurrentQuestion() {


return questions.get(currentQuestionIndex);
}

public void setCurrentQuestion(Question currentQuestion) {


this.currentQuestion = currentQuestion;
}

public Result generateResult() {


totalQuestionCount = questions.size();
List<Question> attemptedQuestions = questions.stream().filter( que ->
que.isAnswered).collect(Collectors.toList());
attemptedQuestionCount = attemptedQuestions.size();

List<Question> passedQuestions = attemptedQuestions.stream().filter( que ->


que.getAnswer().equals(que.getUserSelectedOption())).collect(Collectors.toList());
passedQuestionCount = passedQuestions.size();

Result result = new Result(passedQuestionCount, totalQuestionCount);


return result;
}

Options.java
package com.oes.pojos;

public class Option {


String name;
String value;

public Option(String name, String value) {


super();
this.name = name;
this.value = value;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getValue() {


return value;
}

public void setValue(String value) {


this.value = value;
}

public boolean equals(Option option) {


return
this.getName().trim().equalsIgnoreCase(option.getName().trim());
}

@Override
public String toString() {
return "Option [name=" + name + ", value=" + value +
"]";
}

Questions.java

package com.oes.pojos;

import java.util.ArrayList;
import java.util.List;

public class Question {

int id;
String question;
List<Option> options;
Option answer;
boolean isAnswered;
Option userSelectedOption;

public Question() {
isAnswered = false;
options = new ArrayList<Option>();
}

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

public String getQuestion() {


return question;
}

public void setQuestion(String question) {


this.question = question;
}

public List<Option> getOptions() {


return options;
}

public void setOptions(List<Option> options) {


this.options = options;
}

public Option getAnswer() {


return answer;
}

public void setAnswer(Option answer) {


this.answer = answer;
}

public boolean isAnswered() {


return isAnswered;
}

public void setAnswered(boolean isAnswered) {


this.isAnswered = isAnswered;
}

public Option getUserSelectedOption() {


return userSelectedOption;
}

public void setUserSelectedOption(Option userSelectedOption) {


this.userSelectedOption = userSelectedOption;
this.isAnswered = true;
}

@Override
public String toString() {
return "Question [id=" + id + ", question=" + question + ", options=" + options + ",
answer=" + answer + "]";
}

}
Result.java
package com.oes.pojos;

import com.oes.constants.ResultStatus;

public class Result {

int passCount;
int totalCount;
int percent;
ResultStatus status;

public Result(int passCount, int totalCount) {


super();
this.passCount = passCount;
this.totalCount = totalCount;
this.percent = passCount * 100 / totalCount;
if(percent >= 35) status = ResultStatus.PASS;
else status = ResultStatus.FAIL;
}

public int getPassCount() {


return passCount;
}

public void setPassCount(int passCount) {


this.passCount = passCount;
}

public int getTotalCount() {


return totalCount;
}

public void setTotalCount(int totalCount) {


this.totalCount = totalCount;
}

public int getPercent() {


return percent;
}

public void setPercent(int percent) {


this.percent = percent;
}

public ResultStatus getStatus() {


return status;
}

public void setStatus(ResultStatus status) {


this.status = status;
}
@Override
public String toString() {
return "Result [passCount=" + passCount + ",
totalCount=" + totalCount + ", percent=" + percent + ", status="
+ status + "]";
}

Student.java

package com.oes.pojos;

public class Student {

private int id;


private String firstName;
private String lastName;
private String qualification;
private String mobile;
private String email;
private String password;

public Student() {
}

public Student(int id, String firstName, String lastName,


String qualification, String mobile, String email,
String password) {
super();
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.qualification = qualification;
this.mobile = mobile;
this.email = email;
this.password = password;
}

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

public String getFirstName() {


return firstName;
}

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public String getLastName() {


return lastName;
}

public void setLastName(String lastName) {


this.lastName = lastName;
}

public String getQualification() {


return qualification;
}

public void setQualification(String qualification) {


this.qualification = qualification;
}

public String getMobile() {


return mobile;
}

public void setMobile(String mobile) {


this.mobile = mobile;
}

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


this.password = password;
}

@Override
public String toString() {
return "Student [id=" + id + ", firstName=" + firstName
+ ", lastName=" + lastName + ", qualification="
+ qualification + ", mobile=" + mobile + ",
email=" + email + ", password=" + password + "]";
}

}
Conclusion

This project is MCQ Exam System has come to its final stage. The system has been
developed with much care that it is free of errors and at the same time this project
is less time consuming.

The most important thing is that the system is robust. And also, provision is
provided for future developments in the system. The entered system is secured. The
MCQ system will be approved and successfully implemented.

Bibliography

Reference books:

 Java: The Complete Reference, Eleventh Edition

Websites:
 www.javatpoint.com
 https://en.wikipedia.org/wiki/EExam
 https://sppuexam.in/login

You might also like