Wednesday, March 28, 2018

Odd and Even Number Checker in Apple Script

Here is a very simple program that I wrote using Apple Script to check if the given number is an ODD or EVEN number. The code is short and very easy to understand.

 I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output for ODD Number


Sample  Program Output for EVEN Number



Program Listing

# checking for ODD number

# odd and even number checker in apple script
# written by Mr. Jake R. Pomperada, MAED-IT
# March 28, 2018

set val1 to 3

if val1 mod 2 is 0 then
display dialog "The given number " & val1 & " is an " & "EVEN number."
else
display dialog "The given number " & val1 & " is an " & "ODD number."
end if


# checking for EVEN number

# odd and even number checker in apple script
# written by Mr. Jake R. Pomperada, MAED-IT
# March 28, 2018

set val1 to 4

if val1 mod 2 is 0 then
display dialog "The given number " & val1 & " is an " & "EVEN number."
else
display dialog "The given number " & val1 & " is an " & "ODD number."
end if





Addition of Two Numbers in Apple Script

A very simple script that I wrote to add the sum of two values using Apple Script in MAC OS.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output



Program Listing

# addition of two numbers in apple script
# written by Mr. Jake R. Pomperada, MAED-IT
# March 28, 2018
set val1 to 97
set val2 to 3
set sum to val1 + val2
display dialog "The sum " & val1 & " and " & val2 & " is " & sum & "."

Hello World in Apple Script

A very simple program to display hello world in Apple Script in Mac OS. This is my first program using Apple Script.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Program Listing and Sample Program Output

PRIME NUMBER CHECKER USING EXCEPTION IN JAVA

A simple program to check if the given number by a user is prime number or not that have exception handling capabilities.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.


Sample Program Output


Program Listing

PrimeNumber.java


package exceptiondemo;

import java.util.Scanner;
import java.util.InputMismatchException;


/**
 * NetBeans IDE 8.2
 * @author Mr. Jake R. Pomperada
 * March 20, 2018  Tuesday
 * Bacolod City, Negros Occidental
 */
public class PrimeNumber {

   public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
               boolean flag = false;
               boolean goodData = false;
                
              while(!goodData) {
              try {
                System.out.print("PRIME NUMBER CHECKER USING EXCEPTION");
                System.out.println("\n");
                System.out.print("Give a number  : ");
int num_value =sc.nextInt();
                
                 for(int i = 2; i <= num_value/2; ++i)
        {
            // condition for nonprime number
            if(num_value % i == 0)
            {
                flag = true;
                break;
            }
        }

        if (!flag) {
            System.out.println("\n");
            System.out.println("The given " + num_value
                    + " is a Prime Number.");
        }
        else{
            System.out.println("\n");
            System.out.println("The given " + num_value
                    + " is Not a Prime Number.");
        }   
                
                System.out.println("\n");
goodData = true;
       
              } catch(InputMismatchException e) {
            
                sc.next();
                System.out.println("You Entered a Bad Data." );
                System.out.println("Please Try Again." );
                System.out.println("\n");
                }
            }  // while loop end
System.out.print("\t END OF PROGRAM");
        System.out.println("\n");
     }
}

 

AREA OF A CIRCLE USING EXCEPTION IN JAVA

A simple program that I wrote to compute the area of the circle with exception handling capabilities.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output


Program Listing

AreaCircle.java


package exceptiondemo;

import java.util.Scanner;
import java.util.InputMismatchException;
import java.text.DecimalFormat;

/**
 * NetBeans IDE 8.2
 * @author Mr. Jake R. Pomperada
 * March 20, 2018  Tuesday
 * Bacolod City, Negros Occidental
 */
public class AreaCircle {

    public static final DecimalFormat TWO_DECIMAL = new DecimalFormat(".##");
     
    public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
      
               final double PI = 3.14159;
               boolean goodData = false;
                
