Sunday, March 22, 2020

BlueJ Program On Quiz Competetion



Details of The Program: Click Here

import java.io.*;

class Quiz 

{

char allans[][]; int result[],n;

String quiz[]={"1. What is the orange part of a egg called?\n1. Yolk 2. Shell 3. Round Vit 4. Solid Membrane\n",

                "\n2. How many legs do insects have?\n 1. 6  2. 4  3. 8 4. 10\n",

                "\n3. What is a baby kangaroo called?\n 1. Puppy  2. Joey  3. Cub  4. Kitten\n",

                "\n4. What is the closest planet to the Sun?\n 1. Mars  2. Pluto  3. Mercury 4. Saturn\n",

                "\n5. In which country can you find the Eiffel Tower?\n 1. Germany  2. Italy  3. France  4. UK\n",

                "\n6. How many days are there in a year?\n 1.365  2. 366  3.May be 1 or 2  4. 360\n",

                "\n7. How many players are in a soccer team?\n 1. 16  2. 7  3.  11  4. 9\n",

                "\n8. Where do polar bears live?\n 1. The Arctic  2. Himalayan Range  3. Eastern Siberia  4. Alashka\n",

                "\n9. Which is faster, light or sound?\n 1. Light  2. Sound  3. Both \n",

                "\n10. How many letters are in the English alphabet?\n 1. 24  2.  28  3.  26  4. 30\n",

                "\n11. What is the name of a shape with 5 sides?\n 1.Hexagon 2. Pentagon  3. Square  4. Rhombus\n",

                "\n12. How many Continents are there?\n 1. 13  2.  6  3. 7  4.  8\n",

                "\n13. What is the name of the tallest mountain on earth?\n 1. Mount Everest  2. Makalu  3. Manaslu  4. K2\n",

                "\n14. The planet Mars is also known as what?\n 1. The Brown Planet  2. The Red Planet  3. The Yellow Planet  4. The Pink Planet\n",

                "\n15. How many months have 31 days? 1. Six 2. Four  3. Seven 4. Nine\n",

                "\n16. How many colors of the rainbow are there?\n 1. Six  2. Seven  3. Five  4. Nine\n",

                "\n17. My mother’s mother is my…what?\n 1. Grandmother  2. Aunty  3. Big Mother  4. None of the above\n",

                "\n18. Which animal lays the largest eggs?\n 1. Emu  2. Ostrich  3. Kiwi  4. None of the above\n",

                "\n19. How many zeros are in ten thousand?\n 1. Four  2. Three  3. Five  4. None\n",

                "\n20. In which country would you find the Sydney Opera House?\n 1. Australia  2. New Zealand  3. Greece  3. Keniya\n"

            };

            char correct[]={'1', '1', '2','3','3','1','3','1','1','3','2','3','1','2','3','2','1','2','1','1'};

            /* Array to store answer key */

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

public void takeAns() throws Exception 

{

System.out.print("Enter number of participants : "); n = Integer.parseInt(br.readLine());

 if(n <4 || n> 10)

{ 

System.out.println("INPUT SIZE OUT OF RANGE"); return; 

}

 allans = new char[n][20]; /* Array to hold answers of every participants */

 result = new int[n]; /* Array to store score of individual participant */

 System.out.println("\n Enter answer of each participant, please enter the answer line 1, 2, 3 or 4 as numbered on options\n");

for(int i = 0; i<n;i++) 

{

 System.out.println("\nTaking answers from participant no "+(i+1));

for(int j=0; j<20; j++)

{

System.out.println(quiz[j]);

br =new BufferedReader(new InputStreamReader(System.in));

System.out.print("\nAnswer of Quiz No " + (j+1) + " : ");

 allans[i][j] = (char)br.read();

}

 }

getMarks();

}

private void getMarks()

/* Function to calculate score */

 {

for(int i = 0; i<n;i++) 

{

result[i] = 0; 

for(int j=0; j<20; j++) 

{

if(allans[i][j] == correct[j])

{

 result[i]=result[i]+1;

}

 } 

}

printResult(); 

}

private void printResult() 

{

int max = 0; System.out.println("\nSCORES : "); for(int i = 0; i<n;i++)

 { 

System.out.println("\tParticipant No:"+(i+1)+" = "+result[i]); if(result[i] > max)

 {

max = result[i]; /* Storing the Highest Score */ 

}

}

System.out.println("\nHighest Score : "+max);

System.out.println("\tHighest Scorers : ");

for(int i = 0; i<n;i++) 

{

if(result[i] == max) 

{ 

System.out.println("***Participant No "+(i+1));

} 

}

}

public static void main(String args[])throws Exception

