Monday, September 14, 2015

Area of the Circle Using Servlet

In this article I would like to share with you a program that I wrote using Java Servlet that will compute the area and the circumference of a circle by accepting the radius size from the user.The program is written in a simple manner that can be useful for anyone interested in web programming using servlet in Java.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.








Sample Program Output


Program Listing

area.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Area of a Circle in Servlet</title>
</head>
<style>
label{
    display: inline-block;
    float: left;
    clear: left;
    width: 185px;
    text-align: left;
}
input {
  display: inline-block;
  float: left;
}

h3 {
   font-family:arial;
   color:blue;
   }
</style>
</head>
<body bgcolor="lightgreen">
<form name='area_circle' action='http://localhost:8080/circle/circle' method='get'>
 <div>
<font face="arial" size="3">
<h3> Area of a Circle in Servlet</h3> <br>
<label>Enter the radius </label> 
<input type='numberic' placeholder='radius' name='radius' size='7' autofocus required><br>
<br>
<input type='submit' name='submit' value='Compute Radius' title='Click here to see the result.'>
<input type='reset'  name='reset' value='Clear' title='Click here to clear text box.'>
</font> </div>
</body>
</html>


area_circle.java


package area_circle;

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class area_circle extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException , ServletException
{
PrintWriter pr=res.getWriter();
res.setContentType("text/html");
try
  
 {
double radius=Integer.parseInt(req.getParameter("radius"));

//Area = PI*radius*radius
double area = Math.PI * (radius * radius);

//Circumference = 2*PI*radius
double circumference= Math.PI * 2*radius;

pr.println("<body bgcolor='lightgreen'>");
pr.println("<font face='arial' size='3'> ");
pr.println("<h3> <font color='Blue'> Display Results </font> </h3>");
pr.println("<br>");
pr.println("The area of the circle is " + String.format("%.4f", area )+ ".<br>");
pr.println("The circumference of the circle is " + String.format("%.4f", circumference) + ".<br>");

pr.println("<br>");
pr.println("<h3><font color='Blue'>  End Program </font> </h3>");
pr.println("</font>");
}
catch(Exception e)
{
pr.println("Invalid Input value please try again");
}
} }


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>circle</display-name>
    <servlet>
<servlet-name>circle</servlet-name>
<servlet-class>area_circle.area_circle</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>circle</servlet-name>
<url-pattern>/circle</url-pattern>
</servlet-mapping>
</web-app>



Math Operations in Servlet

I just started learning how to program in Java Servlet in this article I would like to share with you a program that I called Math Operations in Servlet. What does the program will do is to accept two number values and then the program will find the sum, difference, product and quotient of the two numbers given by the user.  The program is written in a simple manner that can be useful for anyone interested in web programming using servlet in Java.

If you  have some questions please send me an email at jake.r.pomperada@gmail.comand jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

form.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Math Operations in Servlet</title>
<style>
label{
    display: inline-block;
    float: left;
    clear: left;
    width: 185px;
    text-align: left;
}
input {
  display: inline-block;
  float: left;
}

h3 {
   font-family:arial;
   color:blue;
   }
</style>
</head>
<body bgcolor="lightgreen">
<form name='math' action='http://localhost:8080/addition/addition' method='get'>
 <div>
<font face="arial" size="3">
<h3> Math Operations in Servlet</h3> <br>
<label>Enter First Number </label> 
<input type='numberic' placeholder='first number' name='val1' size='10' autofocus required><br>
<label> Enter Second Number </label>
 <input type='numeric'  placeholder='second number' name='val2' size='10' required><br>
<br>
<input type='submit' name='submit' value='Compute' title='Click here to see the result.'>
<input type='reset'  name='reset' value='Clear' title='Click here to clear text box.'>
</font> </div>
</body>
</html>


addition_two_numbers.java

package addition;

import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

public class addition_two_numbers extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException , ServletException
{
PrintWriter pr=res.getWriter();
res.setContentType("text/html");
try
  
 {
int x=Integer.parseInt(req.getParameter("val1"));
int y=Integer.parseInt(req.getParameter("val2"));

int total_sum = (x+y);
int total_product = (x*y);
int total_diff = (x-y);
int total_quotient = (x/y);

pr.println("<body bgcolor='lightgreen'>");
pr.println("<font face='arial' size='3'> ");
pr.println("<h3> <font color='Blue'> Display Computed Results </font> </h3>");
pr.println("<br>");
pr.println("The sum of  " + x + " and " + y 
 + " is "+ total_sum + ".<br>");
pr.println("The difference between  " + x + " and " + y 
 + " is "+ total_diff + ".<br>");
pr.println("The product of  " + x + " and " + y 
 + " is "+ total_product + ".<br>");
pr.println("The quotient of  " + x + " and " + y 
 + " is "+ total_quotient+ ".<br>");
pr.println("<br>");
pr.println("<h3><font color='Blue'>  End Program </font> </h3>");
pr.println("</font>");
}
catch(Exception e)
{
pr.println("Invalid Input value please try again");
}
} }



