Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.test.brzoracunanje;
- import android.app.Activity;
- import android.os.Bundle;
- import android.text.Editable;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.os.CountDownTimer;
- public class BrzoRacunanjeActivity extends Activity implements OnClickListener {
- TextView broj1, op, broj2, poeni, tvRezultat, tvPreostaloVrijeme1,
- tvPreostaloVrijeme;
- Button start, posalji;
- int brojevi[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 25, 50, 100 };
- String operatori[] = { "+", "-", "/", "*" };
- EditText et1;
- int poenibrojanje = 0;
- int rez = 0;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- broj1 = (TextView) findViewById(R.id.textView1);
- op = (TextView) findViewById(R.id.textView2);
- broj2 = (TextView) findViewById(R.id.textView3);
- poeni = (TextView) findViewById(R.id.textView7);
- tvRezultat = (TextView) findViewById(R.id.textView4);
- tvPreostaloVrijeme1 = (TextView) findViewById(R.id.textView5);
- tvPreostaloVrijeme = (TextView) findViewById(R.id.textView6);
- start = (Button) findViewById(R.id.button2);
- posalji = (Button) findViewById(R.id.button1);
- start.setOnClickListener(this);
- posalji.setOnClickListener(this);
- }
- public void racunanje() {
- int a = Integer.parseInt((String) broj1.getText());
- int b = Integer.parseInt((String) broj2.getText());
- String c = op.getText().toString();
- if (c.equals("+")) {
- rez = a + b;
- } else if (c.equals("-"))
- rez = a - b;
- else if (c.equals("*"))
- rez = a * b;
- else if (c.equals("/"))
- rez = a / b;
- tvPreostaloVrijeme1.setText(Integer.toString(rez));
- }
- public void posaljiOdgovor() {
- //int x =Integer.parseInt(et1.getText().toString());
- String xS = et1.getText().toString();
- int x = Integer.parseInt(xS);
- if (x == rez) {
- tvPreostaloVrijeme.setText("Tacan odgovor +1!");
- poenibrojanje++;
- poeni.setText(poenibrojanje);
- } else
- tvPreostaloVrijeme.setText("Pogresan odgovor");
- }
- @Override
- public void onClick(View v) {
- // fali STOP dugme i klasa
- switch (v.getId()) {
- case R.id.button2:
- broj1.setText(Integer.toString(brojevi()));
- broj2.setText(Integer.toString(brojevi()));
- op.setText(operatori());
- racunanje();
- new CountDownTimer(30000, 1000) {
- public void onTick(long millisUntilFinished) {
- tvPreostaloVrijeme.setText(Integer
- .toString((int) (millisUntilFinished / 1000)));
- }
- public void onFinish() {
- tvPreostaloVrijeme.setText("Isteklo vrijeme...");
- broj1.setText("");
- broj2.setText("");
- op.setText("");
- }
- }.start();
- break;
- case R.id.button1:
- posaljiOdgovor();
- }
- }
- public int brojevi() {
- int i;
- i = (int) (Math.random() * brojevi.length);
- return brojevi[i];
- }
- public String operatori() {
- int i;
- i = (int) (Math.random() * operatori.length);
- return operatori[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement