Sunday, June 21, 2015

Math Operations in JSP

In this short article I would like to share with you a program that I wrote in Java Server Pages or JSP I called this program Math Operations in JSP. What program does is to ask the user to enter two numbers and then it will find the sum, product, difference and quotient of two numbers. JSP is the scripting language used in J2EE programming in Java it is similar to PHP, Ruby or Perl but it uses more Java programming language statements. 

In this program I am using Java EE IDE provided freely by Eclipse.org and Apache Tomcat as my application server. I hope you will find my work useful in learning web programming using Java Server Pages or JSP.

If you have some questions please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com.

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

Thank you very much and Happy Programming.



Sample Program Output


Program Listing

<HTML>
    <HEAD>
        <TITLE>Math Operations in JSP</TITLE>
    </HEAD>

    <BODY BGCOLOR="lightgreen">
        <H1>Basic Math Operations in JSP</H1>
             <FORM NAME="form1" METHOD="POST">
       Enter first value  : <input type="text" name="value1" size="10" ><br>
       Enter second value : <input type="text" name="value2" size="10"><br>
           
           <br><br>
            <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Solve">
        </FORM>
<%
int x=  Integer.parseInt(request.getParameter("value1"));
int y = Integer.parseInt(request.getParameter("value2"));
   
  int sum = (x+y);
  int difference = (x-y);
  int product = (x*y);
  int quotient = (x/y);
%>
         <% 
            if(request.getParameter("submit") != null) {
            out.print("The sum of " + x + " and " + y + "  is  " + sum + ". <br>");   
            out.print("The difference of " + x + " and " + y + "  is  " + difference + ". <br>"); 
            out.print("The product of " + x + " and " + y + "  is  " + product + ". <br>");   
            out.print("The quotient of " + x + " and " + y + "  is  " + quotient + ". <br>");  
        %>
        
        <%
            }
        %>
        
    </BODY>
</HTML>



Thursday, June 18, 2015

Greeter Program in Java Server Pages or JSP

In this article I would like to share with you a simple greeter program that I wrote using Java Server Pagers or JSP scripting language that is based in Java programming language. What does the program will do is very simple it will ask the user its first and last name and then say hello to the user.

I just wrote this code as a learning aid in my study of JSP in J2EE programming for web in Java. I hope beginners like me will benefited from my work.

If you have some questions please send me an email at jakerpomperada@gmail.comand 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

<html>
<head>
<title>Greeter in JSP</title>
</head>
<body>
<form action="test.jsp">
<table border="1">
<tr>
<td>Enter First Name</td>
<td><input type="text" name="first_name" id="first_name" value=""></td>
<td>Enter Last Name</td>
<td><input type="text" name="last_name" id="last_name" value=""></td>
<td><input type="Submit" value="Click to Submit"></td>
</tr>
</table>
</form>
<br>
<%
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
if (first_name == null ||  last_name == null) {

} else { 
if (first_name.length() == 0 || last_name.length() ==0) {
%>
<b>myText is empty</b>
<% } else { %>
<b>Hello <%= first_name %> <%= last_name %></b>
<%
}
}
%>
</body>
</html> 

Sunday, June 7, 2015

Cars Collections Information System in PHP and XML

A simple application that I wrote in PHP and XML that will give information to the user about the classic car collections in the past. The data is being stored in XML file  and I retrieve the records using PHP as my programming language.

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.






Sample Program Output

index.php


<!-- Selecting a value in PHP and XML           -->
<!-- June 7, 2015   Sunday                      -->
<!-- Written By: Mr. Jake R. Pomperada, MAED-IT -->
<!-- Email Address: jakerpomperada@gmail.com    -->
<!--              : jakerpomperada@yahoo.com    -->
<html>
<title>Car Collection in PHP and XML
</title>
<style>
h1 {
    font-family:arial;
color:blue;
};

</style>

