Java Quiz Contest System Implementation
VerifiedAdded on 2020/04/07
|15
|2080
|86
AI Summary
This assignment focuses on implementing a Java-based quiz contest system. It involves creating classes for students, a quiz contest, and a main program to manage the system. Students can be registered with their names and school affiliations. The quiz contest allows for entering scores and displaying the overall leaderboard. The program utilizes menus for user interaction and handles input validation.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Assignment Cover Sheet Faculty of Science and Technology
Student ID Student Name
Course Code Course Name
Date Submitted Lecturer’s Name
Tutor’s Name
ASSIGNMENT TITLE:
PLAGIARISM
Plagiarism is the presentation of the expressed thought or work of another person as though it is one's own without
properly acknowledging that person. You must not allow other students to copy your work and must take care to
safeguard against this happening.
Plagiarism is a serious offence. As set out in University Regulation 6.1.1., students who are caught plagiarising
will, for a first offence, be given a zero mark for that task. A second offence will result in a failing grade for the
Course(s) involved and any subsequent offence will be referred to the Student Discipline Committee.
Feedback / Assessment:
LECTURER’S SIGNATURE: DATE:
Faculty of Science and Technology, Federation University
Mt Helen Campus: PO Box 663 Ballarat Vic 3353
Gippsland Campus: PO Box 3191 Gippsland Mail Centre Vic 3481
CRICOS Provider Number 00103D
Declaration
Except where appropriately acknowledged, this assignment is my own work, has been expressed in
my own words and has not previously been submitted for assessment. I have also retained a copy
of this assessment piece for my own records.
Signature: Date:
Student ID Student Name
Course Code Course Name
Date Submitted Lecturer’s Name
Tutor’s Name
ASSIGNMENT TITLE:
PLAGIARISM
Plagiarism is the presentation of the expressed thought or work of another person as though it is one's own without
properly acknowledging that person. You must not allow other students to copy your work and must take care to
safeguard against this happening.
Plagiarism is a serious offence. As set out in University Regulation 6.1.1., students who are caught plagiarising
will, for a first offence, be given a zero mark for that task. A second offence will result in a failing grade for the
Course(s) involved and any subsequent offence will be referred to the Student Discipline Committee.
Feedback / Assessment:
LECTURER’S SIGNATURE: DATE:
Faculty of Science and Technology, Federation University
Mt Helen Campus: PO Box 663 Ballarat Vic 3353
Gippsland Campus: PO Box 3191 Gippsland Mail Centre Vic 3481
CRICOS Provider Number 00103D
Declaration
Except where appropriately acknowledged, this assignment is my own work, has been expressed in
my own words and has not previously been submitted for assessment. I have also retained a copy
of this assessment piece for my own records.
Signature: Date:
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Section 1: Design Documentation
Program Algorithm / Pseudocode / Flowchart
Step 1: Start
Step 2: Read the Number of Question for the quiz in the contest
Step 3: Display the header message
Step 4: Declare the contest object
Step 5: Declare the School Array
Step 6: Declare the Student Object for each student
Step 7: Enroll the student to the contest
Step 8: Print the enrolled or duplicate or exceed limit information
Step 9: Set isContinue to True
Step 10: Print menu list and get the user data
Step 11: Switch (userData)
If userData is 1, read the quiz scores
If userData is 2, display the student name and total score of the quiz in descending order
If userData is 3, display the program credit details
If userData is 4, set isContinue is False
If userData is > 5, Print the invalid choice message
Step 12: Check if isContinue is True, Got to 10, Otherwise Goto 13
Step 13: Print the exit information
Step 14: End
Program Algorithm / Pseudocode / Flowchart
Step 1: Start
Step 2: Read the Number of Question for the quiz in the contest
Step 3: Display the header message
Step 4: Declare the contest object
Step 5: Declare the School Array
Step 6: Declare the Student Object for each student
Step 7: Enroll the student to the contest
Step 8: Print the enrolled or duplicate or exceed limit information
Step 9: Set isContinue to True
Step 10: Print menu list and get the user data
Step 11: Switch (userData)
If userData is 1, read the quiz scores
If userData is 2, display the student name and total score of the quiz in descending order
If userData is 3, display the program credit details
If userData is 4, set isContinue is False
If userData is > 5, Print the invalid choice message
Step 12: Check if isContinue is True, Got to 10, Otherwise Goto 13
Step 13: Print the exit information
Step 14: End
Test Cases
Test Case Expected Result Actual Result
Program Initialization Display the enrolled
School, student details
Test Case 1
Read the Contest Score Enter the quiz mark for
each student
Test Case 2
View Contest Score Print the Student Name
with total mark and First
three student details
Test Case 3
View Credit Info Display the program
developer information
Test Case 4
Test Case Expected Result Actual Result
Program Initialization Display the enrolled
School, student details
Test Case 1
Read the Contest Score Enter the quiz mark for
each student
Test Case 2
View Contest Score Print the Student Name
with total mark and First
three student details
Test Case 3
View Credit Info Display the program
developer information
Test Case 4
Section 2: Program Development
public class School
{
private String name,registrationID;
public School(String regnum,String schoolname)
{
registrationID=regnum;
name=schoolname;
System.out.printf("\t... Successfully registered %s\n",name);
}
public String getID()
{
return registrationID;
}
public String getName()
{
return name;
}
}
public class Student
{
private String name;
private School enrolledSchool;
public Student(String studName,School enrollSchool)
{
name=studName;
enrolledSchool=enrollSchool;
System.out.printf("\t... student %s created.\n",name);
}
public String getName()
{
return name;
}
public School getSchool()
{
return enrolledSchool;
}
}
public class Entry
{
private Student entrant;
private int[] quizScores;
public Entry(Student student,int numQuiz)
{
quizScores=new int[numQuiz];
entrant=student;
School tSchool=entrant.getSchool();
System.out.printf("\t... successfully registered %s
representing %s\n",entrant.getName(),tSchool.getName());
}
public class School
{
private String name,registrationID;
public School(String regnum,String schoolname)
{
registrationID=regnum;
name=schoolname;
System.out.printf("\t... Successfully registered %s\n",name);
}
public String getID()
{
return registrationID;
}
public String getName()
{
return name;
}
}
public class Student
{
private String name;
private School enrolledSchool;
public Student(String studName,School enrollSchool)
{
name=studName;
enrolledSchool=enrollSchool;
System.out.printf("\t... student %s created.\n",name);
}
public String getName()
{
return name;
}
public School getSchool()
{
return enrolledSchool;
}
}
public class Entry
{
private Student entrant;
private int[] quizScores;
public Entry(Student student,int numQuiz)
{
quizScores=new int[numQuiz];
entrant=student;
School tSchool=entrant.getSchool();
System.out.printf("\t... successfully registered %s
representing %s\n",entrant.getName(),tSchool.getName());
}
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
public Student getEntrant()
{
return entrant;
}
public void setScore(int quizNum,int score)
{
quizScores[quizNum]=score;
}
public int getScore(int quizNum)
{
return quizScores[quizNum];
}
public int totalScore()
{
int i,tScore=0;
for(i=0;i<quizScores.length;i++)
tScore=tScore+quizScores[i];
return tScore;
}
}
import java.util.Scanner;
public class Contest
{
private String name;
private int MAX_ENTRANTS;
private int NUMBER_OF_QUESTIONS;
private int MAX_SCHOOL_ENTRANTS;
private int numberOfContestReg;
private Entry[] entries;
private int i,j;
public Contest(String contestname,int maxentrant,int numquestions,int
maxschoolentrant)
{
entries=new Entry[maxentrant];
numberOfContestReg=0;
name=contestname;
MAX_ENTRANTS=maxentrant;
NUMBER_OF_QUESTIONS=numquestions;
MAX_SCHOOL_ENTRANTS=maxschoolentrant;
}
public String getContestName()
{
return name;
}
public int getEntrantLimit()
{
return MAX_ENTRANTS;
}
public int getNumberOfQuestions()
{
return NUMBER_OF_QUESTIONS;
}
public void registerEntrant(Student student)
{
if(isDuplicateRegistration(student))
{
return entrant;
}
public void setScore(int quizNum,int score)
{
quizScores[quizNum]=score;
}
public int getScore(int quizNum)
{
return quizScores[quizNum];
}
public int totalScore()
{
int i,tScore=0;
for(i=0;i<quizScores.length;i++)
tScore=tScore+quizScores[i];
return tScore;
}
}
import java.util.Scanner;
public class Contest
{
private String name;
private int MAX_ENTRANTS;
private int NUMBER_OF_QUESTIONS;
private int MAX_SCHOOL_ENTRANTS;
private int numberOfContestReg;
private Entry[] entries;
private int i,j;
public Contest(String contestname,int maxentrant,int numquestions,int
maxschoolentrant)
{
entries=new Entry[maxentrant];
numberOfContestReg=0;
name=contestname;
MAX_ENTRANTS=maxentrant;
NUMBER_OF_QUESTIONS=numquestions;
MAX_SCHOOL_ENTRANTS=maxschoolentrant;
}
public String getContestName()
{
return name;
}
public int getEntrantLimit()
{
return MAX_ENTRANTS;
}
public int getNumberOfQuestions()
{
return NUMBER_OF_QUESTIONS;
}
public void registerEntrant(Student student)
{
if(isDuplicateRegistration(student))
System.out.printf("\t... Unable to register %s. Duplicate
registration\n",student.getName());
else if(capacityReached())
System.out.printf("\t... Unable to register %s. Contest
registration limit met.\n",student.getName());
else if (schoolLimitReached(student.getSchool()))
System.out.printf("\t... Unable to register %s. School
registration limit met.\n",student.getName());
else
entries[numberOfContestReg++]=new
Entry(student,NUMBER_OF_QUESTIONS);
}
private boolean capacityReached()
{
if(numberOfContestReg>=MAX_ENTRANTS)
return true;
else
return false;
}
private boolean schoolLimitReached(School school)
{
int numSchoolEntrant=0;
for(i=0;i<numberOfContestReg;i++)
{
i
f(entries[i].getEntrant().getSchool().getName().equalsIgnoreCase(school.get
Name()))
numSchoolEntrant++;
}
if(numSchoolEntrant>=MAX_SCHOOL_ENTRANTS)
return true;
else
return false;
}
public void enterScores()
{
@SuppressWarnings("resource")
Scanner kb=new Scanner(System.in);
for(i=0;i<NUMBER_OF_QUESTIONS;i++)
{
System.out.printf("\nScores for Question %d\n",(i+1));
for(j=0;j<numberOfContestReg;j++)
{
System.out.printf("\n\tEnter score for %s : \
n",entries[j].getEntrant().getName());
int quizScore=Integer.parseInt(kb.nextLine());
entries[j].setScore(i, quizScore);
}
}
System.out.println("Score entry complete");
}
public void viewContestScores()
{
sortResults();
for(i=0;i<numberOfContestReg;i++)
{
registration\n",student.getName());
else if(capacityReached())
System.out.printf("\t... Unable to register %s. Contest
registration limit met.\n",student.getName());
else if (schoolLimitReached(student.getSchool()))
System.out.printf("\t... Unable to register %s. School
registration limit met.\n",student.getName());
else
entries[numberOfContestReg++]=new
Entry(student,NUMBER_OF_QUESTIONS);
}
private boolean capacityReached()
{
if(numberOfContestReg>=MAX_ENTRANTS)
return true;
else
return false;
}
private boolean schoolLimitReached(School school)
{
int numSchoolEntrant=0;
for(i=0;i<numberOfContestReg;i++)
{
i
f(entries[i].getEntrant().getSchool().getName().equalsIgnoreCase(school.get
Name()))
numSchoolEntrant++;
}
if(numSchoolEntrant>=MAX_SCHOOL_ENTRANTS)
return true;
else
return false;
}
public void enterScores()
{
@SuppressWarnings("resource")
Scanner kb=new Scanner(System.in);
for(i=0;i<NUMBER_OF_QUESTIONS;i++)
{
System.out.printf("\nScores for Question %d\n",(i+1));
for(j=0;j<numberOfContestReg;j++)
{
System.out.printf("\n\tEnter score for %s : \
n",entries[j].getEntrant().getName());
int quizScore=Integer.parseInt(kb.nextLine());
entries[j].setScore(i, quizScore);
}
}
System.out.println("Score entry complete");
}
public void viewContestScores()
{
sortResults();
for(i=0;i<numberOfContestReg;i++)
{
Entry entry=entries[i];
System.out.printf("Total Score for : %-25s %d\n\
n",entry.getEntrant().getName(),entry.totalScore());
}
Student posEntrant=entries[0].getEntrant();
System.out.printf("First : \t %s from %s\
n",posEntrant.getName(),posEntrant.getSchool().getName());
posEntrant=entries[1].getEntrant();
System.out.printf("Second : \t %s from %s\
n",posEntrant.getName(),posEntrant.getSchool().getName());
posEntrant=entries[2].getEntrant();
System.out.printf("Third : \t %s from %s\
n",posEntrant.getName(),posEntrant.getSchool().getName());
}
private void sortResults()
{
Entry tempEntry;
for(i=1;i<numberOfContestReg;i++)
{
for(j=i;j>0;j--)
{
if(entries[j].totalScore()>entries[j-
1].totalScore())
{
tempEntry=entries[j];
entries[j]=entries[j-1];
entries[j-1]=tempEntry;
}
}
}
}
private boolean isDuplicateRegistration(Student student)
{
boolean result=false;
for(i=0;i<numberOfContestReg;i++)
{
if(entries[i].getEntrant().getName().equalsIgnoreCase(student.getName()))
{
result= true;
break;
}
}
return result;
}
}
import java.util.Scanner;
public class ID30332712
{
static String studentNum="30332712";
static String studentName="Mohammad Mozammel Hoque";
static Scanner keyboard =new Scanner(System.in);
static String contestName="Maths Whiz! Championship";
public static String menuList()
System.out.printf("Total Score for : %-25s %d\n\
n",entry.getEntrant().getName(),entry.totalScore());
}
Student posEntrant=entries[0].getEntrant();
System.out.printf("First : \t %s from %s\
n",posEntrant.getName(),posEntrant.getSchool().getName());
posEntrant=entries[1].getEntrant();
System.out.printf("Second : \t %s from %s\
n",posEntrant.getName(),posEntrant.getSchool().getName());
posEntrant=entries[2].getEntrant();
System.out.printf("Third : \t %s from %s\
n",posEntrant.getName(),posEntrant.getSchool().getName());
}
private void sortResults()
{
Entry tempEntry;
for(i=1;i<numberOfContestReg;i++)
{
for(j=i;j>0;j--)
{
if(entries[j].totalScore()>entries[j-
1].totalScore())
{
tempEntry=entries[j];
entries[j]=entries[j-1];
entries[j-1]=tempEntry;
}
}
}
}
private boolean isDuplicateRegistration(Student student)
{
boolean result=false;
for(i=0;i<numberOfContestReg;i++)
{
if(entries[i].getEntrant().getName().equalsIgnoreCase(student.getName()))
{
result= true;
break;
}
}
return result;
}
}
import java.util.Scanner;
public class ID30332712
{
static String studentNum="30332712";
static String studentName="Mohammad Mozammel Hoque";
static Scanner keyboard =new Scanner(System.in);
static String contestName="Maths Whiz! Championship";
public static String menuList()
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
{
String menu="";
men
u+="=======================================================================
========================\n";
menu+=contestName+" Administration\n";
men
u+="=======================================================================
========================\n\n";
menu+="Please select an option below :\n";
menu+="1. Enter Results\n";
menu+="2. Display Results\n";
menu+="3. View Program Credits\n";
menu+="4. Exit Program\n";
return menu;
}
public static String getCreditInfo()
{
String credit="";
credi
t+="=======================================================================
========================\n";
credit+="Program Credits\n\n";
credit+="This program was developed by :\n\n";
credit+="\t\t"+studentName+", "+studentNum+"\n\n";
credit+="for ITECH1000 Programming 1 Semester 2 2017\n\n";
credi
t+="=======================================================================
========================\n";
return credit;
}
public static int getNumQuizQuest()
{
int quizNum;
while(true) {
try {
System.out.println("How many questions are
required? (minimum of 1) : ");
quizNum=Integer.parseInt(keyboard.nextLine());
if(quizNum<1)
System.out.println("Invalid number of
question, it shoule be one or greater than one\n");
else
break;
}
catch(NumberFormatException nf) {
System.out.println("Invalid data type\n");
}
}
return quizNum;
String menu="";
men
u+="=======================================================================
========================\n";
menu+=contestName+" Administration\n";
men
u+="=======================================================================
========================\n\n";
menu+="Please select an option below :\n";
menu+="1. Enter Results\n";
menu+="2. Display Results\n";
menu+="3. View Program Credits\n";
menu+="4. Exit Program\n";
return menu;
}
public static String getCreditInfo()
{
String credit="";
credi
t+="=======================================================================
========================\n";
credit+="Program Credits\n\n";
credit+="This program was developed by :\n\n";
credit+="\t\t"+studentName+", "+studentNum+"\n\n";
credit+="for ITECH1000 Programming 1 Semester 2 2017\n\n";
credi
t+="=======================================================================
========================\n";
return credit;
}
public static int getNumQuizQuest()
{
int quizNum;
while(true) {
try {
System.out.println("How many questions are
required? (minimum of 1) : ");
quizNum=Integer.parseInt(keyboard.nextLine());
if(quizNum<1)
System.out.println("Invalid number of
question, it shoule be one or greater than one\n");
else
break;
}
catch(NumberFormatException nf) {
System.out.println("Invalid data type\n");
}
}
return quizNum;
}
public static void main(String[] args)
{
boolean isContinue=true;
int userData,numContestQuestion;
Contest quizContest;
System.out.println("Initialising Contest Administration
System ...\n");
numContestQuestion=getNumQuizQuest();
quizContest=new Contest(contestName,8,numContestQuestion,2);
System.out.println("\n--- Initialising Championship");
System.out.println("\t... Successfully created contest
"+contestName);
System.out.println("\n--- Registering Participating Schools
---");
School[] school=new School[5];
school[0]=new School("REG123","Damascus College");
school[1]=new School("REG456","Mt Clear Secondary College");
school[2]=new School("REG789","Ballarat High School");
school[3]=new School("REG369","Loreto College");
school[4]=new School("REG478","Ballarat and Clarendon
College");
System.out.println("\n--- Creating Student Recrods ---");
Student hary=new Student("Harry Potter",school[0]);
Student ronald=new Student("Ronald Weasley",school[0]);
Student hermione=new Student("Hermione Granger",school[1]);
Student draco=new Student("Draco Malfoy",school[1]);
Student nevile=new Student("Neville Longbottom",school[2]);
Student vincent=new Student("Vincent Crabbe",school[2]);
Student gregory=new Student("Gregory Goyle",school[3]);
Student luna=new Student("Luna Lovegood",school[3]);
Student pansy=new Student("Pansy Parkinson",school[0]);
Student anthony=new Student("Anthony Goldstein",school[4]);
System.out.println("\n--- Registering students in contest
---");
quizContest.registerEntrant(hary);
quizContest.registerEntrant(hary);
quizContest.registerEntrant(ronald);
quizContest.registerEntrant(pansy);
quizContest.registerEntrant(hermione);
quizContest.registerEntrant(draco);
quizContest.registerEntrant(nevile);
quizContest.registerEntrant(vincent);
quizContest.registerEntrant(gregory);
quizContest.registerEntrant(luna);
quizContest.registerEntrant(anthony);
System.out.println("\nInitialisation complete\n");
do
{
try
{
System.out.println(menuList());
public static void main(String[] args)
{
boolean isContinue=true;
int userData,numContestQuestion;
Contest quizContest;
System.out.println("Initialising Contest Administration
System ...\n");
numContestQuestion=getNumQuizQuest();
quizContest=new Contest(contestName,8,numContestQuestion,2);
System.out.println("\n--- Initialising Championship");
System.out.println("\t... Successfully created contest
"+contestName);
System.out.println("\n--- Registering Participating Schools
---");
School[] school=new School[5];
school[0]=new School("REG123","Damascus College");
school[1]=new School("REG456","Mt Clear Secondary College");
school[2]=new School("REG789","Ballarat High School");
school[3]=new School("REG369","Loreto College");
school[4]=new School("REG478","Ballarat and Clarendon
College");
System.out.println("\n--- Creating Student Recrods ---");
Student hary=new Student("Harry Potter",school[0]);
Student ronald=new Student("Ronald Weasley",school[0]);
Student hermione=new Student("Hermione Granger",school[1]);
Student draco=new Student("Draco Malfoy",school[1]);
Student nevile=new Student("Neville Longbottom",school[2]);
Student vincent=new Student("Vincent Crabbe",school[2]);
Student gregory=new Student("Gregory Goyle",school[3]);
Student luna=new Student("Luna Lovegood",school[3]);
Student pansy=new Student("Pansy Parkinson",school[0]);
Student anthony=new Student("Anthony Goldstein",school[4]);
System.out.println("\n--- Registering students in contest
---");
quizContest.registerEntrant(hary);
quizContest.registerEntrant(hary);
quizContest.registerEntrant(ronald);
quizContest.registerEntrant(pansy);
quizContest.registerEntrant(hermione);
quizContest.registerEntrant(draco);
quizContest.registerEntrant(nevile);
quizContest.registerEntrant(vincent);
quizContest.registerEntrant(gregory);
quizContest.registerEntrant(luna);
quizContest.registerEntrant(anthony);
System.out.println("\nInitialisation complete\n");
do
{
try
{
System.out.println(menuList());
userData=Integer.parseInt(keyboard.nextLine());
switch(userData)
{
case 1:
quizContest.enterScores();
break;
case 2:
quizContest.viewContestScores();
break;
case 3:
System.out.println(getCreditInfo());
break;
case 4:
isContinue=false;
break;
default:
System.out.println("Invalid menu data\
n");
}
}
catch(NumberFormatException nf)
{
System.out.println("Invalid data input\n");
}
} while(isContinue);
System.out.printf("\nThank for using the %s Adminstration
System",contestName);
}
}
switch(userData)
{
case 1:
quizContest.enterScores();
break;
case 2:
quizContest.viewContestScores();
break;
case 3:
System.out.println(getCreditInfo());
break;
case 4:
isContinue=false;
break;
default:
System.out.println("Invalid menu data\
n");
}
}
catch(NumberFormatException nf)
{
System.out.println("Invalid data input\n");
}
} while(isContinue);
System.out.printf("\nThank for using the %s Adminstration
System",contestName);
}
}
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Section 3: Testing
Test Case 1
Test Case 1
Test Case 2
Test Case 3
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Test Case 4
Section 4: Acknowledgements
Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java
Language > Numbers and Strings). (n.d.). Retrieved from
https://docs.oracle.com/javase/tutorial/java/data/numberformat.html
Java String equalsIgnoreCase() Method. (n.d.). Retrieved from
https://www.tutorialspoint.com/java/java_string_equalsignorecase.htm
Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java
Language > Numbers and Strings). (n.d.). Retrieved from
https://docs.oracle.com/javase/tutorial/java/data/numberformat.html
Java String equalsIgnoreCase() Method. (n.d.). Retrieved from
https://www.tutorialspoint.com/java/java_string_equalsignorecase.htm
1 out of 15
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.