Wednesday, August 5, 2015

Bubble Sort in Java Program

In this article I would like to share with you one of the most common sorting algorithm used in computer science it is called bubble sort. Basically we use sorting to arrange the values in ascending or descending order. What our program does is to ask the user how many items to be sorted and then our program will ask the user to enter a series of values. After which our program will display the original values and it will display the ascending and descending order of values after it is processed by our program using bubble sort algorithm.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

// bubble_sort.java
// Written By: Mr. Jake R. Pomperada, BSCS, MAED-IT
// August 5, 2015   Wednesday
// Create a program that uses bubble sort algorithm with the following results.
//   BUBBLE SORT PROGRAM
//   How many values :6
//   Enter value in item no.1: 540
//   Enter value in item no.2: 313
//   Enter value in item no.3: 741
//   Enter value in item no.4: -456
//   Enter value in item no.5: 600
//   Enter value in item no.6: 341
//
//   BEFORE SORTING
//   540 313 741 -456 600 341 
//   AFTER SORTING
//
//   ASCENDING ORDER
//
 // -456 313 341 540 600 741
//   DESCENDING ORDER
//   741 600 540 341 313 -456
// THANK YOU FOR USING THIS PROGRAM


import java.util.Scanner;
class bubble_sort {
public static void main(String args[])  {
        
        Scanner scan = new Scanner(System.in);
        int items[] = null;
int values = 0;
       
        System.out.print("BUBBLE SORT PROGRAM");
        System.out.println();    
System.out.print("How many values :");
values = scan.nextInt();
        items = new int[values];

        for(int i=0; i<values; i++)
             {
            System.out.print("Enter value in item no." + (i+1) + ": ");     
            items[i] = scan.nextInt();
            }
        System.out.println();
System.out.print("BEFORE SORTING");
System.out.println();
for(int i=0; i<values; i++) 
              {
System.out.print(items[i] + " ");
     }
for(int i = 0; i < values; i++) {
 for(int j = 1; j < (values-i); j++) {
   if(items[j-1] > items[j]) {
        int temp = items[j-1];
                 items[j-1] = items[j];
items[j] = temp;
}
   }
}
        System.out.println();
System.out.println("AFTER SORTING");
        System.out.println();
System.out.println("ASCENDING ORDER");
        System.out.println();
for(int i=0; i<values; i++) 
         {
System.out.print(" " + items[i]);
}
        System.out.println();
System.out.print("DESCENDING ORDER");
         System.out.println();
for(int i=values-1; i>=0; i--)
        {
System.out.print(" " + items[i]);
}
       System.out.println("\n\n");
       System.out.print("\t THANK YOU FOR USING THIS PROGRAM"); 
       System.out.println();
    }
}



First Letter Capital Program in Java

As I continue my study on Java I have discovered that Java programming language has many built in functions that makes programming much easier and more fun specially we are working with strings. I enjoy every minute working with Java. No wonder there are many programmers, developers and software engineers find it very useful in many programming project because it is a very versatile programming language.

In this article I would like to share with you guys a sample program that I wrote in Java that will ask the user to give a sentence and then our  program will convert the first letter of the sentence into uppercase letter. I have created a method on it that well convert the first letter of the word in a give sentence by our user.  In addition our program it will ask the user if the user would want to repeat the program running by asking the user do you want to continue yes or not.
 
If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.
 
 
 
 
Sample Program Output 
 
 
Program Listing
 
 
// find_upper_case.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : August 5, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com
// Write a program that will conver the first letter of a word into capital
// letters


 import java.util.Scanner; 
  
 public class find_upper_case { 
  
public static String Upper_First_Letter(String str)
{
    boolean check_space = true;
    char[] chars = str.toCharArray();
    for (int a = 0; a < chars.length; a++) {
        if (Character.isLetter(chars[a])) {
            if (check_space) {
                chars[a] = Character.toUpperCase(chars[a]);   
            }
            check_space = false;
        } else {
            check_space = Character.isWhitespace(chars[a]);
        }
    }
    return new String(chars);
}
 
    public static void main(String[] args) {
     Scanner input = new Scanner(System.in);
     char ch;
                  
  do {
     String sentence,repeat;
     repeat = input.nextLine();
     System.out.print("FIRT LETTER CAPITAL PROGRAM");
     System.out.println();   
     System.out.print("Enter a Sentence : ");
     sentence = input.nextLine();
     System.out.println();
     System.out.println("ORIGINAL SENTENCE");
     System.out.print(sentence);
     System.out.println("\n\n");
     System.out.println("CONVERTED SENTENCE");
     System.out.print(Upper_First_Letter(sentence));
     System.out.println();
      System.out.print("\nDo you want to continue (Type y or n) : ");
     ch = input.next().charAt(0);                       
     } while (ch == 'Y'|| ch == 'y'); 
     System.out.println();
     System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
     System.out.println();
    }
}
 

Friday, July 31, 2015

Addition of Two Numbers in Cobol

Cobol is one of the earliest high level language know to us it stands for Common Business Oriented Language it is develop by Admiral Grace Hooper the first person who write the first compiler. In this program that I wrote it will ask the user to enter two numbers and then our program will display the total sum of two number given by our user.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output




Program Listing

 IDENTIFICATION DIVISION.
       PROGRAM-ID. ADD01.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  FIRST-NUMBER      PICTURE IS 99999.
       01  SECOND-NUMBER     PICTURE IS 99999.
       01  THE-RESULT        PICTURE IS 99999.
       PROCEDURE DIVISION.
       PROGRAM-BEGIN.
               DISPLAY "===== ADDITION OF TWO NUMBERS =====".
               DISPLAY "Enter the first number :".
               ACCEPT FIRST-NUMBER.
               DISPLAY "Enter the second number :".
               ACCEPT SECOND-NUMBER.
               ADD FIRST-NUMBER, SECOND-NUMBER GIVING THE-RESULT.
  DISPLAY "The result is : ".
  DISPLAY THE-RESULT.
               STOP RUN.  

Inheritance in PHP

As I learned programming specially PHP one of my favorite web programming language I have to admit that some of the advance concepts like object oriented programming I'm not yet equip with. One of its is the concept of inheritance this concepts is one of the most important aspect in object oriented programming not only in PHP but other programming language like Java and C#.

Inheritance teaches us how to use the attributes and methods from the parent class. It makes our programming much easier in a sense that we use existing codes in the library class file specially we are using web frameworks like codeigniter, laravel, magento and many others. I hope you will find my program useful in learning the concepts of object oriented programming in PHP using the concepts of inheritance.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output


Program Listing


<?php

class user_details {
public $name;
public $address;
public $age;
public  $email;
function display_user_details() {
echo "<font color='blue'>";
echo "<h2> About the User </h1>";
echo "<h4> Name                : " .$this->name. "</h4>";
echo "<h4> Address             : " .$this->email. "</h4>";
echo "<h4> Age                 : " .$this->age. "</h4>";
echo "<h4> Email Address       : " .$this->email. "</h4>";
echo "</font>";
}
}


class person extends user_details {
}

$user = new person;
$user->name='Willian Gates III';
$user->address= 'One Microsoft Way';
$user->age= 60;
$user->email= 'bill_gates@microsoft.com';
$user->display_user_details();

?>

Thursday, July 30, 2015

Age Calculator in Java

I have wrote a simple program that will ask the user its birth month, birth day and birth year and then the program will check and determine the present age of the user. The code uses calendar libraries in Java programming language.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output


Program Listing

 // age_calculator.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 30, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com
