Selasa, 15 Agustus 2017

Soal Angka

package com.example.app_tpa;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;

import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class soal_angka extends Activity {
String sNama="Fulan",sUsia="xx",sJK="Laki-laki",sCatatan="";
 long starttime = 0;
   Timer timer = new Timer();
int jd=0;
String[]arTanya;
String[]arA;
String[]arB;
String[]arC;
String[]arD;
String[]arE;
String[]arBenar;
int ke=0;
int jumbenar=0;
String record="";

TextView txtTanya,txtTanyaKe,txtTimer;
RadioButton radA,radB,radC,radD,radE;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soal_angka);
  Intent i = this.getIntent();
       sNama=i.getStringExtra("nama");
       sUsia=i.getStringExtra("usia");
       sJK=i.getStringExtra("jk");
     
callSoal();

txtTanya=(TextView)findViewById(R.id.txtTanya);
txtTanyaKe=(TextView)findViewById(R.id.txtTanyaKe);
txtTimer=(TextView)findViewById(R.id.txtTimer);

radA=(RadioButton)findViewById(R.id.radA);
radA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih A",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda A: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda A: Salah\n";}

ke=ke+1;
lihat();
}});  
radB=(RadioButton)findViewById(R.id.radB);
radB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih B",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda B: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda B: Salah\n";}

ke=ke+1;
lihat();
}});  
radC=(RadioButton)findViewById(R.id.radC);
radC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih C",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda C: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda C: Salah\n";}

ke=ke+1;
lihat();
}});  
radD=(RadioButton)findViewById(R.id.radD);
radD.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih D",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda D: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda D: Salah\n";}

ke=ke+1;
lihat();
}});  
radE=(RadioButton)findViewById(R.id.radE);
radE.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih E",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda E: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda E: Salah\n";}

ke=ke+1;
lihat();
}});  
lihat();
final Handler h = new Handler(new Callback() {
       @Override
       public boolean handleMessage(Message msg) {
          long millis = System.currentTimeMillis() - starttime;
          int seconds = (int) (millis / 1000);
          int minutes = seconds / 60;
          seconds     = seconds % 60;
          if (minutes >=0 && seconds >=20){selesai();}
         
           txtTimer.setText(String.format("Waktu Anda ini :"+"%d:%02d"+" (max=> 3:20)", minutes, seconds));
           return false;
       }
   });
  class firstTask extends TimerTask {
       @Override
       public void run() {
           h.sendEmptyMessage(0);
       }
  };
  starttime = System.currentTimeMillis();
               timer.schedule(new firstTask(), 0,1000);
}
    public void selesai(){
    new AlertDialog.Builder(this)
.setTitle("Selesai Angka")
.setMessage("Terimakasih... Anda Telah Melakukan tes TPA Angka")
.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
  timer.cancel();
              timer.purge();
Intent  i= new Intent(soal_angka.this, hasil.class);
i.putExtra("nama", sNama);
i.putExtra("usia", sUsia);
i.putExtra("jk", sJK);
i.putExtra("record", record);
i.putExtra("kategori", "Tes Angka");
i.putExtra("jumbenar", String.valueOf(jumbenar));
startActivity(i);
}})
.show();
    }
   
