Sunday, July 12, 2015

Student Tuition Fee Solver in PHP

A simple program that I wrote in PHP in my web programming class in college I called this program Student Tuition Fee Solver in PHP that will compute the payment of the student based on the course and units being enrolled by the student in school.

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.



Sample Program Output

Program Listing


<!-- stud.php -->
<!-- Created By: Mr. Jake R. Pomperada, MAED-IT -->
<!-- December 14, 2012 Thursday -->
<!-- Tool : PHP -->

 <html> 
 <head><title>Student Tuition Fee Solver</title>
 
 <STYLE type="text/css">
     
      h3 { 
        font-sytle: comic sans ms;
    text-align:center;
        color: white;                /* text color is white */ 
        background: red;            /* Content, padding will be blue */
        
        padding: 12px 0px 12px 12px; /* Note 0px padding right */
        list-style: none             /* no glyphs before a list item */
                                     /* No borders set */
      }
     
    </STYLE>
 </head> 
 <?php
 error_reporting(0);

$fname = trim($_REQUEST['fname']);
$lname = trim($_REQUEST['lname']);
$gender = strip_tags($_POST['gender']);

$course = trim($_REQUEST['course']);

$units= trim($_REQUEST['units']);

$cost = trim($_REQUEST['cost']);
$paid2 = trim($_REQUEST['paid']); 

$paid = number_format($paid2,2,'.',',');

$solve = ($units * $cost);

$total_cost = number_format($solve,2,'.',',');
// Clear the text field

if ($_REQUEST['clear']){
   $fname="";
   $lname="";
   $gender="";
   $total_cost="";
   $course="";
   $units="";
   $cost="";
   $paid2="";
   $paid="";
     
}

if ($_REQUEST['change']){

$change3 = ($paid2 - $solve);

$change =number_format($change3,2,'.',',');
}

?>
 <body bgcolor="green"> 
 <font face="comic sans ms">
 <h3>Student Tuition Fee Solver</h3> 
  <form action="" method="post"> 
 <fieldset>
 <table> 
 
 <tr><td><font color="white">First Name </font> </td>  <td> </td> <td>
 <input type="text" name="fname"  value="<?php echo $fname; ?> " size="30" /></td> 
 <td ><font color="white"> Last Name </font> </td>  <td> </td> <td >
 <input type="text" name="lname" value="<?php echo $lname; ?>" size="30" /></td>
 </tr>   
 
 <tr><td><font color="white">Gender </font></td>   <td> </td> <td>

   <font color="white"> 
 
   Male </font> <input type="radio" value="Male" name="gender" id="gender" 
<?php  if ($_POST ['gender']=='Male') echo 'checked ="checked"' ; ?>  />
  <font color="white">    Female </font><input type="radio" value="Female" name="gender" id="gender"
 <?php  if ($_POST ['gender']=='Female') echo 'checked ="checked"' ; ?>  />
  </td>
     
  <td> <font color="white"> Course  </font> </td>    <td> </td>
  <td>
       <select name="course" id="course">
<option value="Bachelor of Science in Computer Science">
Bachelor of Science in Computer Science</option>
<option value="Bachelor of Science in Information Technology">
Bachelor of Science in Information Technology</option>
<option value="Bachelor of Science in Information System">
Bachelor of Science in Information System </option>
 <option value="Bachelor of Science in Information Management">
 Bachelor of Science in Information Management </option>
 <option value="Bachelor of Science in Software Engineering">
 Bachelor of Science in Software Engineering </option>
 <option value="Bachelor of Science in Accountancy">
 Bachelor of Science in Accountancy </option>
 <option value="Bachelor of Science in Management Accounting">
 Bachelor of Science in Management Accounting </option>
 <option value="Bachelor of Science in Management ">
 Bachelor of Science in Management </option>
 <option value="Bachelor of Science in Management Accounting">
 Bachelor of Science in Management Accounting </option>
  <option value="Bachelor of Science in Banking and Finance">
 Bachelor of Science in Banking and Finance</option>
 <option value="Bachelor of Science in Computer Engineering">
 Bachelor of Science in Computer Engineering</option>
 <option value="Bachelor of Science in Chemical Engineering">
 Bachelor of Science in Chemical Engineering</option>
 <option value="Bachelor of Science in Civil Engineering">
 Bachelor of Science in Civil Engineering</option>
 <option value="Bachelor of Science in Industrial Engineering">
 Bachelor of Science in Industrial Engineering</option>
 <option value="Bachelor of Science in Nursing">
 Bachelor of Science in Nursing</option>
 <option value="Bachelor of Science in Pharmacy">
 Bachelor of Science in Pharmacy</option>
 <option value="Bachelor of Science in Medical Technology">
 Bachelor of Science in Medical Technology</option>