 { 

Quiz ob = new Quiz(); ob.takeAns();

} 

}

 

 

Algorithm

 

1.    Create variables char allans[][]; int result[],n; and initialize the variables String quiz[] and char correct [] with constant values

2.    Take the number of participants from user and store in ‘n’. while storing the value, confirm that number of participants is greater than 4 and less than 10

3.    Display one after another quiz questions along with 4 options and take user input and store in allans[][]

4.    Once the intake of answers is completed, checks the answers of each participants with the correct answers and store the results in array result[]

5.    Display the results

6.    Check the highest score and display

 

Variable Description

 

Type

Name

Purpose

char

allans[][]

Stores answers of all participants

int

result[]

Stores score of all participants

int

n

Holds number of participants

String

quiz[]

Stores 20 questions along with 4 options

char

correct[]

Stores the correct answers of all questions

BufferedReader

br

Input object

 

 

Sample Input Output

 

Enter number of participants : 5

 

 Enter answer of each participant, please enter the answer line 1, 2, 3 or 4 as numbered on options

 

Taking answers from participant no 1

1. What is the orange part of an egg called?

1. Yolk 2. Shell 3. Round Vit 4. Solid Membrane

 

Answer of Quiz No 1 : 1

 

2. How many legs do insects have?

 1. 6  2. 4  3. 8 4. 10

 

Answer of Quiz No 2 : 2

 

3. What is a baby kangaroo called?

 1. Puppy  2. Joey  3. Cub  4. Kitten

 

Answer of Quiz No 3 : 3

 

4. What is the closest planet to the Sun?

 1. Mars  2. Pluto  3. Mercury 4. Saturn

 

Answer of Quiz No 4 : 4

 

5. In which country can you find the Eiffel Tower?

 1. Germany  2. Italy  3. France  4. UK

 

Answer of Quiz No 5 : 6

 

6. How many days are there in a year?

 1.365  2. 366  3.May be 1 or 2  4. 360

 

Answer of Quiz No 6 : 5

 

7. How many players are in a soccer team?

 1. 16  2. 7  3.  11  4. 9

 

Answer of Quiz No 7 : 1

 

8. Where do polar bears live?

 1. The Arctic  2. Himalayan Range  3. Eastern Siberia  4. Alashka

 

Answer of Quiz No 8 : 2

 

9. Which is faster, light or sound?

 1. Light  2. Sound  3. Both

 

Answer of Quiz No 9 : 4

 

10. How many letters are in the English alphabet?

 1. 24  2.  28  3.  26  4. 30

 

Answer of Quiz No 10 : 1

 

11. What is the name of a shape with 5 sides?

 1.Hexagon 2. Pentagon  3. Square  4. Rhombus

 

Answer of Quiz No 11 : 2

 

12. How many Continents are there?

 1. 13  2.  6  3. 7  4.  8

 

Answer of Quiz No 12 : 3

 

13. What is the name of the tallest mountain on earth?

 1. Mount Everest  2. Makalu  3. Manaslu  4. K2

 

 

Answer of Quiz No 13 : 4

 

14. The planet Mars is also known as what?

 1. The Brown Planet  2. The Red Planet  3. The Yellow Planet  4. The Pink Planet

 

Answer of Quiz No 14 : 1

 

15. How many months have 31 days? 1. Six 2. Four  3. Seven 4. Nine

 

Answer of Quiz No 15 : 2

 

16. How many colors of the rainbow are there?

 1. Six  2. Seven  3. Five  4. Nine

 

Answer of Quiz No 16 : 3

 

17. My mother’s mother is my…what?

 1. Grandmother  2. Aunty  3. Big Mother  4. None of the above

 

Answer of Quiz No 17 : 1

 

18. Which animal lays the largest eggs?

 1. Emu  2. Ostrich  3. Kiwi  4. None of the above

 

Answer of Quiz No 18 : 2

 

19. How many zeros are in ten thousand?

 1. Four  2. Three  3. Five  4. None

 

Answer of Quiz No 19 : 3

 

