Thursday, June 30, 2016

Sum and Product of Two Numbers in Android Version 2

This is the second version of my work in Android I called this program Sum and Product of two numbers. There are some improvements on the code particularly in the output edittext it no only allows the user to put any value on it and others improvement that makes our application more stable and accurate.

Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output



Program Listing

MainActivity.java

package com.example.servo.add;

import android.view.View;
import android.widget.EditText;
import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.content.Context;
import android.content.DialogInterface.OnClickListener;



public class MainActivity extends ActionBarActivity {

    final Context context = this;

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

    public void sum_and_product(View view) {

        EditText editText2 = (EditText) findViewById(R.id.editText2);
        EditText editText3 = (EditText) findViewById(R.id.editText3);
        EditText editText4 = (EditText) findViewById(R.id.editText4);
        EditText editText = (EditText) findViewById(R.id.editText);


        int first = Integer.valueOf(editText2.getText().toString());
        int second = Integer.valueOf(editText4.getText().toString());

        int add = first + second;

        int product = first * second;


        editText3.setText(Integer.toString(add));
        editText.setText(Integer.toString(product));
    }


    public void clear(View view) {
        EditText editText2 = (EditText) findViewById(R.id.editText2);
        EditText editText3 = (EditText) findViewById(R.id.editText3);
        EditText editText4 = (EditText) findViewById(R.id.editText4);
        EditText editText = (EditText) findViewById(R.id.editText);

        editText2.setText("");
        editText2.requestFocus();
        editText2.setText("");
        editText3.setText("");
        editText4.setText("");
        editText.setText("");

    }


    public void quit() {
        // TODO Auto-generated method stub        //super.onBackPressed();        openQuitDialog();
    }

    private void openQuitDialog() {
        AlertDialog.Builder quitDialog
                = new AlertDialog.Builder(MainActivity.this);
        quitDialog.setTitle("Confirm to Quit?");

        quitDialog.setPositiveButton("OK, Quit!", new OnClickListener() {

            @Override            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub                finish();
            }
        });

        quitDialog.setNegativeButton("NO", new OnClickListener() {

            @Override            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
            }
        });

        quitDialog.show();
    }
}


activity_main.xml

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:id="@+id/myRelativeLayout"
    android:background="#ff1dffb7">


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:inputType="number"
        android:layout_above="@+id/textView2"
        android:layout_alignLeft="@+id/editText4"
        android:layout_alignStart="@+id/editText4"
        android:textColor="#ff0918ff" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText3"
        android:inputType="number"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:clickable="false"
        android:cursorVisible="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/editText"
        android:layout_alignStart="@+id/editText"
        android:textColor="#ff142eff" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText4"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:inputType="number"
        android:textColor="#ff1024ff"
        android:layout_below="@+id/textView"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ok"
        android:id="@+id/button"
        android:onClick="sum_and_product"
        android:textStyle="bold"
        android:layout_alignTop="@+id/button2"
        android:layout_alignRight="@+id/textView3"
        android:layout_alignEnd="@+id/textView3" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Clear"
        android:id="@+id/button2"
        android:onClick="clear"
        android:textStyle="bold"
        android:layout_below="@+id/editText"
        android:layout_alignRight="@+id/textView5"
        android:layout_alignEnd="@+id/textView5"
        android:layout_marginTop="37dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First Number"
        android:id="@+id/textView"
        android:textStyle="bold"
        android:layout_marginTop="50dp"
        android:layout_below="@+id/textView5"
        android:layout_alignLeft="@+id/textView4"
        android:layout_alignStart="@+id/textView4"
        android:textColor="#ff0e16ff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Second Number"
        android:textStyle="bold"
        android:id="@+id/textView2"
        android:layout_below="@+id/textView"
        android:layout_alignLeft="@+id/textView"
        android:layout_alignStart="@+id/textView"
        android:layout_marginTop="42dp"
        android:textColor="#ff1121ff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="The product is"
        android:textStyle="bold"
        android:id="@+id/textView6"
        android:layout_marginTop="34dp"
        android:textColor="#ff0a1eff"
        android:layout_below="@+id/textView3"
        android:layout_alignLeft="@+id/textView3"
        android:layout_alignStart="@+id/textView3" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="The total sum is"
        android:textStyle="bold"
        android:id="@+id/textView3"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/textView2"
        android:layout_alignStart="@+id/textView2"
        android:textColor="#ff1624ff" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sum and Product of Two Numbers"
        android:textStyle="bold"
        android:textSize="18dp"
        android:textColor="#ff0d19ff"
        android:id="@+id/textView4"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:shadowColor="#ffac0dff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Created By: Mr. Jake R. Pomperada"
        android:textSize="16dp"
        android:textColor="#ff0c26ff"
        android:textStyle="bold"
        android:id="@+id/textView5"
        android:layout_marginTop="38dp"
        android:layout_below="@+id/textView4"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:inputType="number"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:clickable="false"
        android:cursorVisible="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_alignBottom="@+id/textView6"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2"
        android:textColor="#ff0f27ff" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Quit"
        android:id="@+id/button3"
        android:onClick="quit"
        android:layout_marginTop="20dp"
        android:textStyle="bold"
        android:layout_below="@+id/button"
        android:layout_toRightOf="@+id/button"
        android:layout_toEndOf="@+id/button" />