</select> 
<script type="text/javascript">
  document.getElementById('course').value = "<?php echo $_POST['course'];?>";
</script>

   </td>                    

  </tr> 
      <tr><td><font color="white">Number of Units </font> </td>  <td> </td> <td>
 <input type="text" name="units"  value="<?php echo $units; ?> " size="30" /></td> 
        <td ><font color="white">Cost Per Unit </font></td>  <td> </td> <td >
<input type="text" name="cost"  value="<?php echo $cost; ?> "  size="30" /></td>                                                                            
                        
 </tr> 
 <tr><td><font color="white">Tuition Fee </font> </td>  <td> </td> <td>
 <input type="text" name="fee"  value="<?php echo $total_cost; ?> " size="30" /></td> 
        <td ><font color="white">Amount Paid </font> </td>  <td> </td> <td >
<input type="text" name="paid"  value="<?php echo $paid2; ?> " size="30" /></td>                                                                            
                        
 </tr> 
 <tr><td><font color="white">Change  </font> </td>  <td> </td> <td>
 <input type="text" name="change2"  value="<?php echo $change; ?> " size="30" /></td> 
 </tr>
 <tr><td colspan="2" align="center"><input type="submit" name="compute" value="Solve Tuition"
    title="Click here to compute the tuition fee of the student." />

<td colspan="2" align="center"><input type="submit" name="change" value="Solve Change"
    title="Click here to compute the payment of the student." />
<td colspan="2" align="center"><input type="submit" name="clear" value="Clear Textbox"
    title="Click here to clear the text box." />
</td>
</tr>
<?php
 error_reporting(0);

$fname = trim($_REQUEST['fname']);
$lname = trim($_REQUEST['lname']);
$gender = $_POST['gender'];
$course = $_POST['course'];


$units= trim($_REQUEST['units']);

$cost = trim($_REQUEST['cost']);
$paid2 = trim($_REQUEST['paid']); 

$paid = number_format($paid2,2,'.',',');

$solve = ($units * $cost);

$total_cost = number_format($solve,2,'.',',');

// Clear the text field

if ($_REQUEST['clear']){
   $fname="";
   $lname="";
   $gender="";
   $total_cost="";
   $course="";
   $units="";
   $cost="";
   $paid2="";
   
     
}

if ($_REQUEST['change']){

$change3 = ($paid2 - $solve);
$change =number_format($change3,2,'.',',');
}


?>
<tr><td><font color="white">  Name           : <?php echo  ucwords($fname) . " " . ucwords($lname); ?>  </font> </td> </tr>
<tr><td><font color="white">  Gender         : <?php echo trim($gender) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Course         : <?php echo trim($course) ?>  </font> </td> </tr>
 <tr><td><font color="white"> No. of Units   : <?php echo trim($units) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Cost Per Unit  : $<?php echo trim($cost) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Tuition Fee    : $<?php echo trim($total_cost) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Amount Paid    : $<?php echo trim($paid2) ?>  </font> </td> </tr>
 <tr><td><font color="white"> Change         : $<?php echo trim($change) ?>  </font> </td> </tr>
 </table> 
 </fieldset>
