Saturday, July 18, 2015

Consonants Remover in Java

In this article I would like to share with you a sample program that will remove any consonants letters in a word or string in Java. The code is very simple and easy to understand.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me 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

/* remove_consonants.java */
/* Written By: Mr. Jake R. Pomperada, MAED-IT */
/* July 14, 2015 */
/* This program will remove consonants in a given word or string by the user */

import java.util.Scanner;
 
class remove_consonants
{
 
    private static String remove_Consonants(String s) {  
        String finalString = "";  
        for (int i = 0;i < s.length(); i++) {      
            if (!isConsonants(Character.toLowerCase(s.charAt(i)))) {  
                finalString = finalString + s.charAt(i);  
            }  
        }  
        return finalString;  
    }

    private static boolean isConsonants(char c) {  
        String consonants = "bcdfghjklmnpqrstvwxyz";   
        for (int i=0; i<21; i++) {   
            if (c == consonants.charAt(i))  
                return true;  
        }  
        return false;     
    }  
    
    
    public static void main(String args[])
   {
      String words;
      char ch;
      do {
      Scanner input = new Scanner(System.in);
      System.out.println();
      System.out.print("\t CONSONANTS REMOVER PROGRAM ");
      System.out.println("\n");
      System.out.print("Kindly enter a word :=> ");
      words= input.nextLine();
      System.out.println("The original words is " + words + ".");
      String final_words = remove_Consonants(words);
      System.out.println("The remaining letters is " + final_words + ".");
       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");
      
      }
}




Users Details System in JSP and MySQL

There are many web scripting programming language in this world one of its based of Java programming language it is called Java Server Pages or JSP. It is entirely based on Java technology to be specific Servlets which interacts together with the web server. In Java the most common web server is Apache Tomcat which is also an open source web server. One of the benefits of learning how to program in JSP is that almost all Java Enterprise application works with JSP and it is easy to learn and implement with database application such as MySQL.

In this article I will not only show you how to create a basic CRUD application in Java Server Pages but also how it is being done through the use of my program codes. Basically I am using NetBeans 8.1.0 as my IDE or Integrated Development Environment in writing this database application and also I download mysql java connector which I include a link in my article. My program that I wrote is a typical database routine Create, Retrieve, Update and Delete or CRUD using JSP and MySQL.

The code is very short in terms of number of lines of instruction and the same way I make sure it is very easy to understand and use in your programming projects that utilize JSP and MySQL as your tool. The application will accept the name of the person, city address and telephone number it is just like an address book or mailing list application.

It has been along while since I was able to achieve this program I have some difficulty also in learning Java and JSP along the way but through dedication and perseverance I was able to get it. That's why I am sharing this to my fellow software developers.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me 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


list.jsp

<%-- list.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*"%>

<head><title>Users Details System</title>
</head>
<style>
    h2 {
        text-align:center;
        font-family: arial;
        color: red;
       };
    td {
        text-align:center;
        font-family: arial;
        font-size: 16;
    };
   
</style>    
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;  "
            + "}; </style>");

out.println("<style>  a.space {font-family: arial;"
           + " color: blue; font-size: 18;  "
            + "margin:0 0 0 208px;}; </style>");

%>
<body>

<div align="center" width="200%">
    <br>
    <h2>USERS DETAILS SYSTEM</h2>
    <br>
    <div align="left" width="200%">
<% out.println("<a class='space' href='insert.jsp'> ADD RECORD </a>");  %>  
    </div>