</RelativeLayout>



strings.xml


<resources>
    <string name="app_name">Sum and Products</string>
    <string name="action_settings">Settings</string>
</resources>



AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.servo.add" >

    <application
        android:allowBackup="true"
        android:title="Sum and Product of Two Numbers"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



Wednesday, June 29, 2016

Sum and Product of Two Numbers in Android

I am very amassed with new developments in technology particularly in mobile phone to be specific Android application development. In this article I would like to share with you my first android application that I have written using Android Studio I called this application sum and product of two numbers in android what thus the program will do is to ask  the user to give two numbers and then our program will compute the sum and product of the two numbers. This program is very simple I just stated learning android programming in couple of days it is more on self study on my part. I hope you will find my work useful.

 Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

MainActivity.java

package com.example.servo.add;

import android.view.View;
import android.widget.EditText;
import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {

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

    public void sum_and_product(View view) {

        EditText editText2 = (EditText) findViewById(R.id.editText2);
        EditText editText3 = (EditText) findViewById(R.id.editText3);
        EditText editText4 = (EditText) findViewById(R.id.editText4);
        EditText editText = (EditText) findViewById(R.id.editText);


         int first = Integer.valueOf(editText2.getText().toString());
         int second = Integer.valueOf(editText4.getText().toString());

         int add = first + second;

        int product = first * second;


        editText3.setText(Integer.toString(add));
        editText.setText(Integer.toString(product));
    }


    public void clear(View view) {
        EditText editText2 = (EditText) findViewById(R.id.editText2);
        EditText editText3 = (EditText) findViewById(R.id.editText3);
        EditText editText4 = (EditText) findViewById(R.id.editText4);
        EditText editText = (EditText) findViewById(R.id.editText);

        editText2.setText("");
        editText2.requestFocus();
        editText2.setText("");
        editText3.setText("");
        editText4.setText("");
        editText.setText("");

    }

    public void quit() {
        new AlertDialog.Builder(this)
                .setMessage("Are you sure you want to exit?")
                .setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        MainActivity.this.finish();
                    }
                })
                .setNegativeButton("No", null)
                .show();
    }
}