// Write a program that will determine the age of the person.


 import java.util.Scanner;  
 import java.util.GregorianCalendar;  
 import java.util.Calendar;  
   
 public class age_calculator {  
   
   private static int age_checker(int y, int m, int d) {  
     Calendar cal = new GregorianCalendar(y, m, d);  
     Calendar now = new GregorianCalendar();  
     
     int age_result = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR);  
     if((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH))  
       || (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH)  
       && cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH)))  
     {  
        age_result--;  
     }  
     return age_result;  
   }  
   
   public static void main(String [] args) {  

      Scanner input = new Scanner(System.in); 
        char ch;
    do {
      int month=0,day=0,year=0;
      System.out.println();
      System.out.print("\t Age Checker Program ");
      System.out.println("\n");
      System.out.print("Enter Birth Month : "); 
      month = input.nextInt();
      System.out.print("Enter Birth Day   : "); 
      day = input.nextInt();
      System.out.print("Enter Birth Year  : "); 
      year = input.nextInt();
      System.out.println("Your present age is " 
              + age_checker(year,month,day)+ " years old.");
      System.out.println();
      System.out.print("\nDo you want to continue (Type y or n) : ");
      ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');     
      System.out.println();
      System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
      System.out.println("\n\n");
    }
 }   


Sunday, July 26, 2015

Smallest Number in Java

In this simple program that I wrote it will allows the user to give a series of numbers and then it will check and display the smallest number from the given number by the user using Java as our programming language.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

/*
smallest_number_array.java
Programmer By: Mr. Jake R. Pomperada, MAED-IT
Date : July 23, 2015
Tools: NetBeans 8.0.2, Java SE 8.0

Problem No. 7:
  
Write a program that will ask the user to give five numbers and then
it will search for the smallest number in the given list from the user.
user.
*/
              

import java.util.Scanner;

class smallest_number_array{
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
                   
  do { 
      int [] values; 
      values  = new int[5];  
      int x=0;
      int smallest = Integer.MAX_VALUE;
      System.out.print("SMALLEST NUMBER PROGRAM");
      System.out.println();
      for (int a=0; a<5; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no. " + x + " : ");
         values[a] = input.nextInt();
        }       
         System.out.println(); 
         for(int a =0;a<5;a++) {
           if(smallest > values[a]) 
           {
            smallest = values[a];
            }
        }  
     System.out.println("The smallest number is " + smallest +".");
      System.out.print("\nDo you want to continue (Type y or n) : ");
     ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
     System.out.println();
     System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
     System.out.println("\n\n");
  }
} // End of Code
    


Square and Cube Number Program in Java

This simple program  ask the user to enter a number and then our program will generate the corresponding square and cube value of the given number using for loop statement in Java. The code is very basic for beginners that are new in Java programming.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Prorgam Output

Program Listing

/*
square_array.java
Programmer By: Mr. Jake R. Pomperada, MAED-IT
Date : July 23, 2015
Tools: NetBeans 8.0.2, Java SE 8.0

Problem No. 6:
  
Write a program that will ask the user to give five numbers and then
it will display the square and cube value of the given number by the
user.
*/
              

import java.util.Scanner;

class square_array{
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
        
  do { 
      int [] values; 
      values  = new int[5];  
      int x=0;
      System.out.print("SQUARE AND CUBE NUMBER PROGRAM");
      System.out.println();
      for (int a=0; a<5; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no. " + x + " : ");
         values[a] = input.nextInt();
        }       
         System.out.println("\n\n"); 
         System.out.print("\tNUMBER     SQUARE      CUBE ");
         for (int a=0; a<5; a++)
          {
             x=1;
             x+=a;
             int square = (values[a] * values[a]);
             int cube  = (values[a] * values[a] * values[a]);
             System.out.println(); 
             System.out.println("\t  "+x+"\t      " + square + " \t" +cube);
          }
     System.out.println(); 
     System.out.print("\nDo you want to continue (Type y or n) : ");
     ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
     System.out.println();
     System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
     System.out.println("\n\n");
  }
} // End of Code
    

Saturday, July 25, 2015

Addition of Five Numbers Using Java Servlet

Learning to program in Java is a journey not a destination.  This program will allow the user to enter five numbers in a form and then it will display the total sum of five numbers using Java Servlet.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.







Sample Program Output


Program Listing