<body bgcolor="yellow">
<br><br>
<h1>
Car Collection in PHP and XML
</h1>
<form method="post" action="">
<select id="select" class="select" name="filter1" style="text-align:center;">
<option value="1" <?php if(@$_POST['filter1'] == '1') { echo 'selected = \"selected\"'; } ?>>Car Series One</option>
<option value="2"  <?php if(@$_POST['filter1'] == '2') { echo 'selected = \"selected\"'; } ?>>Car Series Two</option>
</select>
<input type="submit" id="submit" name="submit" value="ok" title="Click here to select your choice.">
</form>
<br>
<?php 
if(isset($_POST['submit'])){

if($_POST['filter1'] == "1")
{
$xml = simplexml_load_file("car1.xml");

         foreach($xml->children() as $automobile)
              {
                  echo "<font color='blue' face='arial' size='3'>Car Name   : ".$automobile->name."<br />";
                  echo "Year    : ".$automobile->year." <br />";
 echo "Price  : ".$automobile->price." <br />";
        echo " Description : ".$automobile->description." <br /> </font>";
echo "<br><br>";
                }             
        }

else if ($_POST['filter1'] == "2")
{
$xml = simplexml_load_file("car2.xml");
       
  foreach($xml->children() as $automobile)
              {
               echo "<font color='blue' face='arial' size='3'>Car Name   : ".$automobile->name."<br />";
               echo "Year    : ".$automobile->year." <br />";
  echo "Price  : ".$automobile->price." <br />";
      echo " Description : ".$automobile->description." <br /> </font>";
   echo "<br><br>";
               
             }
  }

}
?>

</body>
</html>


car1.xml

<?xml version="1.0"?>
<cars>
   <automobile id="1">
      <name>Studebaker President Eight Roadster </name>
      <year> 1929 </year>
       <price>$1,895</price>
       <description>
   Studebaker 1929 President Eight Roadster seats two
in the comfortable front seats and two in the Rumble
, 115 Horsepower engine, hydraulic shock absorbers, wire wheels,
spare tire and bumpers are additional 
to the price. 
   </description>
   </automobile>

   <automobile id="2">>
      <name>Chevrolet</name>
      <year> 1924 </year>
       <price>$525.00</price>
       <description>
   By the middle of the decade Chevrolet had joined the auto mass production 
era and although the cars were more expensive than Ford's at the time many of 
those things that cost extra on the Ford were included, the basic specs were Standard 
Transmission with 3 forward and 1 reverse gear, Standard Electrical System which 
included electric starter, electric lights front and rear, large radiator and fan, 
speedometer, ammeter, oil pressure gauge,choke pull, starting switch, plus an extra tire 
rim was included mounted on the rear of the car
   </description>
   </automobile>
   
    <automobile id="3">>
      <name>Buick Marquette </name>
      <year> 1930</year>
       <price>$965.00</price>
       <description>
 The Buick Marquette features a 67.5 horsepower engine that 
 races from 0 to 60 in just 31 seconds. The Buick Marquette offers 
 easy vibration free motoring at 70 MPH, also featuring 4 wheel brakes 
 working on 12 inch drums, 4 hydraulic shock absorbers ensure a 
 smooth ride over all surfaces. Bodies are manufactured by Fisher 
   </description>
   </automobile>
   
   <automobile id="4">>
      <name>Gray Motor Company Coach </name>
      <year> 1923</year>
       <price>$785</price>
       <description>
1923 Gray Motor Company Coach features a four cylinder engine, 
3 speed transmission, lightening ignition from Westinghouse, 
4 wheel shock absorbing springs,comes in 4 options starting at $495 for
the Roadster to the 4 door sedan costing $835.00 
   </description>
   </automobile>
     

</cars>

car2.xml

<?xml version="1.0"?>
<cars>
   <automobile id="1">
      <name>Dodge Brothers De-Luxe Sedan   </name>
      <year> 1926</year>
       <price>$1,075</price>
       <description>
   Dodge Brothers auto's are known for their top quality materials used 
in each and every auto with the finest Chrome Vanadium used from the Axles 
to the engine, and Mohair Interior of the finest quality offering long life 
and dependability for your purchase. 
   </description>
   </automobile>

   <automobile id="2">>
     <name>Cadillac 90 Degree </name>
      <year> 1927</year>
       <price>$2,995</price>
       <description>
   Cadillac Prestige Pointing the way to Luxury, Distinction and motor car value 
