Saturday, May 6, 2017

Product of Two Numbers in Java Using Object Oriented Programming

In this article I would like to share with you a program that I wrote in Java to accept two numbers and then our program will compute the product of the two given numbers using object oriented programming approach in Java. The code is very short and easy to understand.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


product.java


package demo;

import java.util.Scanner;


class product_value {
int val_1=0,val_2=0;
}

public class product {

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 int product=0;
 
 product_value a = new product_value();
 product_value b = new product_value();
 
 System.out.println();
     System.out.println("PRODUCT OF TWO NUMBERS IN JAVA OOP");
     System.out.println();
     System.out.print("Enter First Value : ");
     a.val_1 = input.nextInt();
     
     System.out.print("Enter Second Value : ");
     b.val_2 = input.nextInt();
     
     product = (a.val_1 * b.val_2);
      
     System.out.println();
     System.out.print("The product of " + a.val_1 + " and " + b.val_2 + " is " + product + ".");
     input.close();
}

}




Simple Animation in C++


A very simple program that I wrote in C++ to demonstrate simple animation. I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler in this program. Thank you.


My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing


#include<iostream>
#include<stdio.h>
#include<dos.h>
#include <windows.h>
#include<conio.h>


using namespace std;

int main()
{
       int y=0;
       char d='|';
        for(int x=0; x<=50; x++)
        {

                y= rand() % 300;
                Sleep(y);
                system("cls");
                if(d=='|')
                  d='/';
                else if(d=='/')
                     d='-';
                else if(d=='-')
                     d='\\';
                else if(d=='\\')
                     d='|';
                 cout<<"Loading Program--------> "<<d;

        }

        cin.get();
        return 0;
}


Getters and Setters in Java

Here is a simple implementation of Getters and Setters in Java. The code is very short and easy to understand.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing


Student.java

package list;

public class Student {
private String name;
private int age;

private int a,b;


  
public String getName(){  
return name;  


public int getAge()
{
return age;
}

public void setName(String name){  
this.name=name;  
}

public void setAge(int age) {
this.age =age;
}

public int get_A()
{
return a;
}

public int get_B()
{
return b;
}

public void Set_A(int a){
this.a = a;
}

public void Set_B(int b){
this.b = b;
}

}


Test.java

package list;

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

int sum=0;
Student s=new Student();  
s.setName("Mario");  
s.setAge(38);
s.Set_A(1);
s.Set_B(4);

sum = s.get_A() + s.get_B();

System.out.println("Your Name is " + s.getName());
System.out.println("Your Age is " + s.getAge());

System.out.println();
System.out.print("The sum of " +s.get_A() + " and " + s.get_B() + " is " + sum + ".");
}  

}




Array List in Java

Here is a simple implementation of array list data structure in Java. The code is very short and easy to understand.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing

package list;

import java.util.*;

class array_list{

public static void main(String args[]){
 
 ArrayList<String> users= new ArrayList<String>();
 
 users.add("Jacob");
 users.add("Ana");
 users.add("Mark");
 users.add("Ma.Junallie");
 users.add("Julianna Rae");
 users.add("Paul Jun");
 users.add("Joan");
 users.add("Sally");
 Iterator <String> list_all =users.iterator();
 
 System.out.println();
 System.out.println("List of Users");
 System.out.println();
 
 while(list_all.hasNext()){
  System.out.println(list_all.next());
 }
}
}


Linked List in Java

Here is a simple implementation of linked list data structure in Java. The code is very short and easy to understand.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing


package list;

import java.util.*;

public class linked_list {
   
public static void main(String args[]) {
LinkedList <String> users= new LinkedList <String>();

users.add("Samboy");
users.add("Allan");
users.add("Rudy");
users.add("Maria");
users.add("Robert");
users.add("Linda");

Iterator <String> list_all =users.iterator();
 
 System.out.println();
 System.out.println("List of Users");
 System.out.println();
 
 while(list_all.hasNext()){
  System.out.println(list_all.next());
 }

}
}

Getting Operating System Information in Java

Here is a sample to get and display the current version of your computer operating system using Java. The code is very easy to learn and understand.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

/* Written By: Jake R. Pomperada, MAED-IT */
/* Language  : Java                       */
/* Date      : May 6, 2017                */


package demo;

public class os {

public static void main(String[] args) {
String name = "os.name";
       
       String version = "os.version";
       
       String architecture = "os.arch";
  

System.out.print("\n\n");
System.out.print("\t Getting Operating System Information in Java ");
System.out.print("\n\n");
       System.out.println("Name: " + System.getProperty(name));
       System.out.println("Version: " + System.getProperty(version));
       System.out.println("Arch: " + System.getProperty(architecture));
}

}

Display Date and Time in Java

Here is a very simple program that I wrote using Java as my programming language to display the current date and time from the users computer. The code is very easy to understand it uses java core API to retrieve the current date and time. I hope you will find my work useful in learning Java programming. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

Demo.java

/* Written By: Jake R. Pomperada, MAED-IT           */
/* Language  : Java                                                  */
/* Date      : May 6, 2017                                        */