</font>
 </form>     
 </body> 
 </html> 

Student Grading System in PHP and MySQL

Most of my career as programmer spend developing programs using PHP and MySQL. In this article I would like to share my program that I wrote a long time ago I called this program Student Grading System in PHP and MySQL. This program will compute and store the grades of the student in MySQL.

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.



Sample Program Output

Program Listing

grade.php


<?php
  /* Student Grade System
     Author : Jake R. Pomperada
Date   : October 5, 2011 Wednesday
Tool   : PHP/MySQL
 */  

  // Block any possible error from the browser
  error_reporting(0);
?>
<?php 
   
     $name =$_REQUEST['name']; 
$course = $_REQUEST['course']; 
$sex = $_REQUEST['sex'];
$department = $_REQUEST['department'];   
$subject =$_REQUEST['subject']; 
$contact =  $_REQUEST['contact']; 
       
   
  if (isset($_REQUEST['solve']))
       {
  
  $prelim = $_REQUEST['prelim'];
  $midterm = $_REQUEST['midterm'];
       $final = $_REQUEST['final']; 
  
   $solve1 = ($_REQUEST['prelim'] * 0.2);
$solve2 = ($_REQUEST['midterm'] * 0.3);
$solve3 = ($_REQUEST['final'] * 0.5);
$add = ($solve1 + $solve2 + $solve3);
$endterm = round($add);
if ($add >= 75) 
  {
          $remarks = "PASSED";
        }
       else {
           $remarks = "FAILED";
       }
}
if (isset($_REQUEST['clear']))
       {
  $name = ""; 
  $course = ""; 
    $subject="";
  $department = ""; 
  $contact =  "";  
  $prelim = "";
  $midterm = "";
       $final = ""; 
       $endterm = "";
  $remarks = ""; 
       }
  
if (isset($_REQUEST['save']))
       {
 
$name = strtoupper($_REQUEST['course']);
$course = strtoupper($_REQUEST['course']);
$deparment = strtoupper($_REQUEST['department']);
$sex = strtoupper($_REQUEST['sex']);
$contact = $_REQUEST['contact'];
$prelim = $_REQUEST['prelim'];
$midterm = $_REQUEST['midterm'];
$final = $_REQUEST['final'];
$endterm = $_REQUEST['endterm'];
$remarks = strtoupper($_REQUEST['remarks']);

//CONNECT TO DATABASE--------------------
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("grade", $con);
 
/*
 *  Specify the field names that are in the form. This is meant 
 *  for security so that someone can't send whatever they want 
 *  to the form.
 */
$allowedFields = array(
'name',
'course',
'subject',
'department',
'contact',
'prelim',
'midterm',
'final',
'endterm',
'remarks'
);
// Specify the field names that you want to require...
$requiredFields = array(
'name',
'course',
'subject',
'department',
'contact',
'prelim',
'midterm',
'final'
);

$errors = array();
foreach($_POST AS $key => $value)
{
// first need to make sure this is an allowed field
if(in_array($key, $allowedFields))
{
$$key = $value;
// is this a required field?
if(in_array($key, $requiredFields) && $value == '')
{
$errors[] = "The field $key is required.";
}
}
}

// were there any errors?
if(count($errors) > 0)
{
$errorString = '<p>There was an error processing the form.</p>';
$errorString .= '<ul>';
foreach($errors as $error)
{
$errorString .= "<li>$error</li>";
}
$errorString .= '</ul>';

echo  $errorString;
  }
  else {
  $sql = "INSERT INTO info ";
  $sql .= " (name,course,subject,department,gender,contact,prelim";
  $sql .= "  ,midterm,final,endterm,remarks)";
  $sql .= "VALUES";
  $sql .= "('$name', '$course', '$subject', '$department', '$sex'";
  $sql .= " ,'$contact','$prelim','$midterm','$final','$endterm','$remarks')";
  
if(!$b=mysql_query($sql)){
echo mysql_error();
}
else {
   echo "<center>";
echo "<h4> Record is Successfully added in the Database.</h4>";
echo "</center>";
   }
    }
  }
