You are on page 1of 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[] = {
"A can do a piece of work in 4 hours; B and C together
can do it in 3 hours, while A and C together can do it in 2 hours. How long will B
alone take to do it? ",
"A, B, and C can do a piece of work in 8 days. B and C
together do it in 24 days. B alone can do it in 40 days. In what time will it be
done by C working alone? ",
"Kamal can do a work in 15 days. Bimal is half more
proficient than kamala. The no. of days, Bimal will take to do likewise bit of
work, is ",
"Radhe does 70% of some work in 15 days. Later, with
Shyam’s help, she completes the remaining work in 4 days. In how many days can
Shyam alone complete the entire work?",
" A and B working separately can do a piece of work in
9 and 12 days respectively. If they work a day alternately. A beginning, in how
many days the work will be completed?",
" A and B can do a piece of work in 12 days and 16 days
respectively. Both work for 3 days and then A goes away. Find how long will B take
to complete the remaining work?",
"A takes twice as much time as B or thrice as much time
as C to finish a piece of work; working together they can finish the work in 2
days. B can do the work alone in",
"Sumit can do a work in 6 days while Deepak can do the
same work in 4 days. Both of them finish the work together and get Rs. 300. What is
the share of Sumit?",
"5 identical kilns can produce a total of 300 bricks
per minute by running at a constant rate.How many bricks could 10 such kilns
produce in 5 minutes?",
"P can do a piece of work in 16 days. P undertook to do
it for Rs. 400. With the help of Q, he finishes the work in 12 days. P’s share is"
};
String answers[] = {"12 hrs","60 days","10 days","35.3","41/4 days","9 days","6
days","120","3000","125"};
String opt[] = {
"5 hrs","10 hrs","12 hrs","20 hrs",
"50 days","60 days","70 days","80 days",
"10 days","55 days","65 days","60 days",
"33","33.5","34","34.5",
"46/4 days","47/4 days","41/4 days","50/4 days",
"9 days","10 days","11 days","15 days",
"6 days","8 days","8 days","9 days",
"120","150","170","13",
"1100 ","1500","3000","1200",
"125","150","250","300"
};
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