<br>
<table border="1" borderColor="black" cellPadding="0" cellSpacing="0" width="920" height="80">
<tbody>
<td bgColor="cyan" width="150" align="center" height="19"><font color="red"><b>
Student No.</b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>NAME</b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>CITY</b></font></td>
<td bgColor="cyan" width="230" height="19"><font color="red"><b>PHONE</b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>ACTIONS </b></font></td>
<td bgColor="cyan" width="290" height="19"><font color="red"><b>TAKEN </b></font></td>
<%
String DRIVER = "com.mysql.jdbc.Driver";
Class.forName(DRIVER).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try{
  
String url="jdbc:mysql://localhost:3306/users?user=root&password=";
int i=1;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
rst=stmt.executeQuery("SELECT * FROM student_info ORDER BY name ASC ");
while(rst.next()){

if (i==(i/2)*2){
%>
<tr>
<td bgColor="lightgreen" vAlign="top" width="80"  height="19"><%=i%></td>
<td bgColor="lightgreen" vAlign="top" width="110" height="19"><%=rst.getString(2)%></td>
<td bgColor="lightgreen" vAlign="top" width="224" height="19"><%=rst.getString(3)%></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19"><%=rst.getString(4)%></td>
<td bgColor="lightgreen" vAlign="top" width="220" height="19" >
    <a href="edit.jsp?id=<%=rst.getInt("id")%>"> Edit Record </a></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19">
    <a href="delete.jsp?id=<%=rst.getInt("id")%>"> Delete Record </a></td>
</tr>
<%
}else{
%>
<tr>
<td bgColor="lightgreen" vAlign="top" width="80" align="center" height="19"><%=i%></td>
<td bgColor="lightgreen" vAlign="top" width="107" height="19"><%=rst.getString(2)%></td>
<td bgColor="lightgreen" vAlign="top" width="224" height="19"><%=rst.getString(3)%></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19"><%=rst.getString(4)%></td>
<td bgColor="lightgreen" vAlign="top" width="220" height="19" >
    <a href="edit.jsp?id=<%=rst.getInt("id")%>"> Edit Record </a></td>
<td bgColor="lightgreen" vAlign="top" width="230" height="19">
    <a href="delete.jsp?id=<%=rst.getInt("id")%>"> Delete Record </a></td>
</tr>
<% }

i++;
}
rst.close();
stmt.close();
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
%>
</tbody>
</table>
</center>
</div>
</body>

insert.jsp

<%-- insert.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<html>
<head>
<title>Add Record </title>
</head>
<body>
<style>
    table, td, th {
    border: 1px solid green;
    font-family: arial;
    color: blue;
}

table {
    background-color: lightgreen;
   }
</style>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>

<table border="1" width="50%">
<tr>
<td width="100%">
<form method="POST" action="save.jsp">

<h2 align="center">ADD RECORD</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>Name:</b></td>
<td width="50%"><input type="text" name="name" size="50"/> </td>
</tr>
<tr>
<td width="50%"><b>City:</b></td>
<td width="50%"><input type="text" name="city" size="50"></td>
</tr>
<tr>
<td width="50%"><b>Telephone Number:</b></td>
<td width="50%"><input type="text" name="telephone" size="15"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</form>
</td>
</tr>
</table>
<% out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
%>

</body>
</html>

save.jsp

<%-- save.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String name=request.getParameter("name");
String city=request.getParameter("city");
String telephone=request.getParameter("telephone");

int val = st.executeUpdate("INSERT student_info "
        + "VALUES(id,'"+name+"','"+city+"','"+telephone +"')");

con.close();
out.println("<p> The record of " +"<b>"+ name +"</b>" + " is successfully saved. </p>");
out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

%>

edit.jsp

<%-- edit.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>
<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<html>

<head>
<title>Update Record</title>
</head>
<style>
    table, td, th {
    border: 1px solid green;
    font-family: arial;
    color: blue;
}

table {
    background-color: lightgreen;
   }
</style>
<body>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>
<% 
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String query = "SELECT name,city,phone FROM student_info WHERE id="+id;
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
%>


<table border="1" width="50%">
<tr>
<td width="100%">
<form method="POST" action="update.jsp">
<input type="hidden" name="id" value="<%=request.getParameter("id")%>">
<h2 align="center">UPDATE RECORD</h2>
<table border="2"  width="100%" bgColor="lightgreen">

<tr>
<td width="50%" bgColor="lightgreen"><b>Name:</b></td>
<td width="50%" bgColor="lightgreen"><input type="text" name="name"
    value="<%=rs.getString("name")%>" size="50"/> </td>
</tr>
<tr>
<td width="50%" bgColor="lightgreen"><b>City:</b></td>
<td width="50%" bgColor="lightgreen"><input type="text" name="city" value="<%=rs.getString("city")%>" size="50"></td>
</tr>
<tr>
<td width="50%" bgColor="lightgreen"><b>Telephone:</b></td>
<td width="50%" bgColor="lightgreen"><input type="text" name="phone" value="<%=rs.getString("phone")%>" size="15"></td>
</tr>
</table>
<p><input type="submit" value="Update" name="submit">
<input type="reset" value="Reset" name="reset"></p>

</form>
</td>
</tr>
</table>


<%}

rs.close();
con.close();

}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
<% out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
%>
</body>
</html>

update.jsp

