You are on page 1of 3

EXP.

NO:2 BUILD A SCORE KEEPER APP THAT GIVES A USER THE ABILITY TO
KEEP TRACK OF THE SCORE OF TWO DIFFERENT TEAMS PLAYING
A GAME OF CHOICE. INCLUDE DIFFERENT BUTTONS WHICH CAN BE
CLICKED FOR DIFFERENT EVENTS IN THE GAME TO ADD POINTS.
AIM:
To develop a score keeper app that gives the score of two different teams playing a games.

PROCEDURE:
STEP 1:- Open eclipse or android studio and select new android project .
STEP 2:-Give application name,select blank activity and design application icon.
SETP 3:-Create view layout for user interface.
SETP 4:-Write a java function for view layout widgets.
SETP 5:-Execute the android application.
SETP 6:-Use android emulator to show the created application.

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity_result">
<TextView
android:id="@+id/result_TeamA"
android:layout_width="182dp"
android:layout_height="70dp"/>
<TextView
android:id="@+id/result_TeamB"
android:layout_width="182dp"
android:layout_height="70dp"
android:layout_marginStart="16dp"/>
<TextView
android:id="@+id/result_TeamAscore"
android:layout_width="151dp"
android:layout_height="61dp"/>
<TextView
android:id="@+id/result_TeamBscore"
android:layout_width="150dp"
android:layout_height="72dp"/>
<TextView
android:id="@+id/result_ResultString"
android:layout_width="match_parent"
android:layout_height="153dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

Main Activity.java
package com.example.scoreboard;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private TextView score1;
private TextView score2;
private int s1=0,s2=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextViewToNumber();
addListenerOnButton();
Reset();
}
private void Reset() {
Button reset=findViewById(R.id.reset_button);
reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
s1=0;
s2=0;
score1.setText(String.valueOf(s1));
score2.setText(String.valueOf(s2));
}
});
}
private void TextViewToNumber() {
score1= findViewById(R.id.Score1);
score2= findViewById((R.id.score2));
s1=Integer.parseInt(score1.getText().toString());
s2 = Integer.parseInt(score2.getText().toString());
}
public void CallResultActivity()
{
Intent intent=new Intent(this,activity_result.class);
intent.putExtra("Ascore",s1);
intent.putExtra("Bscore",s2);
startActivity(intent);
}
private void addListenerOnButton() {
Button button1= findViewById(R.id.button1);
Button button2= findViewById(R.id.button2);
Button result_button= findViewById(R.id.button_result);
button1.setOnClickListener(view -> {
s1 = s1 + 1;
score1.setText(String.valueOf(s1));
});
button2.setOnClickListener(view -> {
s2 = s2 + 1;
score2.setText(String.valueOf(s2));
});
//result_button.setOnClickListener(view -> CallResultActivity());
result_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CallResultActivity();
} }); } }
OUTPUT:-

RESULT:-
These the score keeper app has been build and execute successfully.

You might also like