              while(!goodData) {
              try {
                System.out.print("AREA OF A CIRCLE USING EXCEPTION");
                System.out.println("\n");
                System.out.print("What is the area?  : ");
double radius=sc.nextDouble();
                
                 double area = (PI * radius * radius);
                
                System.out.println("\n");
                System.out.println("The Area of Circle is " 
                        + TWO_DECIMAL.format(area) +".");
                System.out.println("\n");
goodData = true;
       
              } catch(InputMismatchException e) {
            
                sc.next();
                System.out.println("You Entered a Bad Data." );
                System.out.println("Please Try Again." );
                System.out.println("\n");
                }
            }  // while loop end
System.out.print("\t END OF PROGRAM");
        System.out.println("\n");
     }
}



ADDITION OF THREE NUMBERS USING EXCEPTION IN JAVA

In this article I wrote a program in Java to ask the user to give three numbers and the program will compute the sum of the three number with exception handling capabilities to check for invalid entries.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output


Program Listing

Addition.java


package exceptiondemo;


import java.util.Scanner;
import java.util.InputMismatchException;

/**
 * NetBeans IDE 8.2
 * @author Mr. Jake R. Pomperada
 * March 20, 2018  Tuesday
 * Bacolod City, Negros Occidental
 */
public class Addition {

   
    public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
                int sum =0;
                boolean goodData = false;
                
              while(!goodData) {
              try {
                System.out.print("ADDITION OF THREE NUMBERS USING EXCEPTION");
                System.out.println("\n");
                System.out.print("Enter First Value  : ");
int num1=sc.nextInt();
                System.out.print("Enter Second Value : ");
int num2=sc.nextInt();
                System.out.print("Enter Third Value  : ");
int num3=sc.nextInt();
                 
                sum = (num1+num2+num3);
                System.out.println("\n");
                System.out.println("The sum of "+ num1 + ", " +num2 + " and " 
                        + num3 + " is " + sum +".");
                System.out.println("\n");
goodData = true;
       
              } catch(InputMismatchException e) {
            
                sc.next();
                System.out.println("You Entered a Bad Data." );
                System.out.println("Please Try Again." );
                System.out.println("\n");
                }
            }  // while loop end
System.out.print("\t END OF PROGRAM");
        System.out.println("\n");
     }
}

 

SQUARE AND CUBE A NUMBER USING EXCEPTION IN JAVA


In this article I would like to share with you a program that I wrote in Java that will ask the user to give a number and then our program will compute the square and cube of the given number I added exception handling routine to check for invalid entries.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output


Program Listing

 ExceptionDemo.java

package exceptiondemo;


import java.util.Scanner;
import java.util.InputMismatchException;

/**
 * NetBeans IDE 8.2
 * @author Mr. Jake R. Pomperada
 * March 20, 2018  Tuesday
 * Bacolod City, Negros Occidental
 */
public class ExceptionDemo {

   
    public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
                boolean goodData = false;
                
              while(!goodData) {
              try {
                System.out.print("SQUARE AND CUBE A NUMBER USING EXCEPTION");
                System.out.println("\n");
                System.out.print("Give a Number : ");
int num=sc.nextInt();
                 
                System.out.println("Square of "+ num + " is: "+ Math.pow(num, 2));
System.out.println("Cube of "+ num + " is: "+ Math.pow(num, 3));
                System.out.println("\n");
goodData = true;
       
              } catch(InputMismatchException e) {
            
                sc.next();
                System.out.println("You Entered a Bad Data." );
                System.out.println("Please Try Again." );
                System.out.println("\n");
                }
            }  // while loop end
System.out.print("\t END OF PROGRAM");
        System.out.println("\n");
     }
}




CRUD in JDBC and MySQL

A simple CRUD program that I wrote using Java JDBC and MySQL. The code is very short and easy to understand.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.


Prorgam Listing

Jdbc.java

package com.jdbc.demo;

import java.sql.*;

public class Jdbc {

    private static Connection connection;

    // create table script
    // create table item(id int primary key auto_increment, name varchar(20), price double);

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

        String dbURL = "jdbc:mysql://localhost:3306/product";
        String username = "root";
        String password = "";

        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            connection = DriverManager.getConnection(dbURL, username, password);

            if (connection != null) {
                System.out.println("Connected");
            }

            // insert record
            //insertItem("Pencil",5.50);
            //insertItem("Ballpen",9.00);

            //updateItem("Pencil",6.00);

            deleteItem("Pencil");
            // select records
            selectItems();


            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void deleteItem(String name) throws Exception {
        String sql = "DELETE FROM Item WHERE name=?";

        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setString(1, name);

        int rowsDeleted = statement.executeUpdate();
        if (rowsDeleted > 0) {
            System.out.println("An item was deleted successfully!");
        }
    }

    private static void updateItem(String name, Double price) throws Exception {
        String sql = "UPDATE Item SET price=? WHERE name=?";

        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setDouble(1, price);
        statement.setString(2, name);

        int rowsUpdated = statement.executeUpdate();
        if (rowsUpdated > 0) {
            System.out.println("An existing item was updated successfully!");
        }
    }
    private static void selectItems() throws Exception {
        String sql = "SELECT * FROM Item";

        Statement statement = connection.createStatement();
        ResultSet result = statement.executeQuery(sql);

        int count = 0;

        while (result.next()){
            String name = result.getString(2);
            Double price = result.getDouble(3);

            String output = "Item #%d: %s - %s";
            System.out.println(String.format(output, ++count, name, price));
        }
    }

    private static void insertItem(String name, Double price) throws Exception {
        String sql = "INSERT INTO Item (name, price) VALUES (?, ?)";

        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setString(1, name);
        statement.setDouble(2, price);

        int rowsInserted = statement.executeUpdate();
        if (rowsInserted > 0) {
            System.out.println("A new item was inserted successfully!");
        }
    }



}


Friday, March 16, 2018

Swap of Two Numbers using Reference in C++

A very simple program that I wrote to show you how to swap two numbers using the concept of reference in C++.


I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.





Sample Program Output


Program Listing

swap.cpp


#include <iostream>

using namespace std;


        void swap(int &x, int &y);

       int main()
       {
          
         int x=0,y=0;
         
  cout << "Swap of Two Numbers using Reference in C++";
   cout << "\n\n";
   cout << "Created By Mr. Jake R. Pomperada, MAED-IT";
   cout << "\n\n";
   cout << "Enter values for x and y : ";
   cin >> x >> y;

       cout << "Main. Before swap, x: " << x << " y: " << y << "\n";
         swap(x,y);
         cout << "Main. After swap, x: " << x << " y: " << y << "\n";
        cout << "\n\n";
   cout << " End of Program ";  
           }


          void swap (int &ax, int &ay)
        {
             int temp;

                cout << "Swap. Before swap, ax: " << ax << " ay: " << ay << "\n";
                temp = ax;
                ax = ay;
              ay = temp;

                cout << "Swap. After swap, ax: " << ax << " ay: " << ay << "\n";
                
            }


Temperature Converter Using Function in C++


In this article I would like to share with you a sample program that I wrote using C++ to demonstrate how to use function to convert temperature the code is very easy to understand to use.

I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.




Sample Program Output


Program Listing


temp.cpp


#include <iostream>
#include <iomanip>

using namespace std;

     float Convert(float);
    int main()
     {
       float TempFer=0.00;
       float TempCel=0.00;
       cout << std::fixed;
       cout << std::setprecision(2);
   cout << "Temperature Converter Using Function in C++";
   cout << "\n\n";
   cout << "Created By Mr. Jake R. Pomperada, MAED-IT";
   cout << "\n\n";
       cout << "Enter temperature in Fahrenheit: ";
       cin >> TempFer;
       TempCel = Convert(TempFer);
       cout << "\nHere's the temperature in Celsius: ";
       cout << TempCel;
   cout << "\n\n";
   cout << " End of Program ";    
     }

    float Convert(float Fer)
     {
        float Cel;
        Cel = ((Fer - 32) * 5) / 9;
        return Cel;
   }