activity_main.xml

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:id="@+id/myRelativeLayout"
    android:background="#ff1dffb7">


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:inputType="number"
        android:layout_above="@+id/textView2"
        android:layout_alignLeft="@+id/editText4"
        android:layout_alignStart="@+id/editText4"
        android:textColor="#ff0918ff" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText3"
        android:inputType="number"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/editText"
        android:layout_alignStart="@+id/editText"
        android:textColor="#ff142eff" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText4"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:inputType="number"
        android:textColor="#ff1024ff"
        android:layout_below="@+id/textView"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2" />



    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ok"
        android:id="@+id/button"
        android:onClick="sum_and_product"
        android:textStyle="bold"
        android:layout_alignTop="@+id/button2"
        android:layout_alignRight="@+id/textView3"
        android:layout_alignEnd="@+id/textView3" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Clear"
        android:id="@+id/button2"
        android:onClick="clear"
        android:textStyle="bold"
        android:layout_below="@+id/editText"
        android:layout_alignRight="@+id/textView5"
        android:layout_alignEnd="@+id/textView5"
        android:layout_marginTop="37dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First Number"
        android:id="@+id/textView"
        android:textStyle="bold"
        android:layout_marginTop="50dp"
        android:layout_below="@+id/textView5"
        android:layout_alignLeft="@+id/textView4"
        android:layout_alignStart="@+id/textView4"
        android:textColor="#ff0e16ff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Second Number"
        android:textStyle="bold"
        android:id="@+id/textView2"
        android:layout_below="@+id/textView"
        android:layout_alignLeft="@+id/textView"
        android:layout_alignStart="@+id/textView"
        android:layout_marginTop="42dp"
        android:textColor="#ff1121ff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="The product is"
        android:textStyle="bold"
        android:id="@+id/textView6"
        android:layout_marginTop="34dp"
        android:textColor="#ff0a1eff"
        android:layout_below="@+id/textView3"
        android:layout_alignLeft="@+id/textView3"
        android:layout_alignStart="@+id/textView3" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="The total sum is"
        android:textStyle="bold"
        android:id="@+id/textView3"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/textView2"
        android:layout_alignStart="@+id/textView2"
        android:textColor="#ff1624ff" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sum and Product of Two Numbers"
        android:textStyle="bold"
        android:textSize="18dp"
        android:textColor="#ff0d19ff"
        android:id="@+id/textView4"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:shadowColor="#ffac0dff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Created By: Mr. Jake R. Pomperada"
        android:textSize="16dp"
        android:textColor="#ff0c26ff"
        android:textStyle="bold"
        android:id="@+id/textView5"
        android:layout_marginTop="38dp"
        android:layout_below="@+id/textView4"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:inputType="number"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:layout_alignBottom="@+id/textView6"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2"
        android:textColor="#ff0f27ff" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Quit"
        android:id="@+id/button3"
        android:onClick="quit"
        android:layout_marginTop="20dp"
        android:textStyle="bold"
        android:layout_below="@+id/button"
        android:layout_toRightOf="@+id/button"
        android:layout_toEndOf="@+id/button" />
</RelativeLayout>

Saturday, June 25, 2016

Decimal To Hexadecimal Converter in Java

This simple program will ask  the user to give a  number and then our program will convert the given number by the user into hexadecimal equivalent. The program is very easy to understand and use.


 Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

package hello;

import java.util.Scanner;

public class Decimal_Hexadecimal {

public static void main(String args[]) {

Scanner input = new Scanner(System.in);
int values = 0;

System.out.println("Decimal To Hexadecimal Converter in Java");
System.out.println();
System.out.print("Enter a Number : ");
values = input.nextInt();

String hex_value = Integer.toHexString(values);

System.out.println("The Hexadecimal Value is : " + hex_value + ".");
System.out.println();
System.out.println("\t End of Program");
}
}

Decimal To Binary Converter in Java

This simple program will ask  the user to give a  number and then our program will convert the given number by the user into binary equivalent. The program is very easy to understand and use.


 Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output



Program Listing


Decimal_binary.java


package hello;

import java.util.Scanner;