<%-- update.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>
<% 
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String name=request.getParameter("name");
String city=request.getParameter("city");
String phone=request.getParameter("phone");
int in = st.executeUpdate("UPDATE student_info SET name='"+name+"'"
                          + ",city='"+city+"',phone='"+phone+"' "
                          + "WHERE id='"+id+"'");
con.close();
out.println("<p> The record of " +"<b>"+ name +"</b>" + " is successfully updated. </p>");
out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>

delete.jsp

<%-- delete.java
     Written By: Mr. Jake R. Pomperada, MAED-IT
     Date : July 17, 2015, Friday
     Tools: JSP and MySQL
            mysql-connecter-java-5.1.13-bin.jar
            netbeans ide 8.0.2
--%>

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>

<% 
String strId =request.getParameter("id");
int id = Integer.parseInt(strId);
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String name=request.getParameter("name");
int in = st.executeUpdate("DELETE FROM student_info WHERE id='"+id+"'");
con.close();
out.println("<p> The record is successfully deleted. </p>");
out.println("<br>");
out.println("<a href='list.jsp'> RETURN TO MAIN PAGE </a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>





Sunday, July 12, 2015

Addition of Three Numbers in C++ Using Pointers

In this article I would like to share with you a sample program that I wrote while I'm still learning how to program using pointers as my data structure. I called this program addition of three numbers using pointers what the program does is to ask the user to enter three numbers and then our program will compute for the sum of the three number being provided by our user.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.


Program Listing

#include <iostream>

using namespace std;


 int addition(int *a, int *b, int *c)
 {
     return(*a + *b + *c);
 }

 main() {
     int x=0,y=0,z=0;

     cout << "Addition Program";
     cout << "\n\n";
     cout << "Enter three numbers : ";
     cin >> x >> y >> z;
     cout << "\n\n";
     cout << "The sum of  three numbers is "
          << addition(&x,&y,&z)
          <<".";
     cout << "\n\n";
     system("pause");
 }



Finding the length of the word in C++ using Pointers

This simple program will count the number of characters in a given string or word by the user in C++ using Pointers as our data structure.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing

#include <iostream>

using namespace std;

int str_length(char *s) {
   int a=0;
   while(*s) {
       s++;
       a++;
   }
   return a;
}

main() {
    char name[100];
    cout << "Enter a Word : ";
    gets(name);
    cout << "\n\n";
    cout << "The lenght of the word is "
         << str_length(name) << ".";
    cout << "\n\n";
    system("pause");
}



Swapping of Two Numbers in C++ using Pointers

In this article I would like to share with you a  program that I wrote in C++ that will interchange or swap the arrangement of numbers using pointers as our data structure.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.


Program Listing

#include <iostream>

using namespace std;

int swap(int *a, int *b)
{
    int temp=0;

    temp = *a;
    *a = *b;
    *b = temp;
}

main() {
    int a=0,b=0;
    cout << "\t\t Swap Two Numbers ";
    cout << "\n\n";

    cout << "Enter two numbers  ==> "; swap(&a,&b);
    cout << "\n\n";
    cout <<"Swap Arragement ==> "
         << a << " " << b;
    cin >> a >> b;
    cout << "\n\n";
    cout <<"Original Arragement ==> "
           << a << " " << b;

    cout << "\n\n";
    system("pause");
}

Year Level Checker Using Pointers in C++

This sample program will determine the year level of the student using pointers in C++. The code is very simple to understand and follow.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing


#include <iostream>

using namespace std;



main ( )
{

struct  {

int year_level;

}*ptr;

cout << "Enter year level :=> ";
cin >> ptr->year_level ;
cout << "\n\n";


if (ptr-> year_level == 1) {
    cout << "You are a Freshmen";
}
else if (ptr-> year_level == 2) {
    cout << "You are a Sophomore";
}
else if (ptr-> year_level == 3) {
    cout << "You are a Junior";
}
else if (ptr-> year_level == 4)
  {
    cout << "You are a Senior";
}
else {
    cout << "Invalid Option Try Again";
}
cout << "\n\n";
system("pause");
}

Age Checker in C++

A simple program  that I wrote in C++ to check if the age of the person is minor or already an adult I wrote this code while I'm still learning how to program in C++.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing

#include <iostream>

 using namespace std;

  int ages(int a) {
      if (a >= 18) {
          cout << "You are an adult";
      }
      else
      {
      cout << "Still a Minor";
      }
  }

  main() {
      int age2[1];

      cout << "Enter your age :";
            cin >> age2[0];
      cout << "\n\n";
      ages(age2[0]);
      cout << "\n\n";
      system("pause");
  }