Thursday, 4 August 2016

Android app for FLAMES

                                                     FLAMES Android App


=> It follows the same way just like 1]how we take two names, 2]cross the common letters of both names, 3]counting  the number of uncommon letters and then 4]striking the FLAMES with the number.

              In this post I shared both MainActivity.java  and activity_main.xml files.


Idea behind reducing complexity of the game:-

             * complexity of the game can be reduced after finding the number of uncommon letters  i.e, last step striking the FLAMES with the number. I calculated it for 50 uncommon letters. 

             => Yes you are right once if sum of uncommon letters of both names exceeds 50 then this app is not going to work. But it is rare to find a person with name having more than 25 letters( so that sum of two leads to 50), More over there are only 26 different Alphabets only. Which means there is a very minute probability to get more than 50 uncommon letters.

Benefit by doing so :-

     => We can increase Running time(Runs fast), decreases complexity(uses less ram) and reduces memory(app occupies less space in your mobile) at same time. Mostly in any Algorithm we need to compromise at one or the another but by using above idea we can achieve it.

Specifications

Version                  :-   1.0

Memory occupied  :-    784 KB

Running Time        :-    < 1 sec

Location                :-     No need

    

NEXT VERSION :- 


 In next version I will try to extend it for persons with big names (more than 100 letters) with out getting compromised for above 3. Meet you in next version. 

                                                                                  ...................Happy Coding

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////











**********************************************************************

                         MainActivity.java

package com.viswadeepgmail.l.flames;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    int c, d, as1, as2, e, h, k;
    private EditText n1;
    private EditText n2;
    private TextView t1;
    private String s1;
    private String s2;


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

        n1 = (EditText) findViewById(R.id.editText);

        n2 = (EditText) findViewById(R.id.editText2);

        t1 = (TextView) findViewById(R.id.textView);


    }


    public void onButtonclick(View v) {
        int u = 0, m5 = 0, j5 = 0;
        String s1 = n1.getText().toString();
        s1 = s1.replace(" ", "");
        s1 = s1.toUpperCase();
        c = s1.length();

        String s2 = n2.getText().toString();

        s2 = s2.replace(" ", "");
        d = s2.length();
        s2 = s2.toUpperCase();

        if (c == 0 && d == 0) {
            Toast.makeText(getApplicationContext(), 
              "Both name feilds are Empty", Toast.LENGTH_LONG).show();
            t1.setText("Cannot find Relation ");

        }
        else if (c == 0) {
            Toast.makeText(MainActivity.this, 
              "Enter First Person Name", Toast.LENGTH_LONG).show();
            t1.setText("Cannot find Relation ");


        } else if (d == 0) {
            Toast.makeText(MainActivity.this, 
              "Enter Second Person Name", Toast.LENGTH_LONG).show();
            t1.setText("Cannot find Relation ");

        }
        else {
            if (c != 0 && d != 0) {
                if (c == d) {
                    for (int i5 = 0; i5 < c; i5++) {
                        if (s1.charAt(i5) == s2.charAt(i5)) {
                            m5++;
                        }
                    }
                }
                if (m5 == c) {
                    j5 = 5;
                }

                for (int r1 = 0; r1 < c; r1++) {
                    as1 = s1.charAt(r1);
            if ((as1 >= 97 && as1 <= 122) || (as1 >= 65 && as1 <= 90)) {
                        u = u;
                    } else {
                        u = u + 1;
                    }
                }
                for (int r2 = 0; r2 < d; r2++) {
                    as2 = s2.charAt(r2);
            if ((as2 >= 97 && as2 <= 122) || (as2 >= 65 && as2 <= 90)) {
                        u = u;
                    } else {
                        u = u + 1;
                    }
                }

                if (u == 0) {
                    e = c + d;

                    h = 0;
                    for (int i = 0; i < c; i++) {
                        for (int j = 0; j < d; j++) {
                            if (s1.charAt(i) == s2.charAt(j)) {
                                h++;
                                StringBuilder s4 = new StringBuilder(s1);
                                s4.setCharAt(i, '/');
                                s1 = new String(s4);
                                StringBuilder s3 = new StringBuilder(s2);
                                s3.setCharAt(j, '-');
                                s2 = new String(s3);
                            } else {
                                h = h;
                            }


                        }

                    }


                    k = e - (2 * h);

                    if (k == 2 || k == 4 || k == 7 || k == 9 || k == 20  
                        ||k == 22 || k == 25) {
                        t1.setText("ENEMIES ");
                    } else if (k == 3 || k == 5 || k == 14 || k == 16 
                        || k == 18 || k == 23) {
                        t1.setText("FRIENDS ");
                    } else if (k == 10 || k == 19) {
                        t1.setText("LOVE ");
                    } else if(k == 12 || k == 8 || k == 13 || k == 17 
                         || k == 28 || k == 30) {
                        t1.setText("AFFECTION ");
                    } else if (k == 6 || k == 11 || k == 15 || k == 26) {
                        t1.setText("MARRIAGE ");
                    } else if (k == 0 && j5 == 5) {
                        t1.setText("NAMES ARE EQUAL ");
                    } else if (k == 0) {
                        t1.setText("  THEY HAVE SAME LETTERS      ");
                    } else {
                        t1.setText("SIBLINGS ");
                    }

                   
                } else {
                    t1.setText("RELATION CANNOT BE DETERMINED");
                }

            }

        }
    }
    public void onSecondButtonclick(View v) {
        t1.setText("Relation ");
        n1.setText("");
        n2.setText("");



    }
}


***************************************************************************

                           activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background"
tools:context="com.viswadeepgmail.l.flames.MainActivity"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Relation"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
android:textStyle="bold|italic"
android:elevation="@dimen/elevation"
android:textColor="#f66015"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView2"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView3"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="249dp"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Enter name 1"
android:imeOptions="actionNext"
android:inputType="textPersonName"
android:textStyle="italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView4"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="247dp"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="Enter name 2"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textStyle="italic" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView5"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView6"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="374dp"
android:layout_height="fill_parent">
<Button
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="@string/button_find"
android:id="@+id/getFlames"
android:onClick="onButtonclick" />
<TextView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView7" />
<Button
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Renew"
android:id="@+id/button"
android:onClick="onSecondButtonclick" />
</LinearLayout>
</LinearLayout>
</LinearLayout>






No comments:

Post a Comment