that brings abiding satisfaction.
   </description>
   </automobile>
   
    <automobile id="3">
       <name>Chrysler 75 Roadster </name>
      <year> 1928</year>
       <price>$1,555</price>
       <description>
 The new Chrysler 75 Roadster for 1928, one the most attractive cars of 
 our times made by master craftsmen entering a new era in design and craftsmanship. 
   </description>
   </automobile>
   
   <automobile id="4">
     <name>Horse Drawn Auto Seat Top Buggy  </name>
      <year> 1905</year>
       <price> $86.70 </price>
       <description>
   I have included this example because it shows how traditional 
horse drawn carriage manufacturers were trying to survive, one
of the most interesting selling points for this carriage was that
the wheel base size was the same as most of the smaller autos of the 
day 4ft 8 inches, and if you look the sitting position and layout was
very similar although higher off the ground. 
  </description>
      </automobile>
</cars>


Selecting a Value in PHP and XML

In this sample program I will show you how to select a value from a drop down menu in HTML and extract the data in an XML file. This will be my first time to write a program that uses XML and PHP. According to Wikipedia.org XML is defined as Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format which is both human-readable and machine-readable. It is defined by the W3C's XML 1.0 Specification and by several other related specifications, all of which are free open standards.

The code is very easy to follow and understand I hope you will find my work useful in your programming projects and assignments. If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

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

Thank you very much and Happy Programming.




Program Listing

index.php

<!-- Selecting a value in PHP and XML           -->
<!-- June 7, 2015   Sunday                      -->
<!-- Written By: Mr. Jake R. Pomperada, MAED-IT -->
<!-- Email Address: jakerpomperada@gmail.com    -->
<!--              : jakerpomperada@yahoo.com    -->
<html>
<title>Selecting a value in PHP and XML
</title>
<style>
h1 {
    font-family:arial;
color:blue;
};

</style>
<body bgcolor="lightgreen">
<br><br>
<h1>
SELECTING A VALUE IN PHP AND XML
</h1>
<form method="post" action="">
<select id="select" class="select" name="filter1" style="text-align:center;">
<option value="1" <?php if(@$_POST['filter1'] == '1') { echo 'selected = \"selected\"'; } ?>>First Record</option>
<option value="2"  <?php if(@$_POST['filter1'] == '2') { echo 'selected = \"selected\"'; } ?>>Second Record</option>
<option value="3" <?php if(@$_POST['filter1'] == '3') { echo 'selected = \"selected\"'; } ?> >Third Record</option>
<option value="4" <?php if(@$_POST['filter1'] == '4') { echo 'selected = \"selected\"'; } ?>>Fourth Record</option>
</select>
<input type="submit" id="submit" name="submit" value="ok" title="Click here to select your choice.">
</form>
<br>
<?php 
if(isset($_POST['submit'])){
if($_POST['filter1'] == "1")
{
$users = simplexml_load_file("1.xml");

            foreach ($users->person as $item)
              {
   
                if ($item->id == 1)  {
                  echo "<font color='blue' face='arial' size='5'>Title   : ".$item->title."<br />";
                  echo "Name    : ".$item->name." <br />";
        echo "Address : ".$item->address." <br /> </font>";
                }
             }
        }
else if ($_POST['filter1'] == "2")
{
$users = simplexml_load_file("1.xml");

            foreach ($users->person as $item)
              {
   
                if ($item->id == 2)  {
                  echo "<font color='blue' face='arial' size='5'>Title   : ".$item->title." <br />";
                  echo "Name    : ".$item->name." <br />";
         echo "Address : ".$item->address." <br /> </font>";
                }
             }
  }
else if ($_POST['filter1'] == "3")
{
    $users = simplexml_load_file("1.xml");

            foreach ($users->person as $item)
              {
   
                if ($item->id == 3)  {
                  echo "<font color='blue' face='arial' size='5'> Title   : ".$item->title." <br />";
                  echo "Name    : ".$item->name." <br />";
         echo "Address : ".$item->address."</font> <br />";
                }
             }
 }  
else if ($_POST['filter1'] == "4")
{
 $users = simplexml_load_file("1.xml");
       foreach ($users->person as $item)
              {
   
                if ($item->id == 4)  {
                  echo "<font color='blue' face='arial' size='5'> Title   : ".$item->title." <br />";
                  echo "Name    : ".$item->name." <br />";
         echo "Address : ".$item->address."</font> <br />";
                }
             }
 
  } 
else {
     echo "No Selected Records.";
}

 }