index.html

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>Addition of Five Numbers</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
       body {
           background:lightgreen; 
           font-family: arial;
        }
        h2 {
            font-family: arial;
        }  
    </style>  </head>  
    <body>
  <h2> Addition of Five Numbers in Java Servlet </h2>
<form name='addition' action='http://localhost:8080/WebApplication1/addition' method='get'>
Enter First  Value <input type='text' name='value1'><br>
Enter Second Value <input type='text' name='value2'><br>
Enter Third  Value <input type='text' name='value3'><br>
Enter Fourth Value <input type='text' name='value4'><br>
Enter Fifth Value <input type='text' name='value5'><br><br>
<input type='submit' name='submit' value='Add Values' title='Click here to find the sum.'>
</form>
</body>
</html>


additional.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author jake.r.pomperada
 */
@WebServlet(urlPatterns = {"/addition"})
public class addition extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException , ServletException
{
PrintWriter pr=res.getWriter();
res.setContentType("text/html");
try
{
int a=Integer.parseInt(req.getParameter("value1"));
int b=Integer.parseInt(req.getParameter("value2"));
int c=Integer.parseInt(req.getParameter("value3"));
int d=Integer.parseInt(req.getParameter("value4"));
int e=Integer.parseInt(req.getParameter("value5"));

int total_sum=(a+b+c+d+e);
pr.println("<body bgcolor='lightgreen'>");    
pr.println("<h1> THE RESULT </h1>");
pr.println("<br>");
pr.println("<h2> The sum of " +a + "," 
          + b + ", " + c + ", " + d + ", "
          + e + " is "+ total_sum +". </h2");
pr.println("</body>");

}
catch(Exception e)
{
pr.println("<body bgcolor='lightgreen'>");    
pr.println("<font face='aria'>Invalid Input Value Try Again");
pr.println("</font> </body>");
}
} }

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet>
        <servlet-name>addition</servlet-name>
        <servlet-class>addition</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>addition</servlet-name>
        <url-pattern>/addition</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file> index.html</welcome-file>
     </welcome-file-list>   
</web-app>




Sum of Numbers Using While Loop

A simple program that will sum up the  series of number using while looping statement in Java.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

/*
while_loops.java
Programmer By: Mr. Jake R. Pomperada, MAED-IT
Date : July 21, 2015

Problem No. 1:
  
Design a program that calculates the sum of the input given
number of N using while loop statement.

*/


import java.util.Scanner;

class while_loops {
    
public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    int sum=0,b=0;
    System.out.print("\t Sum of Numbers Using While Loop");
    System.out.println();
    System.out.print("Enter your desired looping number : ");
    int value = input.nextInt();
    while (b<=value) {
      System.out.print(" " + b + " ");
        sum+=b;
        b++;
    }   
    System.out.println();
    System.out.println("The total sum is  " + sum +".");
    System.out.println();
    System.out.println(" END OF PROGRAM"); 
    System.out.println();
  }
}

Word Count in Java

A program that I wrote in Java that will ask the user to enter a sentence and then our program will count the number of words in a given sentence.

If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.





Sample Program Output

Program Listing

/* word_count.java */
/* Written By: Mr. Jake R. Pomperada, MAED-IT */
/* July 15, 2015 */
/* This program will count the number of words in a given sentence by the user */

import java.util.Scanner;

class word_count {

    
    private static int word_count(String phrase)
    {
    if (phrase == null)
       return 0;
    return phrase.trim().split("\\s+").length;
    }

public static void main(String args[])
   {
      String words;
      char ch;

      do {
          Scanner input = new Scanner(System.in);
          System.out.println();
          System.out.print("\t WORD COUNT PROGRAM ");
          System.out.println("\n");
          System.out.print("Kindly enter a word :=> ");
          words= input.nextLine();
          System.out.println();
          System.out.print("The total number of words is " + word_count(words) +".");
          System.out.println();
          System.out.print("\nDo you want to continue (Type y or n) : ");
          ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
          System.out.println();
          System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
          System.out.println("\n\n");    
   }
}