Showing posts with label area of the circle solver in android. Show all posts
Showing posts with label area of the circle solver in android. Show all posts

Thursday, December 21, 2017

Area of the Circle Solver in Android

I wrote this program to continue my study on Android programming it is not an easy task for me but I have learned many things in doing this simple program. What does the program will do is to ask the user to give the radius of the circle and then our program will compute it's area equivalent. The code is very simple and easy to understand.

 I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.





Sample Program Output


Program Listing


content_main.xml

<?xml version="1.0" encoding="utf-8"?><android.support.constraint.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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.jacob.areaofthecirclesolver.MainActivity"
    tools:showIn="@layout/activity_main">

    <RelativeLayout
        android:layout_width="389dp"
        android:layout_height="515dp"
        android:background="@android:color/background_light"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:layout_marginEnd="60dp"
            android:layout_marginTop="33dp"
            android:text="Area of the Circle Solver"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/textView"
            android:layout_below="@+id/textView"
            android:layout_marginEnd="84dp"
            android:layout_marginTop="12dp"
            android:text="Created By"
            android:textAppearance="@style/TextAppearance.AppCompat.Body2" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/textView"
            android:layout_below="@+id/textView2"
            android:layout_marginEnd="15dp"
            android:layout_marginTop="11dp"
            android:text="Mr. Jake R. Pomperada, MAED-IT"
            android:textAppearance="@style/TextAppearance.AppCompat.Body2"
            android:tooltipText="Authoer of the Program" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView3"
            android:layout_marginTop="36dp"
            android:layout_toStartOf="@+id/editText"
            android:text="Give the radius :"
            android:textAppearance="@style/TextAppearance.AppCompat.Large" />

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView4"
            android:layout_alignStart="@+id/textView2"
            android:layout_marginStart="12dp"
            android:ems="10"
            android:inputType="textPersonName"
            android:textAppearance="@style/TextAppearance.AppCompat.Large" />

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/textView4"
            android:layout_below="@+id/textView4"
            android:layout_marginTop="53dp"
            android:onClick="solve_area"
            android:text="Calculate"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            android:tooltipText="Click here to solve."
            tools:ignore="HardcodedText,OnClick" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/button"
            android:layout_alignBottom="@+id/button"
            android:layout_alignEnd="@+id/textView3"
            android:layout_marginEnd="14dp"
            android:onClick="clear_textbox"
            android:text="Clear"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

    </RelativeLayout>
</android.support.constraint.ConstraintLayout>


MainActivity.java

package com.example.jacob.areaofthecirclesolver;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    public void solve_area(View view) {
        EditText editText = (EditText) findViewById(R.id.editText);

        int value_area = Integer.valueOf(editText.getText().toString());

       double area_solve = java.lang.Math.PI*value_area*value_area;

        String str = String.format("%5.2f", area_solve);
        double display_result = Double.valueOf(str);

       Toast.makeText(this,"The area of the circle is " + String.valueOf(display_result)+".", Toast.LENGTH_SHORT).show();
    }


    public void clear_textbox(View view) {
        EditText editText = (EditText) findViewById(R.id.editText);
        editText.setText("");
        editText.requestFocus();

    }
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button, so long        // as you specify a parent activity in AndroidManifest.xml.        int id = item.getItemId();

        //noinspection SimplifiableIfStatement        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}


strings.xml

<resources>
    <string name="app_name">Area of the Circle Solver</string>
    <string name="action_settings">Settings</string>
</resources>