?>

</body>
</html>

1.xml

<?xml version="1.0"?>
<information>
   <person>
     <id> 1 </id>
     <title> First Record </title>
<name> Ana Maria Tan </name>
<address> Cubao, Quezon City </address>
   </person>

  <person>
     <id> 2 </id>
     <title> Second Record </title>
<name> David Smith </name>
<address> Washington Street, Iloilo City </address>
   </person>
   
   
  <person>
    <id> 3</id>
     <title> Third Record </title>
<name> Linda Lee </name>
<address> Hongkong, China </address>
   </person>
   
  
  <person>
     <id> 4 </id>
     <title> Fourth Record </title>
<name> Adam Stone </name>
<address> West Avenue, United Kingdom </address>
   </person>
 </information>


Sunday, May 31, 2015

Reverse a Word in Turbo Pascal

In this article I will share a code that I wrote during my college days using Turbo Pascal I called this program reverse a word. What does this program will do is to ask the user a word or string and then it will display the word in reverse order.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.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


Program Reverse;
Uses Crt;
Var  InpStr : String;
     OutStr : String;
     Size, I : Integer;


Begin
  Clrscr;
  Write('REVERSE A WORD');
  Writeln; Writeln;
  Write('Please Enter A String :=> ');
  Readln(InpStr);
  Size := Length(InpStr);
  For I := 1 To Size Do
   Begin
    OutStr[I] :=  InpStr[Size - (I - 1)];
    OutStr[0] := Chr(Size);
   End;
   Writeln;
   Writeln;
   Write('The Reversed String is ' ,OutStr,'.');
   Readln;
End.




Finding the Area of a Circle Using BASH

In this article I would like to share with you a sample program that I wrote using Bourne Again Shell or BASH scripting language that is being used in UNIX and LINUX operating system. What does the program will do is to ask the user to enter the radius of the circle and then our program will compute the area of the circle.

The script is very simple and short is very easy to understand and read. If you have some questions regarding about my works feel free to send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippine who wish to contact me can reach me through my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output


Program Listing


#!/bin/bash

echo -e "\n\n"
echo -e "\t\t FINDING THE AREA OF THE CIRCLE IN BASH"
echo -e "\n"
read -p  "Kindly give the radius of a circle :=> " radius
echo -e "\n"

area=$(echo "scale=2;3.14159 * ($radius * $radius)" | bc)

printf "The area of the circle is %0.2f." $area
echo -e "\n"
echo -e "Thank you for using this program."




Payroll Database System in C++

In this article I will share with you a program that I wrote in C++ that will manage the payroll system of the employees in the company I called this program Payroll Database System in C++ that uses text file to save the records of the employees. In this program I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler that is very available over the Internet for free because it is an open source.

If you have some questions regarding about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines who wish to contact me can reach me thru my mobile number at 09173084360.

Thank you and Happy Programming.



Sample Program Output

Program Listing

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<sstream>
#include<iomanip>

using namespace std;

void append();
void find();
void read();
void whattodo();
void loop();
void about();
void mainfind();