package demo;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Demo {

public static void main(String[] args) {
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date = new Date();
System.out.print("\n\n");
System.out.print("\t Display Date and Time in Java ");
System.out.print("\n\n");
System.out.println("Today is " + dateFormat.format(date) + "."); 
}

}



Thursday, May 4, 2017

US Dollar To Philippine Peso Converter in Turbo Pascal

Here is a sample program that I wrote using Turbo Pascal 6.0 for DOS to ask the user to give a value in US Dollars and convert it to Philippine Peso currency equivalent. The code is very simple and easy to understand. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

Program US_PESO;

Uses Crt;

Const
  
   PHP = 48.75;

Var  Convert : Real;
     US_value : Integer;
Begin
  
  Clrscr;
  Writeln;
  textcolor(white);
  Write('US Dollar To Philippine Peso Converter in Turbo Pascal');
  Writeln;
  Writeln;
  Write('Give the value in US Dollars : ');
  Readln(US_value);

  Convert := (US_value * PHP);

  Writeln;
  Write('The value of ',US_value, ' in Philippine Peso is ',convert:5:2,'.');
  Writeln;
  Writeln;
  Write('End of Program');
  Readln;
End.



Simple Login System in PHP and MySQL

Here is a sample program wrote by my best friend and fellow software engineer Mr. Dave Marcellana a simple login system using PHP and MySQL. It uses bootstrap framework for the design. I hope you will find the work of Dave useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output



Program Listing

db.php


<?php
mysql_connect("localhost","root","") or
 die('Could not connect to the database!');


mysql_select_db("dbloginv1") or
 die('No database selected!');
?>

index.php

<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title Page</title>

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<h1 class="text-center">Login Version 1.0</h1>

<?php
session_start();

//Includes the connection file that contains the MYSQL database information
include('db.php');

if(isset($_POST['login']))
{
$user = $_POST['username'];
$pass = $_POST['password'];

// Selects the username and password from the users database.
$query = "SELECT * FROM users WHERE User='$user'";

$result = mysql_query($query);

if(!$result) 
{
echo "The query failed " . mysql_error();
else 
{
// If the row vairble does not equal the pass variable then an error occurs.
$row = mysql_fetch_object($result);

if(isset($_COOKIE['login']))
{
if($_COOKIE['login'] < 3)
{
$attempts = $_COOKIE['login'] + 1;
setcookie('login', $attempts, time()+60*10); //set the cookie for 10 minutes with the number of attempts stored
echo "I'm sorry, but your username and password don't match. Please go back and enter the correct login details.You Click <a href=\"login.php\">here</a> to try again.";
else
{
echo 'You\'ve had your 3 failed attempts at logging in and now are banned for 10 minutes. Try again later!';
}
else 
{
setcookie('login', 1, time()+60*10); //set the cookie for 10 minutes with the initial value of 1
}
exit;
header('Location: http://www.google.com');
}
}
?>

<form action="" method="POST" role="form">
<legend>Login</legend>
<div class="form-group">
<label for="">Username</label>
<input type="text" class="form-control" name="username" placeholder="Username" required="required">
</div>

<div class="form-group">
<label for="">Password</label>
<input type="password" class="form-control" name="password" placeholder="Password" required="required">
</div>
<button type="submit" name="login" class="btn btn-primary">Submit</button>
</form>

<!-- jQuery -->
<script src="//code.jquery.com/jquery.js"></script>
<!-- Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  <script src="Hello World"></script>
</body>
</html>


Reverse a Number in PHP Version 2

Here is the version 2 of my program reverse a number in PHP what does the program will to is to ask the user to give a number and then it will check if the given number is a palindrome or not a palindrome.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

<html>
   
   <head>
      <title>Reverse a Number in PHP </title>
   </head>
   <style>
      
   body {
   font-family:arial;
   font-size:14px;
   font-weight:bold;
   };
   </style>
   
   <body>
      <?php
         error_reporting(0);
                  
         if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $val_1 = test_input($_POST["val_no"]);
          
$num = $val_1;
$p=$num;
$revnum = 0;

while ($num != 0)
{
$revnum = $revnum * 10 + $num % 10;
$num = (int)($num / 10); 
}

if($revnum==$p)
{
echo "\n\n\n";
$result = "The number $p is a Palindrome.";
}
else
{
echo "\n\n\n";
$result = "The number $p is Not a Palindrome.";

}
 
      }
         
         function test_input($data) {
            $data = trim($data);
            return $data;
         }
 
  if ($_POST["clear_me"] == true) {
            $val_1 = "";
$result = "";
           
         }
         
      ?>
      <br>
      <h2>Reverse a Number in PHP</h2>
      <form method = "post" action = "form1.php">
         <table>
            <tr>
               <td>Give a Number </td> 
               <td>&nbsp;<input type = "text" name = "val_no" value="<?php echo $val_1; ?>" autofocus required></td>
            </tr>
                   
            <tr>
               <td>
     <br>
                  <input type = "submit" name = "submit" value = "Check" 
 title="Click here to check if the given number in Palindrome or Not"> &nbsp;&nbsp;&nbsp;
               <input type = "submit" name = "clear_me" value = "Clear"
  title="Click here to clear the textbox."> 
  </td>
            </tr>
         </table>
      </form>
      
      <?php
echo "<br>"; 
echo $result; 
     ?>
    </body>
</html>