/*
This program is a musical quiz that tests the users knowledge on all different types of music.
Auther- Tsotne Gvadzabia
Date Created = 10/10/16
*/
import java.util.Scanner;
import java.util.Random;
class quiz
{
public static void main(String[]p) //Main
{
int teamsc = 0; //initialize teamsc---used to determine team score
int team =0; //initialize team----used to determine number of people in team
boolean correct = false; //initialize correct--- this is used to determine if the user got the question correct or not
int [] score; //Score array declared
team = teamintro(team);
score=scorem(team);
//Question round methods:
teamsc=rounds(correct,team,score,teamsc);
lastprint(teamsc,team,score);
System.exit(0);
}
public static int teamintro(int team) //Method used to find out how many team members there are
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of people in your team.");
team = scanner.nextInt();
return team;
}
public static int [] scorem(int team) //Array method
{
int [] score = new int [team+1]; //Array is initialised with plus 1 so it doesnt go out of bounds
return score; //returns the array data
}
public static int round1(boolean correct,int team,int [] score,int teamsc) //First Question
{
for (int i=1;i<=3;i++
Scanner scanner= new Scanner(System.in);
questions q1 = new questions();
q1=setQuestion(q1,"Who composed the first Opera?");
q1=setReal(q1,"Jacopo Peri");
String answer1;
//boolean correct;
for (int i=1; i<=team; i++) //Loop START--- is repeated depending on how many team members were inputted by the user
{
System.out.println(getQuestion(q1));
answer1= scanner.nextLine();
if (answer1.equalsIgnoreCase(getReal(q1)))
{
correct = true; //Makes correct true
System.out.println("You are correct!");
}
else
{
correct= false; //Makes correct false
System.out.println("You are wrong!");
}
Random dice = new Random();
if (correct)
{
score[i] = dice.nextInt(6)+1;
System.out.println("Your score is: "+ score[i]); //displays score only if correct is true
teamsc= teamsc+score[i];
}
else
{
System.out.println("Your score is: "+score[i]); //Displays score as 0 when correct is falce
}
} //LOOP END
return teamsc;
}
public static void lastprint(int teamsc,int team,int[]score)
{
System.out.println(" ");
System.out.println("---------------------------- "); //Creates a gap between the questions and the actual results
System.out.println(" ");
System.out.println("Team Score"); //Team Score displayed below
System.out.println(" ");
System.out.println("Your team collected the score of:"+teamsc);
System.out.println("With "+team+" members.");
System.out.println("-----------------------------");
System.out.println("Player Score"); //Individual Score
System.out.println(" ");
for (int i=1; i<=team; i++) //For loop to display each players score
{
System.out.println(" "+i+" | "+score[i]);
}
}
//Getter and Setter methods are used below to store the question and correct answer
public static String [] getQuestion(questions q)
{
return q.question;
}
public static String [] getReal(questions q)
{
return q.real;
}
public static questions setQuestion(questions q, String [] qu)
{
q.question = qu;
return q;
}
public static questions setReal(questions q, String [] r)
{
q.real = r;
return q;
}
} //End of program
class questions
{
String [] question = new String[3]; //question
String [] real = new String [3]; //stores the correct answer
}
A one question Quiz that could be easily expanded.
You enter how many members there are in your team.
Each correct answer gives you a random score between 1-6
If your answer is incorrect you gain 0 points.
The points are then added up at the end to show your teams score along with Individual scores.
You enter how many members there are in your team.
Each correct answer gives you a random score between 1-6
If your answer is incorrect you gain 0 points.
The points are then added up at the end to show your teams score along with Individual scores.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.