20. In which country would you find the Sydney Opera House?

 1. Australia  2. New Zealand  3. Greece  3. Keniya

 

Answer of Quiz No 20 : 1

 

Taking answers from participant no 2

1. What is the orange part of an egg called?

1. Yolk 2. Shell 3. Round Vit 4. Solid Membrane

 

Answer of Quiz No 1 : 1

 

2. How many legs do insects have?

 1. 6  2. 4  3. 8 4. 10

 

Answer of Quiz No 2 : 2

 

3. What is a baby kangaroo called?

 1. Puppy  2. Joey  3. Cub  4. Kitten

 

Answer of Quiz No 3 : 3

 

4. What is the closest planet to the Sun?

 1. Mars  2. Pluto  3. Mercury 4. Saturn

 

Answer of Quiz No 4 : 2

 

5. In which country can you find the Eiffel Tower?

 1. Germany  2. Italy  3. France  4. UK

 

Answer of Quiz No 5 : 1

 

6. How many days are there in a year?

 1.365  2. 366  3.May be 1 or 2  4. 360

 

Answer of Quiz No 6 : 2

 

7. How many players are in a soccer team?

 1. 16  2. 7  3.  11  4. 9

 

Answer of Quiz No 7 : 3

 

8. Where do polar bears live?

 1. The Arctic  2. Himalayan Range  3. Eastern Siberia  4. Alashka

 

Answer of Quiz No 8 : 4

 

9. Which is faster, light or sound?

 1. Light  2. Sound  3. Both

 

Answer of Quiz No 9 : 3

 

10. How many letters are in the English alphabet?

 1. 24  2.  28  3.  26  4. 30

 

Answer of Quiz No 10 : 2

 

11. What is the name of a shape with 5 sides?

 1.Hexagon 2. Pentagon  3. Square  4. Rhombus

 

Answer of Quiz No 11 : 1

 

12. How many Continents are there?

 1. 13  2.  6  3. 7  4.  8

 

 

Answer of Quiz No 12 : 2

 

13. What is the name of the tallest mountain on earth?

 1. Mount Everest  2. Makalu  3. Manaslu  4. K2

 

Answer of Quiz No 13 : 3

 

14. The planet Mars is also known as what?

 1. The Brown Planet  2. The Red Planet  3. The Yellow Planet  4. The Pink Planet

 

Answer of Quiz No 14 : 4

 

15. How many months have 31 days? 1. Six 2. Four  3. Seven 4. Nine

 

Answer of Quiz No 15 : 3

 

16. How many colors of the rainbow are there?

 1. Six  2. Seven  3. Five  4. Nine

 

Answer of Quiz No 16 : 2

 

17. My mother’s mother is my…what?

 1. Grandmother  2. Aunty  3. Big Mother  4. None of the above

 

Answer of Quiz No 17 : 1

 

18. Which animal lays the largest eggs?

 1. Emu  2. Ostrich  3. Kiwi  4. None of the above

 

Answer of Quiz No 18 : 2

 

19. How many zeros are in ten thousand?

 1. Four  2. Three  3. Five  4. None

 

Answer of Quiz No 19 : 3

 

20. In which country would you find the Sydney Opera House?

 1. Australia  2. New Zealand  3. Greece  3. Keniya

 

Answer of Quiz No 20 : 4

 

Taking answers from participant no 3

1. What is the orange part of an egg called?

1. Yolk 2. Shell 3. Round Vit 4. Solid Membrane

 

Answer of Quiz No 1 : 4

 

2. How many legs do insects have?

 1. 6  2. 4  3. 8 4. 10

 

Answer of Quiz No 2 : 3

 

3. What is a baby kangaroo called?

 1. Puppy  2. Joey  3. Cub  4. Kitten

 

Answer of Quiz No 3 : 2

 

4. What is the closest planet to the Sun?

 1. Mars  2. Pluto  3. Mercury 4. Saturn

 

Answer of Quiz No 4 : 1

 

5. In which country can you find the Eiffel Tower?

 1. Germany  2. Italy  3. France  4. UK

 

Answer of Quiz No 5 : 2

 

6. How many days are there in a year?

 1.365  2. 366  3.May be 1 or 2  4. 360

 

Answer of Quiz No 6 : 2

 

7. How many players are in a soccer team?

 1. 16  2. 7  3.  11  4. 9

 