?>
 
<html>
<head>
 <STYLE type="text/css">
     
      h2 { 
        text-align:center;
color: white;                /* text color is white */ 
        background: green;            /* Content, padding will be blue */
        margin: 12px 12px 12px 30px;
        padding: 12px 0px 12px 12px; /* Note 0px padding right */
        list-style: none             /* no glyphs before a list item */
                                     /* No borders set */
      }
     
    </STYLE>
</head>
<body>
<h2> <marquee direction=left behavior=alternate>
 ABC College Student Grading System </marquee> </h2>
<br>
<FORM NAME="form1" METHOD="POST" ACTION="">
<TABLE BORDER="0">
  <tr> </tr> <tr> </tr>
  <TR>
    <TD>Student Name</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="name" SIZE="30"MAXLENGTH=30
   value="<?php echo $name; ?>">
 
 
      <TD>  Course</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="course" SIZE="33" MAXLENGTH=35
 value="<?php echo $course; ?>">
 </TD>
    </TR>
    <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
  
  <TR>
    <TD>Prelim Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="prelim" SIZE="1"  MAXLENGTH=3
  value="<?php echo $prelim; ?>">
  
</TD>
<TD>Subject</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="subject" SIZE="35" MAXLENGTH=35
   value="<?php echo $subject; ?>">
 </TD>
      </TR> 
     <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
  <TR>
    <TD>Midterm Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="midterm" SIZE="1" MAXLENGTH=3
   value="<?php echo $midterm; ?>">
</TD>
    <TD>Department</TD>
     <TD>
      <INPUT TYPE="TEXT" NAME="department" SIZE="40" MAXLENGTH=40
  value="<?php echo $department; ?>">
  </TD>
  </TR>
     <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
<TR>
    <TD>Final Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="final" SIZE="1" MAXLENGTH=3
  value="<?php echo $final; ?>">
</TD>
     <TD>Gender</TD>
<td> <select name="sex"> 
<option>Male</option>
<option>Female</option>
</select>
      </td>
   </tr>
<tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
<tr>
   <TD>Endterm Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="endterm" SIZE="1" MAXLENGTH=3
   value="<?php echo $endterm; ?>" READONLY>
</TD>
    <TD>Contact Number</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="contact" SIZE="15" MAXLENGTH=15
 value="<?php echo $contact; ?>">
 </TD>
</tr>
    <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
  <tr>
<TD>Remarks</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="remarks" SIZE="10" 
   value="<?php echo $remarks; ?>" READONLY>
 </TD>
     </TR>
    </TABLE>
  <!-- End of the Table -->
  
<P><input type="submit" name="solve" value="Compute"> 
<input type="submit" name="clear" value=" Clear ">
<input type="submit" name="save" value=" Save  ">
</P>
</FORM>
</body>
</html>


grade.sql

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 05, 2011 at 12:11 PM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `grade`
--

-- --------------------------------------------------------

--
-- Table structure for table `info`
--

