Question

In: Computer Science

Create a Scorekeeper app in android studio by using java language - Layouts | Widgets Create...

Create a Scorekeeper app in android studio by using java language

- Layouts | Widgets

  • Create the layout for your score keeping app. The app should have:
    • Two team names (TextViews)
    • Two scores (TextViews)
    • Buttons to increase/ decrease the scores
    • An amount to change the score by (RadioButtons)
      • You must have at least two score options
      • The scores can be changed by anything you want
        • American football: 1, 2, 3, 6
        • Basketball: 1, 2, 3
        • Freestyle wrestling: 1, 2, 3, 4, 5
        • Your own game that you make up your own scores: 1, 50, 99
    • Anything else you think is important to include
    • All 4 buttons change the score (2)
    • RadioButtons allow for different types of scoring (3)

Solutions

Expert Solution

CODE:

MainActivity.java

package com.akshansh.score;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, View.OnClickListener {
    private TextView teamScoreRedTextView;
    private TextView teamScoreBlueTextView;

    private int incrementBy;
    private int teamRedScore;
    private int teamBlueScore;

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

        teamRedScore = 0;
        teamBlueScore = 0;

        //finding all the views by ids, refer to the xml page for the ids,
        //the names are self explanatory
        RadioGroup radioGroup = findViewById(R.id.radio_group);

        teamScoreRedTextView = findViewById(R.id.team_score_red);
        teamScoreBlueTextView = findViewById(R.id.team_score_blue);

        teamScoreBlueTextView.setText(Integer.toString(teamBlueScore));
        teamScoreRedTextView.setText(Integer.toString(teamRedScore));

        Button upButtonRed = findViewById(R.id.buttonUp_red);
        Button downButtonRed = findViewById(R.id.buttonDown_red);
        Button upButtonBlue = findViewById(R.id.buttonUp_blue);
        Button downButtonBlue = findViewById(R.id.buttonDown_blue);

        //setting onClickListeners for these vie
        radioGroup.setOnCheckedChangeListener(this);
        upButtonRed.setOnClickListener(this);
        downButtonRed.setOnClickListener(this);
        upButtonBlue.setOnClickListener(this);
        downButtonBlue.setOnClickListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        //selecting the increment value using the radio button
        switch (i){
            case 1:
                incrementBy = 1;
                break;
            case 2:
                incrementBy = 2;
                break;
            case 3:
                incrementBy = 3;
                break;
        }
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        //according to the buttons clicked the respective functions are performed
        switch (id){
            case R.id.buttonUp_blue:
                teamBlueScore += incrementBy;
                teamScoreBlueTextView.setText(Integer.toString(teamBlueScore));
                break;
            case R.id.buttonDown_blue:
                teamBlueScore -= incrementBy;
                teamScoreBlueTextView.setText(Integer.toString(teamBlueScore));
                break;
            case R.id.buttonUp_red:
                teamRedScore += incrementBy;
                teamScoreRedTextView.setText(Integer.toString(teamRedScore));
                break;
            case R.id.buttonDown_red:
                teamRedScore -= incrementBy;
                teamScoreRedTextView.setText(Integer.toString(teamRedScore));
                break;
        }
    }
}

_____________________________________________

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=".MainActivity">
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Team Red"
        android:textSize="20sp"
        android:textColor="#EC0519"
        android:textStyle="bold"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Team Blue"
        android:textStyle="bold"
        android:textSize="20sp"
        android:textColor="#065FF4"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/team_score_red"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:text="0"
        android:textColor="#000000"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="@+id/textView2"
        app:layout_constraintStart_toStartOf="@+id/textView2"
        app:layout_constraintTop_toBottomOf="@+id/textView2" />
    <TextView
        android:id="@+id/team_score_blue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:text="0"
        android:textColor="#000000"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="@+id/textView"
        app:layout_constraintStart_toStartOf="@+id/textView"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <Button
        android:id="@+id/buttonUp_red"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="64dp"
        android:layout_marginStart="16dp"
        android:background="#EC0519"
        android:text="Up"
        android:textColor="#fff"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/team_score_red" />
    <Button
        android:id="@+id/buttonUp_blue"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:background="#065FF4"
        android:textColor="#fff"
        android:text="Up"
        android:layout_marginTop="64dp"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/team_score_blue" />

    <Button
        android:id="@+id/buttonDown_red"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:background="#EC0519"
        android:text="Down"
        android:textColor="#fff"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="@+id/buttonUp_red"
        app:layout_constraintStart_toStartOf="@+id/buttonUp_red"
        app:layout_constraintTop_toBottomOf="@+id/buttonUp_red" />
    <Button
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:text="Down"
        android:id="@+id/buttonDown_blue"
        android:background="#065FF4"
        android:textColor="#fff"
        android:textSize="20sp"
        android:layout_marginTop="16dp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="@+id/buttonUp_blue"
        app:layout_constraintStart_toStartOf="@+id/buttonUp_blue"
        app:layout_constraintTop_toBottomOf="@+id/buttonUp_blue" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="64dp"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonDown_red">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Points increase by: "
            android:textColor="#000000"
            android:textSize="16sp"
            android:textStyle="bold" />

        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/radio_group"
            android:orientation="horizontal">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1"
                android:textColor="#000000"
                android:textSize="16sp"
                android:textStyle="bold" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2"
                android:textColor="#000000"
                android:textSize="16sp"
                android:textStyle="bold" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="3"
                android:textColor="#000000"
                android:textSize="16sp"
                android:textStyle="bold" />
        </RadioGroup>
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