web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>addition</display-name>
    <servlet>
<servlet-name>addition</servlet-name>
<servlet-class>addition.addition_two_numbers</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>addition</servlet-name>
<url-pattern>/addition</url-pattern>
</servlet-mapping>
</web-app>



Sunday, September 13, 2015

Passing values between pages in PHP

In this article will teach you how to pass a value from pages to pages in PHP using $_POST command. The code is very basic and intended for those people that are new in PHP programming in general.

If you  have some questions please send me an email at jake.r.pomperada@gmail.comand jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

index.php

<html>
<body bgcolor="lightgreen">
<font face="arial" size="5">
<h1> Page 1 </h1>
<br><br>
<form action="welcome.php" method="post">
Name: <input type="text"  placeholder="name" name="fname" /> <br>
Age: <input type="text" placeholder="age"  name="age" /> <br>
Address  <input type="text" placeholder="add" name="add" />
</font>
<input type="submit"  value="Ok na" title="Click here to send data." />
</form>
</body>
</html>

welcome.php

<html>
<body bgcolor="lightgreen">
<font face="arial" size="5">
<h1> Page 2 </h1>
<br><br>
Welcome <?php echo $_POST["fname"]; ?>! How are you today<br>
You are <?php echo $_POST["age"]; ?> years old. <br>
Your address is <?php echo $_POST["add"]; ?><br>
</font>
</body>
</html>





Reverse a Number in a Text File in C++

This is another program that I wrote in C++ that will ask a series of integer number and then it will display the number in reverse order.

If you  have some questions please send me an email at jake.r.pomperada@gmail.comand jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.

Program Listing


#include <iostream>
#include <fstream>

using namespace std;