public class Decimal_binary {

public static void main(String args[]) {

Scanner input = new Scanner(System.in);
int values = 0;

System.out.println("Decimal To Binary Converter in Java");
System.out.println();
System.out.print("Enter a Number : ");
values = input.nextInt();

String binary_value = Integer.toBinaryString(values);

System.out.println("The Binary Value is : " + binary_value + ".");
System.out.println();
System.out.println("\t End of Program");
}
}

Decimal To Octal Converter in Java

This simple program will ask  the user to give a  number and then our program will convert the given number by the user into octal equivalent. The program is very easy to understand and use.


 Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

decimal_octal.java

package hello;

import java.util.Scanner;

public class decimal_octal {

public static void main(String args[]) {

Scanner input = new Scanner(System.in);
int values = 0;

System.out.println("Decimal To Octal Converter in Java");
System.out.println();
System.out.print("Enter a Number : ");
values = input.nextInt();

String octal_value = Integer.toOctalString(values);

System.out.println("The Octal Value is : " + octal_value + ".");
System.out.println();
System.out.println("\t End of Program");
}
}

Sum and Average of Numbers Using Array in Java

A simple program that I wrote in Java to find the sum and average of numbers using one dimensional array in Java. What the program does it will ask the user to give a series of integer number and then the program will compute the sum and average of the five numbers given by the user of our program.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

sum_array.java

package hello;

import java.util.Scanner;

public class sum_array {

 
 public static void main(String args[]){
 
 Scanner input = new Scanner(System.in);
    
       int num[]=new int[5];
       int average=0,i=0,sum=0;
     
       System.out.println("Sum and Average of Numbers Using Array in Java");
       System.out.println();
       for (i=0;i<num.length;i++) {
       
       
          System.out.print("Enter a Number : ");
           num[i]=input.nextInt();
           sum=sum+num[i];
       }
       
       average=(sum/5);
       
       System.out.println();
       System.out.println("The total sum is  "+ sum + ".");
       System.out.println();
       System.out.println("The average is "+average+".");
       System.out.println();
       System.out.println("\t End of Program");
 
 }
 
 
}





Simple Inheritance in Java

A simple program that I wrote in Java to show how the concepts of inheritances works. This program will greet the user three times when we assign a name of the user in a string. The code is very easy to understand and learn ideal for those that are new in Java programming.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Simple_Inheritance.java


package hello;


class hello_world{ 

 public void greet2(String user){
        System.out.println("Hello " + user + " How are you?");
        System.out.println();
  }
 public void greet3(String user){
        System.out.println("Kamusta ka " + user + " Welcome to Philippines.");
        System.out.println();
        System.out.println("\t End of Program");
     }
 
}


public class Simple_Inheritance extends hello_world {
 public void greet1(String person1){
    System.out.println("\t Simple Inheritance in Java");
    System.out.println();
        System.out.println("Welcome " + person1 + " to our home.");
        System.out.println();
  }
 public static void main(String args[]){
 String name="Jake R. Pomperada";
 
 Simple_Inheritance person = new Simple_Inheritance();
 person.greet1(name);
 person.greet2(name);
 person.greet3(name);
 
  }
}


 

Sunday, June 19, 2016

Multiply Two Numbers in C++ Using Classes

This simple program in C++ will show you how to multiply them using Classes. The code is very simple and easy to understand.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.


My mobile number here in the Philippines is 09173084360.



Program Listing

#include <iostream>
#include <string>

using namespace std;

class multiply {
    int val1,val2;
    char reply;
    public:
    int get_data();
    void display_result(void);
};


int multiply :: get_data()
{
    while (1) {
    system("cls");
    cout << "enter two number :";
    cin >> val1>> val2;
    cout << "\n\n The Product is " << (val1*val2);
    cout << "\n\n";
    cout << "More Y Or N : ";
    cin >> reply;

    if (tolower(reply) == 'n') {
        cout << "Thanks";
        break;
    }
    }
}

void multiply :: display_result(void)
{
    int val=0;
    val = get_data();
}

main() {
    multiply numbers;

    numbers.display_result();
}