GithubHelp home page GithubHelp logo

sumofgiven3numbers's Introduction

sumofgiven3numbers

xml file-

<EditText
    android:id="@+id/number1EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Enter number 1" />

<EditText
    android:id="@+id/number2EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/number1EditText"
    android:layout_marginTop="16dp"
    android:hint="Enter number 2" />

<EditText
    android:id="@+id/number3EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/number2EditText"
    android:layout_marginTop="16dp"
    android:hint="Enter number 3" />

<Button
    android:id="@+id/calculateButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/number3EditText"
    android:layout_marginTop="16dp"
    android:text="Calculate" />

<TextView
    android:id="@+id/resultTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/calculateButton"
    android:layout_marginTop="16dp"
    android:textSize="18sp"
    android:text="The sum of the three numbers will be displayed here." />

java file- package com.example.sumofgiven3numbers;

import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private EditText number1EditText;
private EditText number2EditText;
private EditText number3EditText;
private Button calculateButton;
private TextView resultTextView;

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

    number1EditText = findViewById(R.id.number1EditText);
    number2EditText = findViewById(R.id.number2EditText);
    number3EditText = findViewById(R.id.number3EditText);
    calculateButton = findViewById(R.id.calculateButton);
    resultTextView = findViewById(R.id.resultTextView);

    calculateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String number1String = number1EditText.getText().toString();
            String number2String = number2EditText.getText().toString();
            String number3String = number3EditText.getText().toString();

            if (number1String.isEmpty() || number2String.isEmpty() || number3String.isEmpty()) {
                resultTextView.setText("Please enter all three numbers.");
                return;
            }

            double number1 = Double.parseDouble(number1String);
            double number2 = Double.parseDouble(number2String);
            double number3 = Double.parseDouble(number3String);
            double sum = number1 + number2 + number3;

            resultTextView.setText("The sum of the three numbers is: " + sum);
        }
    });
}

}

sumofgiven3numbers's People

Contributors

mjshoaib avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.