Answer of Quiz No 7 : 2

 

8. Where do polar bears live?

 1. The Arctic  2. Himalayan Range  3. Eastern Siberia  4. Alashka

 

Answer of Quiz No 8 : 1

 

9. Which is faster, light or sound?

 1. Light  2. Sound  3. Both

 

Answer of Quiz No 9 : 2

 

10. How many letters are in the English alphabet?

 1. 24  2.  28  3.  26  4. 30

 

Answer of Quiz No 10 : 1

 

11. What is the name of a shape with 5 sides?

 1.Hexagon 2. Pentagon  3. Square  4. Rhombus

 

Answer of Quiz No 11 : 2

 

12. How many Continents are there?

 1. 13  2.  6  3. 7  4.  8

 

Answer of Quiz No 12 : 1

 

13. What is the name of the tallest mountain on earth?

 1. Mount Everest  2. Makalu  3. Manaslu  4. K2

 

Answer of Quiz No 13 : 2

 

14. The planet Mars is also known as what?

 1. The Brown Planet  2. The Red Planet  3. The Yellow Planet  4. The Pink Planet

 

Answer of Quiz No 14 : 1

 

15. How many months have 31 days? 1. Six 2. Four  3. Seven 4. Nine

 

Answer of Quiz No 15 : 2

 

16. How many colors of the rainbow are there?

 1. Six  2. Seven  3. Five  4. Nine

 

Answer of Quiz No 16 : 1

 

17. My mother’s mother is my…what?

 1. Grandmother  2. Aunty  3. Big Mother  4. None of the above

 

Answer of Quiz No 17 : 2

 

18. Which animal lays the largest eggs?

 1. Emu  2. Ostrich  3. Kiwi  4. None of the above

 

Answer of Quiz No 18 : 1

 

19. How many zeros are in ten thousand?

 1. Four  2. Three  3. Five  4. None

 

Answer of Quiz No 19 : 2

 

20. In which country would you find the Sydney Opera House?

 1. Australia  2. New Zealand  3. Greece  3. Keniya

 

Answer of Quiz No 20 : 3

 

Taking answers from participant no 4

1. What is the orange part of an egg called?

1. Yolk 2. Shell 3. Round Vit 4. Solid Membrane

 

Answer of Quiz No 1 : 1

 

2. How many legs do insects have?

 1. 6  2. 4  3. 8 4. 10

 

Answer of Quiz No 2 : 2

 

3. What is a baby kangaroo called?

 1. Puppy  2. Joey  3. Cub  4. Kitten

 

Answer of Quiz No 3 : 3

 

4. What is the closest planet to the Sun?

 1. Mars  2. Pluto  3. Mercury 4. Saturn

 

Answer of Quiz No 4 : 2

1

2

5. In which country can you find the Eiffel Tower?

 1. Germany  2. Italy  3. France  4. UK

 

Answer of Quiz No 5 :

 

6. How many days are there in a year?

 1.365  2. 366  3.May be 1 or 2  4. 360

 

Answer of Quiz No 6 : 3

 

7. How many players are in a soccer team?

 1. 16  2. 7  3.  11  4. 9

 

Answer of Quiz No 7 : 2

 

8. Where do polar bears live?

 1. The Arctic  2. Himalayan Range  3. Eastern Siberia  4. Alashka

 

Answer of Quiz No 8 : 1

 

9. Which is faster, light or sound?

 1. Light  2. Sound  3. Both

 

Answer of Quiz No 9 : 2

 

10. How many letters are in the English alphabet?

 1. 24  2.  28  3.  26  4. 30

 

Answer of Quiz No 10 : 3

 

11. What is the name of a shape with 5 sides?

 1.Hexagon 2. Pentagon  3. Square  4. Rhombus

 

Answer of Quiz No 11 : 2

 

12. How many Continents are there?

 1. 13  2.  6  3. 7  4.  8

 

Answer of Quiz No 12 : 1

 

13. What is the name of the tallest mountain on earth?

 1. Mount Everest  2. Makalu  3. Manaslu  4. K2

 

Answer of Quiz No 13 : 2

 

14. The planet Mars is also known as what?

 1. The Brown Planet  2. The Red Planet  3. The Yellow Planet  4. The Pink Planet

 

Answer of Quiz No 14 : 3

 

15. How many months have 31 days? 1. Six 2. Four  3. Seven 4. Nine

 