CREATE TABLE IF NOT EXISTS `info` (
  `name` varchar(100) NOT NULL,
  `course` varchar(100) NOT NULL,
  `subject` varchar(100) NOT NULL,
  `department` varchar(100) NOT NULL,
  `gender` varchar(100) NOT NULL,
  `contact` int(15) NOT NULL,
  `prelim` int(3) NOT NULL,
  `midterm` int(3) NOT NULL,
  `final` int(3) NOT NULL,
  `endterm` int(3) NOT NULL,
  `remarks` varchar(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `info`
--

INSERT INTO `info` (`name`, `course`, `subject`, `department`, `gender`, `contact`, `prelim`, `midterm`, `final`, `endterm`, `remarks`) VALUES
('Jake Pomperada', 'BS Computer Science', 'Pascal Programming', 'Commerce', 'MALE', 4335081, 78, 89, 95, 90, 'PASSED'),
('Ma. Junallie Fuentebella', 'BS Chemical Engineering', 'Chemistry 1', 'Engineering', 'FEMALE', 4335675, 89, 78, 100, 91, 'PASSED'),
('Ana Tan', 'BS Accountancy', 'Financial Management', 'Commerce', 'FEMALE', 7078423, 78, 78, 79, 79, 'PASSED'),
('Tita Swarding', 'Mass Communication', 'Basic Journalism', 'Arts and Sciences', 'FEMALE', 7546348, 87, 89, 94, 91, 'PASSED'),
('Vincent Qui', 'BS Business Management', 'Accouting 101', 'Commerce', 'MALE', 999237563, 74, 83, 84, 82, 'PASSED'),
('Boy Cruz', 'BS Mathematics', 'Calculus', 'Education', 'MALE', 4567812, 65, 72, 76, 73, 'FAILED'),
('Juan Tamad', 'BS Secondary Education', 'Physical Education', 'Education', 'MALE', 4235562, 73, 65, 71, 70, 'FAILED');



Thursday, July 9, 2015

Least Common Multiple (LCM) Solver in Java

This sample program that I wrote in Java programming language will ask the user to enter two numbers and then our program will compute and determine the least common multiple or LCM of the two numbers 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.




Sample Program Output

Program Listing

// lcm.java
// Written By: Mr. Jake R. Pomperada, BSCS, MAED-IT
// July 9, 2015   Thursday
// Email Address:  jakerpomperada@gmail.com 
//                 jakerpomperada@yahoo.com

import java.util.Scanner;

public class lcm {

    public static void find_lcm(int x, int y)
    {
        int max=0,min=0,z=0,lcm=1;
  if(x>y)
    {
    max=x;
    min=y;
    }
    else
    {
    max=x;
    min=y;
    }

for(int i=1;i<=min;i++)
   {
    z=max*i; 
    if(z%min==0) 
     {
      lcm=z; 
      break; 
     }
    }
    System.out.println();
    System.out.println("The Least Common Multiple (LCM) of "+ x 
                   + " and " + y +  " is = " + lcm + ".");
    }

    
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
        
      char ch;
      int first_value=0;
      int second_value=0;
 do {
      System.out.println();
      System.out.print("\t LEAST COMMON MULTIPLE (LCM) SOLVER ");
      System.out.println("\n");
      
      System.out.print("Kindly give the first number  : "); 
      first_value = input.nextInt();
      
      System.out.print("Kindly give the second number : "); 
      second_value = input.nextInt();

      find_lcm(first_value,second_value);
      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");
   }

}


Area of a Triangle in Java

In this article I would like to share with you a sample program that I wrote in Java programming language I called this program Area of a Triangle in Java that will compute the are of the triangle based on the based and height of the triangle given by the 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.



Sample Program Output

Program Listing

// area_of_the_triangle.java
// Written By: Mr. Jake R. Pomperada, BSCS, MAED-IT
// July 9, 2015   Thursday
// Email Address:  jakerpomperada@gmail.com 
//                 jakerpomperada@yahoo.com

import java.util.Scanner;
 
public class area_of_the_triangle {
 
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
        
      char ch;
      double base_triangle = 0;
      double height_triangle = 0;
      double solve_area = 0;
 do {
      System.out.println();
      System.out.print("\tAREA OF THE TRIANGLE SOLVER ");
      System.out.println("\n\n");
      System.out.print("What is the length of base of the triangle : "); 
      base_triangle = input.nextDouble();
 
      System.out.print("What is the length of height of triangle : "); 
      height_triangle = input.nextDouble();
 
      solve_area = (base_triangle * height_triangle) / 2;
      
      System.out.println();
      System.out.println("The Area of Triangle is : " + solve_area + ".");
      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");
   }
 
}