int main()
{
    system("Color 2F");

    cout<<"\t\t\t------------------"<<endl;
    cout<<"\t\t\t* Payroll System *"<<endl;
    cout<<"\t\t\t------------------"<<endl;
    whattodo();
    getch();
    return 0;
}
void whattodo()
{

    int choice;

    loop:


   cout << "\n\t\t Created By: Mr. Jake R.Pomperada, MAED-IT";
    cout << "\n\n";

    cout<<"Type the number of the command you want to perform:"<<endl;
    cout<<endl;
    cout<<"[1] Append Record"<<endl;
    cout<<"[2] Browse all file contents"<<endl;
    cout<<"[3] Find a record"<<endl;
    cout<<"[4] Exit"<<endl;
    cout<<"[5] About"<<endl;
    cout<<""<<endl;

    cin>>choice;

    cout<<""<<endl;
     if (choice==1)
        {
            system("cls");
            append();
            cout<<endl;
            loop();
        }
       else if (choice==2)
        {
            system("cls");
            read();
            cout<<endl;
            loop();
        }
        else if(choice==3)
        {
            system("cls");
            mainfind();
            loop();
        }
        else if(choice==4)
        {
            system("cls");
            cout<<"Goodbye.";
        }
        else if(choice==5)
        {
            system("cls");
            about();
        }
        else
        {
            cout<<"Invalid! Try again."<<endl;
            goto loop;
        }

    system ("cls");
}

void append()
{
     string emp_first, emp_last;
     string id;
     double salary=0.00;
     ofstream fout;
     fout.open("myRecord.txt",ios::app);    // open file for appending



     cout<<"Enter Employee Id: ";
      cin >> id;

      cout << "\n";
     cout<<"Enter Employee Name: ";
     cin >> emp_first >> emp_last;

     cout<<"Enter Employee Salary:";
     cin >> salary;
     fout << setiosflags(ios::fixed | ios :: showpoint)
        << setprecision(2);
            fout<<  id<< ", " << emp_first
                << " " << emp_last << " , " << salary << endl;
            fout << fixed;

     fout.close( );       //close file


}


void read()
{
    string line;
    ifstream x ("myRecord.txt");

    if (x.is_open())
    {
    while(!x.eof())
    {

    cout<<endl;
    getline(x,line);
    cout<<line<<endl;

    }
    x.close();
    }
    else
    cout<<"Cant open file."<<endl;
}
void find()
{
    ifstream data("myRecord.txt");
    string item,line;
    int x=0;
    int y=0;
    string id;

    cout<<endl;
    cout<<"Enter Employee Id: ";
    cin>>id;
    cout<<""<<endl;

    while(!data.eof())
    {
        getline(data,line);
        string item_array[10];
        stringstream stream(line);
        x=0,y=0;

        while(getline(stream,item,','))
        {
            item_array[x]=item;
            x++;
            item_array[y]=item;
            y++;
        }

        if(item_array[0]==id)
        {
            cout<<setfill('-')<<left<<setw(10)<<"\t\t\tID:   " <<right<<"  "<<item_array[0]<<endl;
            cout<<setfill('-')<<left<<setw(10)<<"\t\t\tName: " <<right<<" "<<item_array[1]<<endl;
            cout<<setfill('-')<<left<<setw(10)<<"\t\t\tRate: " <<right<<" "<<item_array[2]<<endl;
            cout<<""<<endl;
        }
    }
    data.close();
}
void loop()
{
    string choice;
    cout<<""<<endl;
    cout<<"Do you want to make another choice?(yes/no)";
    cin>>choice;
    system("cls");
    cout<<""<<endl;
        if (choice=="yes")
        {
            whattodo();
        }
        else if(choice=="no")
        {
            cout<<"Goodbye.";
        }
}
void about()
{
    cout<<endl;
    cout<<"                    ABC Computer Training Center"<<endl;
    cout<<"                     1st Floor, Victoria Center"<<endl;
    cout<<"                Bacolod City, Philippines Tel.No. 4335081"<<endl;
    cout<<"                          Endterm Exams"<<endl;
    cout<<""<<endl;
    cout<<"                 Professor       : Sir Jake R. Pomperada"<<endl;
    cout<<""<<endl;
    cout<<"                 Project Manager : Juan Dela Cruz"<<endl;
    cout<<""<<endl;
    cout<<"                 Program Designer: Pedro Santa Maria"<<endl;
    cout<<""<<endl;
    loop();
}
void mainfind()
{
    find();

    string id;
    cout<<"Type back to go to main menu."<<endl;
    cout<<"Press any key to find another profile."<<endl;
    cin>>id;
    system("cls");

    if (id=="back")
    {
        whattodo();
    }
    else
    {
        mainfind();
        find();
    }
}