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 certain work in the same time in which B
and C together can do it. If A and B together could do it in 10 days and C alone in
50 days, then B alone could do it in: ",
"A and B undertake to do a piece of work for Rs. 450. A
can do it in 20 days and B can do it in 40 days. With the help of C, they finish it
in 8 days. How much should C be paid for his contribution? ",
"A and B can do a bit of work in 12 days. B and C can
do it in 15 days and C and A can do it in 20 days. An alone can take every
necessary step in: ",
"The hourly wages of a mason have increased by 25%.
Since the increase, the number of hours he works daily has reduced by 16%. If he
was earning Rs. 120 per day before the increase, how much (in Rs.) is he earning
now?",
"A father can do a job as fast as his two sons working
together. If one son does the job in 3 hours and the other in 6 hours, how many
hours does it take the father to do the job?",
" A and B can do a piece of work in 3 days, B and C in
4 days, C and A in 6 days. How long will C take to do it?",
"A can do a piece of work in 10 days. He works at it
for 4 days and then B finishes it in 9 days. In how many days can A and B together
finish the work?",
"A can do 1/4th part of work in 10 days and B can do
40% work in 40 days and C can do 1/3rd of the work in 13 days. Who will complete
the work first?",
"A can finish a job in 15 days and B can do the same
work in 18 days. A worked for 10 days and left the job. In how many days, B alone
can finish the remaining work?",
"X is thrice as good a workman as Y and therefore is
able to finish a job in 60 days less than Y. What is the time taken to do twice the
work when they are working together ?"
};
String answers[] = {"25 days","180","30 days","126","2","24 days","6
days","C","6 days","45 days"};
String opt[] = {
"5 days","10 days","15 days","25 days",
"560","180","130","820",
"50 days","55 days","65 days","30 days",
"126","110","120","140",
"4","7 ","2","5",
"11 days","24 days","34 days","35 days",
"7 days","8 days","6 days","9 days",
"A","B","C","not given",
"11 days","15 days","17 days","6 days",
"15 days","45 days","75 days","30 days"
};
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