Test 5
Test 5
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;
String questions[] = {
"A, B and C can do a piece of work in 20, 30 and 60
days respectively. In how many days can A do the work if he is assisted by B and C
on every third day? ",
"A and B can do a piece of work in 4 days, while C and
D can do the same work in 12 days. In how many days will A, B, C and D do it
together? ",
"A can do a bit of work in 25 days which B can complete
in 20 days. Both together labor for 5 days and afterward A leaves off. How long
will B take to complete the remaining work? ",
" A contractor hire Amitabh Arora to complete the work
and Amitabh can do the work in 25 days. Amitabh worked for 5 days and after that
Bindu singh completed it in 20 days. In how many days will Amitabh and Bindu
together finish the work?",
"45 men can complete a work in 16 days, 6 days after
they started working. 30 more men join them. How many days will they now take to
complete the remaining work?",
"A can do a piece of work in 4 days. B can do it in 5
days. With the assistance of C they completed the work in 2 days. Find in how many
days can C alone do it?",
"If Ram and Shyam together can build a house in 10
days; Ram and Arun can build it together in 12 days and Shyam and Arun can build it
in 15 days. Shyam, Ram and Arun start working together. In how many days they build
the house?",
"A tank is filled by a pipe A in 20 min. and pipe B in
30 min. When filled, it can be emptied by pipe C in 10 minute. If all the three
pipes are opened simultaneously, 2/3rd of tank will be filled in",
"Twelve men can complete a work in 8 days. Three days
after they stated the work, 3 more men joined them. In how many days will all of
them together complete the remaining work?",
"Ram, who is half as efficient as Krish, will take 24
days to complete a task if he worked alone. If Ram and Krish worked together, how
long will they take to complete the task?"
};
String answers[] = {"15 days","3 days","11 days","12.5 days","6 days","20
days","8 days","10 min","4 days","8 days"};
String opt[] = {
"5 days","10 days","15 days","20 days",
"5 days","3 days","7 days","8 days",
"11 days","55 days","65 days","60 days",
"10 days","11 days","12.5 days","14 days",
"6 days","7 days","9 days","5 days",
"10 days","20 days","34 days","35 days",
"7 days","8 days","10 days","9 days",
"2 min","6 min","12 min","10 min",
"4 days","15 days","17 days","13 days",
"8 days","15 days","25 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);
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);
}
});
}