0% found this document useful (0 votes)
17 views

Test 5

The document defines a Java class called QuestionsActivity that is used to display multiple choice quiz questions. It contains methods to display questions and answers, check the submitted answers, and navigate to a results page.

Uploaded by

moni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Test 5

The document defines a Java class called QuestionsActivity that is used to display multiple choice quiz questions. It contains methods to display questions and answers, check the submitted answers, and navigate to a results page.

Uploaded by

moni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package com.example.vikasojha.

quizbee;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class QuestionsActivity extends AppCompatActivity {


TextView tv;
Button submitbutton, quitbutton;
RadioGroup radio_g;
RadioButton rb1,rb2,rb3,rb4;

String questions[] = {
"L = ['a','b','c','d'] print "".join(L)",
"What is the output of the following segment :
chr(ord('A'))",
"y = 8 z = lambda x : x * y print z(6)",
"What is called when a function is defined inside a
class?",
"Which of the following is the use of id() function in
python?",
"time.time() returns ________",
"print 9//2",
"Which function overloads the >> operator?",
"Which operator is overloaded by the or() function?",
"What is the output of the following program :
i = 0
while i < 3:
print i
i++
print i+1"
};
String answers[] = {"abcd","A","48","Method","Id returns the identity of the
object","the current time in milliseconds since midnight, January 1, 1970 GMT (the
Unix time)","4","None of the above","|","Error"};
String opt[] = {
"a b c d","abcd","a b c d","error",
"A","65","97","a",
"86","68","error","48",
"Method","Class","tuple","None of the above",
"Every object doesn’t have a unique id","Id returns the
identity of the object","All of the mentioned","None of the mentioned",
"the current time in milliseconds since midnight, January 1,
1970 GMT (the Unix time)","the current time in milliseconds since midnight, January
1, 1970","the current time","the current time in milliseconds",
"4.0","4","4.5","error",
"more()","gt()","ge()","None of the above",
"\\","|","||","\",
"0 2 1 3 2 4","0 1 2 3 4 5","Error","1 0 2 4 3 5"
};
int flag=0;
public static int marks=0,correct=0,wrong=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_questions);

final TextView score = (TextView)findViewById(R.id.textView4);


TextView textView=(TextView)findViewById(R.id.DispName);
Intent intent = getIntent();
String name= intent.getStringExtra("myname");

if (name.trim().equals(""))
textView.setText("Hello User");
else
textView.setText("Hello " + name);

submitbutton=(Button)findViewById(R.id.button3);
quitbutton=(Button)findViewById(R.id.buttonquit);
tv=(TextView) findViewById(R.id.tvque);

radio_g=(RadioGroup)findViewById(R.id.answersgrp);
rb1=(RadioButton)findViewById(R.id.radioButton);
rb2=(RadioButton)findViewById(R.id.radioButton2);
rb3=(RadioButton)findViewById(R.id.radioButton3);
rb4=(RadioButton)findViewById(R.id.radioButton4);
tv.setText(questions[flag]);
rb1.setText(opt[0]);
rb2.setText(opt[1]);
rb3.setText(opt[2]);
rb4.setText(opt[3]);
submitbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//int color = mBackgroundColor.getColor();
//mLayout.setBackgroundColor(color);

if(radio_g.getCheckedRadioButtonId()==-1)
{
Toast.makeText(getApplicationContext(), "Please select one
choice", Toast.LENGTH_SHORT).show();
return;
}
RadioButton uans = (RadioButton)
findViewById(radio_g.getCheckedRadioButtonId());
String ansText = uans.getText().toString();
// Toast.makeText(getApplicationContext(), ansText,
Toast.LENGTH_SHORT).show();
if(ansText.equals(answers[flag])) {
correct++;
Toast.makeText(getApplicationContext(), "Correct",
Toast.LENGTH_SHORT).show();
}
else {
wrong++;
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
}
flag++;

if (score != null)
score.setText(""+correct);

if(flag<questions.length)
{
tv.setText(questions[flag]);
rb1.setText(opt[flag*4]);
rb2.setText(opt[flag*4 +1]);
rb3.setText(opt[flag*4 +2]);
rb4.setText(opt[flag*4 +3]);
}
else
{
marks=correct;
Intent in = new
Intent(getApplicationContext(),ResultActivity.class);
startActivity(in);
}
radio_g.clearCheck();
}
});

quitbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new
Intent(getApplicationContext(),ResultActivity.class);
startActivity(intent);
}
});
}

You might also like