main() {
      int number=0;
      int remainder=0;

       ofstream file("result.txt");

       cout << "\t Reverse a Number Version 1.0";
       cout << "\n\n";
       cout<<"\n Enter the number :=> ";
       cin>>number;

       cout<<"\n The number with reverse digits is  ";
  file << "\n ===== Reverse a Number 1.0 =====";
  file << "\n\n";
  file << "\n Original Number :=> " << number;
  file << "\n";
 file << "\n Reversed Number :=> ";
       do
 {
    remainder=number%10;

      cout<<remainder;

          file << remainder;

    number=number/10;
 } while(number>0);

  file.close();

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

Sum and Average of a Number Using Text File in C++

In this article I would like to share with you a sample program on how to store values in a text file using C++ this activity I wrote during my work as a college instructor in my programming class in C++. I called this program Sum and Average of a Number Using Text file in C++.  All my programming activities that I wrote I am using Dev C++ or CodeBlock as my text editor. I hope you will find my work useful.

If you  have some questions please send me an email at jake.r.pomperada@gmail.comand jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.

Program Listing

#include <iostream>
#include <fstream>

using namespace std;

main() {

     int val[5], sum=0, average=0,list=0;
     ofstream file("result.txt");
     cout << "\t\tSUM AND AVERAGE OF THE NUMBER 1.0";
     cout << "\n\n";
     for ( list=0; list < 5; list++) {
      cout << "Enter Item No. " << list+1 << " : ";
      cin >> list[val];
     }
     cout << "\n";
     cout << "\n List of Values";
     cout << "\n\n";
     for ( list=0; list < 5; list++) {
      sum+=list[val];
      average = (sum/5);
      cout << "  " << list[val] << " ";
     }
     cout << "\n\n";
     cout << "\nThe total sum of the values is " << sum << ".";
     cout << "\nThe average of the values is " << average << ".";

     file << "\n\t ======== LIST OF VALUES  ========";
     file << "\n\n";
       for ( list=0; list < 5; list++) {
     file << "  " << list[val] << " ";

     }
     file << "\n";
     file << "\nThe total sum of the values is " << sum << ".";
     file << "\nThe average of the values is " << average << ".";
     file.close();
     cout << "\n\n";
     system("PAUSE");
}

Hello World Servlet in Java

I just started how to learn how to program a Java Servlet so the basic program that I wrote is the famous hello world program with a simple math functions in Java like square root and cube root. In this program I am using Eclipse as my text editor and Apache Tomcat 8.0 as my web server.  This program is very simple yet is show you how to write a simple Java servlet that is the fundamentals of any web applications written in Java.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.




Sample Program Output

Program Listing

package company.helloworld.servlets;

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

/**
 * Servlet implementation class HelloWorld
 */
@WebServlet("/HelloWorld")
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloWorld() {
        super();
        // TODO Auto-generated constructor stub
    }

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
double sqrtvalue = Math.sqrt(144.0);
double cuberoot = Math.cbrt(8.0);
out.println("<html><body> <font color='green'>  <h1 align='center'>Hello World Servlet </h1> "
+ "The square root of 144 is "  + sqrtvalue
+ "<br>The cube root of 8 is "  + cuberoot + "</font> </body></html>");
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

Friday, September 11, 2015

Payroll Program in JQuery

Here is a sample payroll program that I wrote using HTML,CSS and JQuery that will compute the salary of an employee in a company what is good about this program is that it automatically compute the gross pay and net pay as soon the values is being entered by the user. The code is a good tutorial in learning how to use JQuery as your javascript library in creating web applications.

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

Program Listing

<!-- index.htm                                                                                             -->
<!-- September 11, 2015     Friday                                                             -->
<!-- Written By: Mr. Jake R. Pomperada, MAED-IT                                 -->
<!-- jakerpomperada@yahoo.com and jakerpomperada@gmail.com  -->

<html>
  <head>
     <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
 <head>
   <title>Basic Math Operations in JQuery</title>
<style type="text/css">
.form-style-3{
    margin: auto;
    width: 60%;
   padding: 10px;
max-width: 420px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
color: red;
font-weight: bold;
font-size: 16px;
}
.form-style-3 label{
display:block;
margin-bottom: 10px;
}
.form-style-3 label > span{
float: left;
width: 180px;
color: blue;
font-weight: bold;
font-size: 15px;
text-shadow: 1px 1px 1px #fff;
}
.form-style-3 fieldset{
border-radius: 12px;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
margin: 0px 0px 0px 0px;
border: 5px solid red;
padding: 20px;
background: lightgreen;

box-shadow: inset 0px 0px 15px black;
-moz-box-shadow: inset 0px 0px 15px black;
-webkit-box-shadow: inset 0px 0px 15px black;
}
.form-style-3 fieldset legend{
color: blue;
border-top: 2px solid red;
border-left: 2px solid red;
border-right: 2px solid red;
border-radius: 6px 6px 0px 0px blue;
-webkit-border-radius: 6px 6px 0px 0px;
-moz-border-radius: 6px 6px 0px 0px;
background: yellow;
padding: 0px 12px 3px 12px;
box-shadow: -0px -1px 2px black;
-moz-box-shadow:-0px -1px 2px black;
-webkit-box-shadow:-0px -1px 2px black;
font-weight: bold;
font-size: 18px;
}
.form-style-3 textarea{
width:320px;
height:100px;
}
.form-style-3 input[type=text],
.form-style-3 input[type=date],
.form-style-3 input[type=datetime],
.form-style-3 input[type=number],
.form-style-3 input[type=search],
.form-style-3 input[type=time],
.form-style-3 input[type=url],
.form-style-3 input[type=email],
.form-style-3 select, 
.form-style-3 textarea{
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border: 2px solid blue;
outline: none;
color: blue;
padding: 5px 8px 5px 8px;
box-shadow: inset 1px 1px 4px black;
-moz-box-shadow: inset 1px 1px 4px black;
-webkit-box-shadow: inset 1px 1px 4px black;
background: yellow;
width:30%;
font-weight: bold;
font-size: 15px;

}
</style></head>
<script>
 $(document).ready(function() {
   function compute_salary() {
          var days_worked = $('#days').val();
          var rate_per_day = $('#rates').val();
 var tax = $('#tax').val();
 
          var total_gross_salary = days_worked * rate_per_day;
 
 var total_netpay = (total_gross_salary - tax);
 
          $('#salary').val(total_gross_salary.toFixed(2));
 $('#net_pay').val(total_netpay.toFixed(2));
        }

        $('#days, #rates,#tax').change(compute_salary);
 });
</script>
<body>
 <div class="form-style-3">
<form>
<br><br>
<fieldset><legend>PAYROLL PROGRAM IN JQUERY</legend><br>
<label for="field1"><span>Number of Day's Work<span class="required"></span></span>
 &nbsp;&nbsp;<input type="number" name="days"  id="days" class="input-field" name="field1"  autofocus /> </label>
<label for="field1"><span>Salary Rate Per Day<span class="required"></span></span>
$<input type="number" name="rates" id="rates" class="input-field" name="field1"   /> <label> 
<br> DISPLAY RESULTS <br><br>

<label for="field1"><span> Gross Pay  <span class="required"></span></span>
$<input type="text" name="salary" id="salary" class="salary" readonly/> </label> 
<label for="field1"><span> TAX <span class="required"></span></span>
$<input type="text" name="tax" class="tax" id="tax"/> </label> 
<label for="field1"><span> Net Pay  <span class="required"></span></span>
$<input type="text" name="net_pay" id="net_pay" class="net_pay" readonly/> </label> 
  <br> <font color="blue">
  Created By Mr. Jake R. Pomperada
  </font>
<center>
</fieldset>
</form>
</div>
 </body>
</html>