Skip to content

apk #4491

@Arafatz7

Description

@Arafatz7

package com.wingo.ai;

import android.os.Bundle;
import android.os.Handler;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText input;
TextView output, timerView;
Button btn;

int wins=0, loss=0, balance=0;
int timer=30;

Handler handler = new Handler();
Runnable runnable;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    input = findViewById(R.id.input);
    output = findViewById(R.id.output);
    timerView = findViewById(R.id.timer);
    btn = findViewById(R.id.btn);

    btn.setOnClickListener(v -> runAI());

    startTimer();
}

void runAI(){
    String text = input.getText().toString();

    if(text.isEmpty()){
        Toast.makeText(this,"Enter number!",Toast.LENGTH_SHORT).show();
        return;
    }

    int num = Integer.parseInt(text);
    String size = num <= 4 ? "Small" : "Big";

    String pred = Math.random() > 0.5 ? "Big" : "Small";

    if(pred.equals(size)){
        wins++;
        balance++;
    }else{
        loss++;
        balance--;
    }

    output.setText(
            "Number: "+num+" ("+size+")\n"+
            "Prediction: "+pred+"\n"+
            "Wins: "+wins+"\n"+
            "Loss: "+loss+"\n"+
            "Balance: "+balance
    );
}

void startTimer(){
    runnable = new Runnable() {
        @Override
        public void run() {
            timer--;
            timerView.setText("Timer: "+timer);

            if(timer <= 0){
                timer = 30;
                Toast.makeText(MainActivity.this,"Enter Result!",Toast.LENGTH_SHORT).show();
            }

            handler.postDelayed(this,1000);
        }
    };
    handler.post(runnable);
}

}

<TextView
    android:id="@+id/timer"
    android:text="Timer: 30"
    android:textColor="#00ff00"
    android:textSize="24sp"
    android:layout_marginBottom="20dp"/>

<EditText
    android:id="@+id/input"
    android:hint="Enter 0-9"
    android:textColor="#ffffff"
    android:hintTextColor="#888"
    android:inputType="number"
    android:layout_marginBottom="10dp"/>

<Button
    android:id="@+id/btn"
    android:text="Run AI"
    android:layout_marginBottom="20dp"/>

<TextView
    android:id="@+id/output"
    android:text="Result will show here"
    android:textColor="#ffffff"/>

<application
    android:allowBackup="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

</application>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions