Saturday, May 7, 2016

Odd and Even Numbers in C++ using Structure

A simple program that I wrote a long time ago that will check if the give number is odd or even using structure in C++.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>
#include <iomanip>

using namespace std;



struct odd {

int n;

  int odd_even() {

  if (n % 2 == 0)
        {
                 cout << n <<" Number is even!\n";
        }
        else
        {
                 cout << n << " Number is odd!\n";
        }
   return(n);

  }

};

main() {

    odd value;

   cout << "\t\t ODD and Even Number Determiner";
   cout << "\n\n";
   cout << "Enter a Number :";
   cin >> value.n;
   cout << "\n\n";
   cout << value.odd_even();
   cout << "\n\n";
   system("pause");


}


Payroll System in Java


A simple payroll system that I wrote using Java programming language a long time ago.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing


import java.io.*;
import java.text.*;

public class payroll_program{


    static BufferedReader in =  new BufferedReader(new InputStreamReader(System.in));

    public static void main(String [] args) throws IOException {

        String EmpCode = “”;

        while(!EmpCode.equals(“0?)) {

            System.out.print(“Enter Employee Code: “);
            EmpCode = in.readLine();

            String EmpInfo[] = getInfo(EmpCode);

            double basicsalary =  Double.parseDouble(EmpInfo[3]);

         
            System.out.println(” NEW MEGA ENTERPRISES PAYROLL SYSTEM“);
            System.out.println(”\n\n“);

            System.out.println(“READ ME FIRST : ****************************”);
            System.out.println(” * Input for Regular Hours  — > 8:00 – 17:00 “);
            System.out.println(” * Input for OT Hours — > 17:30 – 20:30 “);
            System.out.println(” * OT Income = ( Basic Salary / 8 ) * 1.1 “);
            System.out.println(” * Holiday = ( Basic Salary / 8 ) * 1.1 “);
            System.out.println(“*******************************************”);
            System.out.println(“============= Employee Information ==========”);
            System.out.println(“Employee Code: ” + EmpInfo[0]);
            System.out.println(“Employee Name: ” + EmpInfo[1]);
            System.out.println(“Employee Position: ” + EmpInfo[2]);
            System.out.println(“Employee  Basic Salary: ” + EmpInfo[3]);
            System.out.println(“=======================================”);

            String days[] = {“Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”};

            double timeInOut[][] =  new double[2][5];
            double otInOut[][] =  new double[2][5];

            String strTemp = “”;
            String tmpTime[] = new String[2];

            double tmpHours, totalHours = 0, tmpRegIncome = 0, totalRegIncome = 0,
            tmpOTHours,totalOTHours = 0, tmpOTIncome, totalOTIncome = 0;

            for(int i = 0; i < 5; i++){

                System.out.print(“Time In for ” + days[i] + “: “);
                strTemp = in.readLine();
                tmpTime = strTemp.split(“:”);
                timeInOut[0][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                System.out.print(“Time Out for ” + days[i] + “: “);
                strTemp = in.readLine();
                tmpTime = strTemp.split(“:”);
                timeInOut[1][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                System.out.print(“is ” + days[i] + ” Holiday?: “);
                String isHoliday =  in.readLine();

                System.out.print(“OT Time In for ” + days[i] + “: “);
                strTemp =  in.readLine();
                tmpTime = strTemp.split(“:”);
                otInOut[0][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                System.out.print(“OT Time Out for ” + days[i] + “: “);
                strTemp = in.readLine();
                tmpTime = strTemp.split(“:”);
                otInOut[1][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                if(timeInOut[0][i] < 8)timeInOut[0][i] = 8;
                if(timeInOut[1][i] > 17)timeInOut[1][i] = 17;
                if(otInOut[0][i] < 17.5 && otInOut[0][i] != 0)otInOut[0][i] = 17.5;
                if(otInOut[1][i] > 20.5)otInOut[1][i] = 20.5;

                tmpHours = timeInOut[1][i] – timeInOut[0][i];
                tmpOTHours = otInOut[1][i] – otInOut[0][i];

                if(tmpHours > 4)tmpHours–;

                if(isHoliday.equals(“Yes”)){
                    totalOTHours += tmpHours;
                    totalOTIncome += tmpHours * ((basicsalary / 8) * 1.1);
                    totalHours += tmpHours;
                    tmpRegIncome = tmpHours * (basicsalary / 8);
                }else{
                    totalHours += tmpHours;
                    tmpRegIncome = tmpHours * (basicsalary / 8);
                }

                    totalOTHours += tmpOTHours;
                    totalOTIncome += tmpOTHours * ((basicsalary / 8) * 1.1);
                    totalRegIncome += tmpRegIncome;

            }
                    double grossincome =  totalRegIncome + totalOTIncome;

                    DecimalFormat df = new DecimalFormat(“#.##”);

                    System.out.println(“=========== Total Output ==============”);
                    System.out.println(“Total work hours: ” + df.format(totalHours));
                    System.out.println(“Total regular income: ” + df.format(totalRegIncome));
                    System.out.println(“Total OT hours: ” + df.format(totalOTHours));
                    System.out.println(“Total OT Income: ” + df.format(totalOTIncome));
                    System.out.println(“Gross Income: ” + df.format(grossincome));
                    System.out.println(“=====================================”);
                    System.out.println(" THANK YOU FOR USING THIS PROGRAM");

        }

    }

    static String[] getInfo(String EmpCode){

        String getInfo[] = new String [4];
        String strLine;
        int ctr =0;
        boolean isFound = false;

        try{

            FileInputStream fstream =  new FileInputStream(“payroll.txt”);
            DataInputStream dstream  =  new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(dstream));

            while((strLine = br.readLine()) != null && ctr < 4){
                if(strLine.equals(EmpCode))isFound = true;
                if(isFound){
                    getInfo[ctr] =  strLine;
                    ctr++;

                }

            }

            br.close();

        }catch(IOException e){

            System.out.println(“Error: ” + e.getMessage());
        }

        return getInfo;

    }

}

Sunday, May 1, 2016

Addition of Two Numbers Using Spring Framework

I am very new in Java Enterprise Edition or J2EE programming particularly using Spring Framework. But I find it easy to learn once you have known the basic concepts and principles behind it. I am thankful that there is a video tutorial in YouTube that we can study to be specific the tutorial of Ankush Gorav here his website http://www.gontu.org.

I have learned a lot from his tutorial in YouTube. In gives me an idea how to get started this sample program that I wrote is based on his tutorial will ask the user to give two numbers and then our program will find the total sum of the two numbers.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output



Some Screenshots


Program Listing


Addition_Two_Numbers.java

package org.gontuseries.springcore;

import java.util.Scanner;

public class Addition_Two_Numbers {
int a=0,b=0,sum=0;
public void find_sum() {
 Scanner in = new Scanner(System.in);
 System.out.println();
 System.out.println("Addition of Two Numbers");
 System.out.println("\n");
   
 System.out.print("Enter First Value : ");
     a = in.nextInt();
     
     System.out.print("Enter Second Value : ");
     b = in.nextInt();
 
     sum=(a+b);
     
     System.out.println("\n");
 System.out.print("The sum of " + a + " and " + b + " is " + sum +".");
 System.out.println("\n");
 System.out.println("End of Program");
 
}

}


SpringConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id="addition_two_numbers_Bean" class="org.gontuseries.springcore.Addition_Two_Numbers">
</bean>

</beans>


TestSpringProject.java

package org.gontuseries.springcore;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpringProject {

public static void main(String[] args) {
 @SuppressWarnings("resource")
ApplicationContext context = 
 new ClassPathXmlApplicationContext("SpringConfig.xml");
 
 Addition_Two_Numbers Add_Two_NumbersObj = (Addition_Two_Numbers) context.getBean("addition_two_numbers_Bean");
    
 Add_Two_NumbersObj.find_sum();
}
}








Sunday, April 24, 2016

Palindrome in Visual Basic.NET

A program that I wrote in Visual Basic.NET that will check if the given word by the user is a palindrome or not a palindrome.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

Public Class Form1

    Private Sub Find_Palindrome(ByVal strString As String)
        Dim str As String
        str = StrReverse(UCase(strString))
        If str.Equals(UCase(strString)) Then
            Label2.Text = UCase(strString) + " is a Palindrome."
        Else
            Label2.Text = UCase(strString) + " is Not a Palindrome."
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label2.Visible = True
        Find_Palindrome(TextBox1.Text)
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label2.Visible = False
        TextBox1.Focus()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Label2.Visible = False
        Label2.Text = ""
        TextBox1.Text = ""
        TextBox1.Focus()
    End Sub
End Class



Thursday, April 14, 2016

Vowels, Consonants and Numbers Counter in JavaScript

A program that I wrote using JavaScript as my programming language that will ask the user to give a string or a sentence and then our program will count the number of occurrence of vowels, consonants and numbers. The code is very simple and very easy to understand.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<head>
<title>Vowels, Consonants and Numbers Counter</title>
<style>
body {
     font-family:arial;
font-size:12;
font-weight:bold;
 }
</style>
<script type="text/javascript">
function count_all() {

var str = document.getElementById('txtname').value;

var count = 0, total_vowels="";
var count2=0, total_consonants="";
var count3=0, total_digits="";

for (var i = 0; i < str.length; i++) {
if (str.charAt(i).match(/[a-zA-Z]/) != null) {

if (str.charAt(i).match(/[aeiouAEIOU]/))
{
total_vowels = total_vowels + str.charAt(i);
count++;
}

if (str.charAt(i).match(/[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]/))
{
total_consonants = total_consonants + str.charAt(i);
count2++;
}


}

function retnum(str1) { 
    var num = str1.replace(/[^0-9]/g, ''); 
    return num; 
}

function count_digits(str2) {
  var num2 = str2.replace(/[^0-9]/g,"").length;
  return num2;
}
}
document.getElementById('consonant_counts').value =  count2;
document.getElementById('total_consonants').value = total_consonants;
document.getElementById('vowels').value = total_vowels;
document.getElementById('vcount').value = count;
document.getElementById('digits1').value = count_digits(str);
document.getElementById('digits2').value = retnum(str);
}

function clear_all()
{
document.getElementById('consonant_counts').value ="";
document.getElementById('total_consonants').value ="";
document.getElementById('vowels').value = "";
document.getElementById('vcount').value = "";
document.getElementById('digits1').value ="";
document.getElementById('digits2').value ="";
document.getElementById('txtname').value ="";
document.getElementById('txtname').focus();
}
</script>
</head>
<body>
<br><br>
<div >
<table border="0" cellspacing="0" width="40%" style="background-color:lightgreen; color:blue">
<tr><td colspan="2" align="center"><b>Vowels, Consonants and Numbers Counter</b></td></tr>
<tr> <td>&nbsp;</td></tr>
<tr>
<td>Enter a String </td>
<td><input type='text' id='txtname' size="30" autofocus/></td>
</tr>
<tr> <td>&nbsp;</td></tr>
<tr>
<td>No. of Consonants </td>
<td><input type='text' readonly="readonly" id='consonant_counts'  size="30"/></td>
</tr>
<tr>
<td>List of Consonant(s) </td>
<td><input type='text' readonly="readonly" id='total_consonants'  size="30"/></td>
</tr>
<tr>
<td>No. of Vowels </td>
<td><input type='text' readonly="readonly" id='vcount'  size="30"/></td>
</tr>
<tr>
<td>List of Vowel(s) </td>
<td><input type='text' readonly="readonly" id='vowels'  size="30"/></td>
</tr>
<tr>
<td>No. of Digits </td>
<td><input type='text' readonly="readonly" id='digits1'  size="30"/></td>
</tr>
<td>List of Digit(s) </td>
<td><input type='text' readonly="readonly" id='digits2'  size="30"/></td>
</tr>
<tr> <td>&nbsp;</td></tr>
<tr>
<td></td>
<td><input type='button' value='Ok' title="Click here to process." 
onclick="javascript:count_all();" />
&nbsp;&nbsp;&nbsp;
<input type='button' value='Clear' title="Click here to clear all the text fields."
onclick="javascript:clear_all();" /></td>
</tr>
</table>
</div>
</body>
</html>



Wednesday, April 13, 2016

Factorial Solver in Visual Basic .NET

A factorial program that I wrote using Microsoft Visual Basic .NET to solve for the factorial of the number. The code is very easy to understand I create a function called factorial which uses recursion algorithm to solve the factorial of the given number by our user.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label2.Visible = False
    End Sub
    Private Function Factorial(ByVal inputval As Integer) As Integer
        Dim f As Integer
        Factorial = 1

        For f = 2 To inputval
            Factorial = Factorial * f
        Next
    End Function


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label2.Visible = True
        Dim myNumber1, mynumber2 As Integer
        myNumber1 = Val(TextBox1.Text)
        mynumber2 = Factorial(Val(TextBox1.Text))
        Label2.Text = "The factorial value of " & myNumber1 & _
                      " is " & mynumber2 & "."

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Label2.Visible = False
        TextBox1.Text = ""
        Label2.Text = ""
        Label2.Text = ""
        TextBox1.Focus()

    End Sub
End Class




Odd and Even Number Checker in Visual Basic NET

Here is a simple program that I wrote using Microsoft Visual Studio 2012 and my language is Visual Basic NET to check if the given number of the user is an odd or even number using the operator MOD. I also include error detection if text field is empty and then the user click the ok button our program will display a message informing the user that the text field needs a value.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Sample Program Output

Program Listing


Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label2.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myNumber As Long
        myNumber = Val(TextBox1.Text)
        Label2.Visible = False


        If myNumber = 0 Then
            MessageBox.Show("Sorry can't be empty.")
            Label2.Visible = False
            Label2.Text = ""

            TextBox1.Focus()
        ElseIf myNumber Mod 2 Then
            Label2.Visible = True
            Label2.Text = "You've entered an odd number."
        Else
        Label2.Visible = True
        Label2.Text = "You've entered an even number."
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Label2.Visible = False
        TextBox1.Text = ""
        Label2.Text = ""
        Label2.Text = ""
        TextBox1.Focus()

    End Sub
End Class



Sunday, April 10, 2016

Pounds To Kilograms Converter in Visual Basic.NET

A program that I wrote in Visual Basic.NET that will ask the user to give a value in Pounds and then it will convert it into Kilograms equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label3.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label3.Visible = True

        Dim Kilograms As Decimal

        Dim Pounds As Decimal

        Pounds = Val(TextBox1.Text)

        Kilograms = (Pounds * 0.45359237)

        Label3.Text = Pounds & " Lbs(s) is equivalent to " & Math.Round(Kilograms, 2) & " Kg(s)"

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        Label3.Text = ""
        TextBox1.Focus()
    End Sub
End Class





Kilograms to Pounds Converter in Visual Basic.NET

A simple program in Visual Basic.NET that will ask the user to give the weight in kilograms and then it will convert it into Pounds equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label3.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label3.Visible = True

        Dim Kilograms As Decimal

        Dim Pounds As Decimal

        Kilograms = Val(TextBox1.Text)

        Pounds = (Kilograms * 2.20462262)

        Label3.Text = Kilograms & " Kg(s) is equivalent to " & Math.Round(Pounds, 2) & " Lbs(s)"


    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        Label3.Text = ""
        TextBox1.Focus()
    End Sub
End Class