void lihat(){
if(ke>=jd){selesai();}
else{
txtTanya.setText("   No."+(ke+1)+"    "+arTanya[ke]);
radA.setText(arA[ke]);
radB.setText(arB[ke]);
radC.setText(arC[ke]);
radD.setText(arD[ke]);
radE.setText(arE[ke]);
txtTanyaKe.setText("    Pertanyaan ke "+(ke+1)+" dari "+jd +" pertanyaan ");
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

void callSoal(){
jd=20;
arTanya=new String[jd];
arA=new String[jd];
arB=new String[jd];
arC=new String[jd];
arD=new String[jd];
arE=new String[jd];
arBenar=new String[jd];

arTanya[0]="19 adalah berapa persennya dari 380 ?";
arA[0]="0,5%";
arB[0]="5%";
arC[0]="0,05%";
arD[0]="0,15%";
arE[0]="5,5%";
arBenar[0]="B";

arTanya[1]="8,0049 : 0,0015";
arA[1]="5336,6";
arB[1]="533,66";
arC[1]="53,366";
arD[1]="53366";
arE[1]="533,55";
arBenar[1]="A";

arTanya[2]="0,012 : 3";
arA[2]="0,04";
arB[2]="0,0004";
arC[2]="0,4";
arD[2]="0,040";
arE[2]="0,0040";
arBenar[2]="E";

arTanya[3]="Seri Angka : 75 97 60 92 45 selanjutnya ....";
arA[3]="87";
arB[3]="78";
arC[3]="102";
arD[3]="75";
arE[3]="54";
arBenar[3]="E";

arTanya[4]="32/9 : 0,75";
arA[4]="6/16";
arB[4]="3";
arC[4]="3,5";
arD[4]="29";
arE[4]="16/6";
arBenar[4]="";

arTanya[5]="0,875 : 5/2";
arA[5]="0,35";
arB[5]="0,55";
arC[5]="0,53";
arD[5]="0,25";
arE[5]="2,65";
arBenar[5]="";

arTanya[6]="0,31 x 0,31";
arA[6]="0,0691";
arB[6]="0,0661";
arC[6]="0,0991";
arD[6]="0,0971";
arE[6]="0,0961";
arBenar[6]="";

arTanya[7]="3/8 dari 40% adalah ?";
arA[7]="0,15";
arB[7]="0,11";
arC[7]="16%";
arD[7]="15,5%";
arE[7]="0,13";
arBenar[7]="";

arTanya[8]="54 adalah 27% dari ?";
arA[8]="190";
arB[8]="210";
arC[8]="200";
arD[8]="300";
arE[8]="127";
arBenar[8]="";

arTanya[9]="2,00486 x 0,5";
arA[9]="1,000243";
arB[9]="1,00243";
arC[9]="1,0243";
arD[9]="1,00234";
arE[9]="1,00253";
arBenar[9]="";

arTanya[10]="Seri angka 75 97 60 92 45 selanjutnya ";
arA[10]="87";
arB[10]="78";
arC[10]="102";
arD[10]="75";
arE[10]="54";
arBenar[10]="";

arTanya[11]="Seri angka 17 21 23 27 selanjutnya ";
arA[11]="31";
arB[11]="33";
arC[11]="32";
arD[11]="29";
arE[11]="25";
arBenar[11]="";

arTanya[12]="Seri angka 1 5 9 2 6 10 3 selanjutnya ";
arA[12]="6-11-4";
arB[12]="7-11-4";
arC[12]="7-12-5";
arD[12]="6-12-3";
arE[12]="8-11-5";
arBenar[12]="";

arTanya[13]="Seri angka -4 -3 0 5 12 selanjutnya ";
arA[13]="21";
arB[13]="19";
arC[13]="17";
arD[13]="15";
arE[13]="23";
arBenar[13]="";

arTanya[14]="Seri angka 22 26 23 27 24 selanjutnya ";
arA[14]="26";
arB[14]="27";
arC[14]="28";
arD[14]="31";
arE[14]="22";
arBenar[14]="";

arTanya[15]="Seri angka 3 8 15 20 27 selanjutnya ";
arA[15]="30";
arB[15]="33";
arC[15]="35";
arD[15]="34";
arE[15]="32";
arBenar[15]="";

arTanya[16]="Seri huruf e h a j m b selanjutnya ";
arA[16]="p s";
arB[16]="p t";
arC[16]="o q";
arD[16]="o r";
arE[16]="o s";
arBenar[16]="";

arTanya[17]="Seri huruf z v r selanjutnya ";
arA[17]="m";
arB[17]="o";
arC[17]="t";
arD[17]="l";
arE[17]="n";
arBenar[17]="";

arTanya[18]="Seri huruf a c f j o selanjutnya ";
arA[18]="p";
arB[18]="t";
arC[18]="v";
arD[18]="u";
arE[18]="z";
arBenar[18]="";

arTanya[19]="Seri huruf c i o selanjutnya ";
arA[19]="t";
arB[19]="v";
arC[19]="u";
arD[19]="w";
arE[19]="h";
arBenar[19]="";


}
}
+++++++++++++++++++
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    
<ScrollView
    android:layout_marginBottom="50dip" 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#999999"
>

<TableLayout android:id="@+id/TableLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#fff">

<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
    
<TextView
android:id="@+id/txtMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp"
android:layout_x="3px"
android:layout_y="4px"
android:typeface="sans"
android:textColor="#0000ff"
android:background="#000000"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever">
</TextView>
</TableRow>  

<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
    <ImageView 
   android:id="@+id/myGambar" android:layout_centerHorizontal="true"
   android:src="@drawable/user"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   />
</TableRow>
    
<TableRow android:id="@+id/TableRow00" android:layout_width="wrap_content" android:layout_height="wrap_content">
      <TextView
        android:id="@+id/txtTanya"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1.Apakah Anda mengalami gejala Pusing2" />
</TableRow>    


<RadioGroup 
android:id="@+id/RadioGroup01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
<RadioButton android:text="A. Pilihan A" 
android:id="@+id/radA" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textColor="#000">
</RadioButton>
<RadioButton android:text="B. Pilihan B" 
android:id="@+id/radB" 
android:layout_width="wrap_content" 
android:textColor="#000" 
android:layout_height="wrap_content">
</RadioButton>
<RadioButton android:text="C. Pilihan C" 
android:id="@+id/radC" 
android:layout_width="wrap_content" 
android:textColor="#000" 
android:layout_height="wrap_content">
</RadioButton>
<RadioButton android:text="D. Pilihan D" 
android:id="@+id/radD" 
android:layout_width="wrap_content" 
android:textColor="#000" 
android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>

<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
      <TextView
        android:id="@+id/txtTanyaKe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pertanyaan ke-1" />
</TableRow>    

</TableLayout>
</ScrollView>
</RelativeLayout>



Tidak ada komentar:

Posting Komentar