_____________________________________________

APP SCREENSHOT:

___________________________________________________

Feel free to ask any questions in the comments section
Thank You!


Related Solutions

android studio Begin a new app and create a Java class for products with data: productName,...
android studio Begin a new app and create a Java class for products with data: productName, productCode and price and use a file of objects to store product data and read back and display on screen. Do this by creating a simple form using EditTexts, buttons or ActionBar items and display output using an Alert.
Hi! I need it in android studio and in java Design a game app “BouncingBall ”...
Hi! I need it in android studio and in java Design a game app “BouncingBall ” in which the user’s goal is to prevent a bouncing ball from falling off the bottom of the screen. When the user presses the start button, a ball bounces off the top, left and right sides (the “walls”) of the screen. A horizontal bar on the bottom of the screen serves as a paddle to prevent the ball from hitting the bottom of the...
Hi! I need it in android studio and in java Design a game app “BouncingBall ”...
Hi! I need it in android studio and in java Design a game app “BouncingBall ” in which the user’s goal is to prevent a bouncing ball from falling off the bottom of the screen. When the user presses the start button, a ball bounces off the top, left and right sides (the “walls”) of the screen. A horizontal bar on the bottom of the screen serves as a paddle to prevent the ball from hitting the bottom of the...
use android studio or MIT inventor Create a Presidents Quiz App for your project with the...
use android studio or MIT inventor Create a Presidents Quiz App for your project with the following requirements: You must have images Buttons Label Conditional Statement Homepage with instructions Sound (music, buzzer, etc.) - Ensure you are using the correct layout: Gravity(Android Studio), Horizontal or Vertical Arrangement (MIT). - 40POINTS Points System (indicating how many answers they got wrong/correct). 20POINT 1-2 questions per President (45+ questions)
I am doing a 4 function calculator app in java on android studio which calculates math...
I am doing a 4 function calculator app in java on android studio which calculates math expressions (add, subtract, multiply, and divide). I ONLY NEED THE CODE THE EQUAL BUTTON. When the user clicks the equal button, it should take the entire sequence of numbers and operators on the screen, such as 1+2*5 , and save them into a String [I am pretty sure this can be done using the toString() call]. Then, the String should be split using StringTokenizer,...
Android Studio. Java. Please create an application that -> An activity that allows user to enter...
Android Studio. Java. Please create an application that -> An activity that allows user to enter name, gender, date of birth, state of residence (selected from a pre-defined list: CA, AZ, NV, OR), email address and favorite website. This activity has a button "Show Data" that displays detail entered
Android Studio Code: Provide a working android studio code i.e java and xml code for the...
Android Studio Code: Provide a working android studio code i.e java and xml code for the activity below: Develop an application that is capable to turn pages back and forth. Detailed Instructions: For the main activity, create a layout that represents a fictitious title and author. The activity should include a clickable button on the bottom right that allows you to go forward to the next activity. The next activity will simply be an image above simple text that can...
Android Programming Create an app called GuessWho. The point of the app will to have the...
Android Programming Create an app called GuessWho. The point of the app will to have the user play a guessing game based on a displayed image. The user will be greeted with a screen that has an image of a person, four buttons and a next button. The four buttons should each have a different name on it. One of the names will be the actual name of the person in the image. Your guess who quiz should consist of...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called DataBaseManager as in Lecture 5 and create a database table in SQLite, called StudentInfo. The fields for the StudentInfo table include StudentID, FirstName, LastName, YearOfBirth and Gender. Include functions for adding a row to the table and for retrieving all rows, similar to that shown in lecture 5. No user interface is required for this question, t -Continuing from , follow the example in...
Create a mobile application using Android studio, for cinema tickets reservation. The application will be used...
Create a mobile application using Android studio, for cinema tickets reservation. The application will be used by the customers to book cinema tickets. Only users of 15 years old and above are allowed to book cinema tickets for a particular film. The user can book more than one ticket where ticket prices vary between 20 and 50 AED. Your app contains tree Activities. The first activity is a launching activity containing a logo and a button start. When the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT