Quiz Scoresheet

Quiz Scoresheet is the project in which it is used to control the quiz scores. And later it gives the names of the winner and scores and also lists the rank of every team.



Explaining the code :-

The first frame of the project is to collect the data from the users about the quiz.

For eg. quiz type, category, year, school/university name and also about marking scheme like marks awarded for answering direct question and pass over question and also for rapid fire questions.

quiz details

To retrieve the data and store it in variables is a simple task, we just have to use the getText() method store the returned the values in the variables.

On this frame you will get three buttons, cancel for exit, clear for clearing the written data in the text fields and team selector for bring up the team selector frame and storing the values.

Now we have the team selector frame in which names of the participant is taken and stored it in the variables. And again we have used the getText() method.

team selector

After filling names we can start the quiz and start recording the quiz scores.

Here we have used have used some good amount of code that we can discuss on.

scoresheet

Firstly, I have used the key events to give the score to a particular team in the particular round.

So, To give the score for direct question you can just press the up arrow key and if the answered question was pass over than press the right arrow key. And for rapid fire round to give score for right answer press the up arrow key and for negative marking press the right arrow key. And every time you award the score to team its total score is updated in the real time.

To achieve these functionality I have used the Key Events.

if(evt.getKeyCode()==KeyEvent.VK_UP){
double x=Double.parseDouble(ar1.getText());
double sumar1=x+dirques;
ar1.setText(""+sumar1);
refresh.doClick();}
if(evt.getKeyCode()==KeyEvent.VK_RIGHT){
double x=Double.parseDouble(ar1.getText());
double sumar1=x+passques;
ar1.setText(""+sumar1);
refresh.doClick();}

 

Here we have used a method doClick() , which is used to click the button without actually clicking on it.




After collecting all the scores Now there is a button to declare the winner. And also it prepares the list of teams with respective scores and ranks.

winner

To prepare the list I had used the JTable and sort method and some code.

double teamscores[] = {teama,teamb,teamc,teamd,teame,teamf};
sort(teamscores);
DefaultTableModel model = (DefaultTableModel) ranktable.getModel();
for(int i=0; i< teamscores.length;i++){

if(teamscores[i] == teama){
model.addRow(new Object[]{"Team A",Double.toString(teama),Integer.toString(i+1)});

}else
if(teamscores[i] == teamb){
model.addRow(new Object[]{"Team B",Double.toString(teamb),Integer.toString(i+1)});

}else
if(teamscores[i] == teamc){
model.addRow(new Object[]{"Team C",Double.toString(teamc),Integer.toString(i+1)});

}else
if(teamscores[i] == teamd){
model.addRow(new Object[]{"Team D",Double.toString(teamd),Integer.toString(i+1)});

}else
if(teamscores[i] == teame){
model.addRow(new Object[]{"Team E",Double.toString(teame),Integer.toString(i+1)});

}else{
model.addRow(new Object[]{"Team F",Double.toString(teamf),Integer.toString(i+1)});

}

}

This is sort method

void sort(double teamscores[]){
int n = teamscores.length;
for(int i=0;i< n;i++){
for(int j=i+1;j<n;j++){
if(teamscores[j] > teamscores[i]){
double temp;
temp = teamscores[i];
teamscores[i]= teamscores[j];
teamscores[j] = temp;
}
}
}
}

There are two major buttons, one is for creating the rank list and another is creating new scoresheet.

To create a new scoresheet is simple as I only have to setText(null) to all the text fields and initialize all the variables to null and also empty the table in which rank list is stored.

After clicking the rank list, it will give the new frame in which teams are arranged in order of their rank and scores.

rank list

You can download the project here

The following two tabs change content below.

Amit Rawat

Founder and Developer at SpiderLabWeb
I love to work on new projects and also work on my ideas. My main field of interest is Web Development.

You may also like...