Answer of Quiz No 15 : 2

 

16. How many colors of the rainbow are there?

 1. Six  2. Seven  3. Five  4. Nine

 

Answer of Quiz No 16 : 1

 

17. My mother’s mother is my…what?

 1. Grandmother  2. Aunty  3. Big Mother  4. None of the above

 

Answer of Quiz No 17 : 2

 

18. Which animal lays the largest eggs?

 1. Emu  2. Ostrich  3. Kiwi  4. None of the above

 

Answer of Quiz No 18 : 1

 

19. How many zeros are in ten thousand?

 1. Four  2. Three  3. Five  4. None

 

Answer of Quiz No 19 : 2

 

20. In which country would you find the Sydney Opera House?

 1. Australia  2. New Zealand  3. Greece  3. Keniya

 

Answer of Quiz No 20 : 2

 

Taking answers from participant no 5

 1. What is the orange part of an egg called?

 

1. Yolk 2. Shell 3. Round Vit 4. Solid Membrane

 

Answer of Quiz No 1 : 2

 

2. How many legs do insects have?

 1. 6  2. 4  3. 8 4. 10

 

Answer of Quiz No 2 : 2

 

3. What is a baby kangaroo called?

 1. Puppy  2. Joey  3. Cub  4. Kitten

 

Answer of Quiz No 3 : 2

 

4. What is the closest planet to the Sun?

 1. Mars  2. Pluto  3. Mercury 4. Saturn

 

Answer of Quiz No 4 : 2

 

5. In which country can you find the Eiffel Tower?

 1. Germany  2. Italy  3. France  4. UK

 

Answer of Quiz No 5 : 2

 

6. How many days are there in a year?

 1.365  2. 366  3.May be 1 or 2  4. 360

 

Answer of Quiz No 6 : 3

2

7. How many players are in a soccer team?

 1. 16  2. 7  3.  11  4. 9

 

Answer of Quiz No 7 :

 

8. Where do polar bears live?

 1. The Arctic  2. Himalayan Range  3. Eastern Siberia  4. Alashka

 

Answer of Quiz No 8 : 2

 

9. Which is faster, light or sound?

 1. Light  2. Sound  3. Both

 

Answer of Quiz No 9 : 2

 

10. How many letters are in the English alphabet?

 1. 24  2.  28  3.  26  4. 30

 

Answer of Quiz No 10 : 2

 

11. What is the name of a shape with 5 sides?

 1.Hexagon 2. Pentagon  3. Square  4. Rhombus

 

Answer of Quiz No 11 : 2

 

12. How many Continents are there?

 1. 13  2.  6  3. 7  4.  8

 

Answer of Quiz No 12 : 1

 

13. What is the name of the tallest mountain on earth?

 1. Mount Everest  2. Makalu  3. Manaslu  4. K2

 

Answer of Quiz No 13 : 1

 

14. The planet Mars is also known as what?

 1. The Brown Planet  2. The Red Planet  3. The Yellow Planet  4. The Pink Planet

 

Answer of Quiz No 14 : 1

 

15. How many months have 31 days? 1. Six 2. Four  3. Seven 4. Nine

 

Answer of Quiz No 15 : 1

 

16. How many colors of the rainbow are there?

 1. Six  2. Seven  3. Five  4. Nine

 

Answer of Quiz No 16 : 1

 

17. My mother’s mother is my…what?

 1. Grandmother  2. Aunty  3. Big Mother  4. None of the above

 

Answer of Quiz No 17 : 1

 

18. Which animal lays the largest eggs?

 1. Emu  2. Ostrich  3. Kiwi  4. None of the above

 

Answer of Quiz No 18 : 1

 

19. How many zeros are in ten thousand?

 1. Four  2. Three  3. Five  4. None

 

Answer of Quiz No 19 : 1

 

20. In which country would you find the Sydney Opera House?

 1. Australia  2. New Zealand  3. Greece  3. Keniya

 

Answer of Quiz No 20 : 1

 

SCORES :

        Participant No:1 = 6

        Participant No:2 = 6

        Participant No:3 = 3

        Participant No:4 = 4

        Participant No:5 = 6

 

Highest Score : 6

        Highest Scorers :

***Participant No 1

***Participant No 2

***Participant No 5


Back To 2017 ISC Practical Paper: Click Here

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner