Wednesday, July 22, 2015

Year Level in Java

In this article I would like to share with you a sample program that I wrote in Java using NetBeans as my integrated development environment I called this program year level checker or determiner that show the user how to use if else statement in Java. This program is for beginners that are very new in Java programming.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

/*
year_level2.java
Programmer By: Mr. Jake R. Pomperada, MAED-IT
Date : July 20, 2015
Tools: NetBeans 8.0.2, Java SE 8.0

Problem No. 4:

Design a program to display the year level of students based on their
year entry number. Here are the given criteria: 
(using if-else statement).

*/


import java.util.Scanner;

class year_level2 {
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
    
  do { 
      
      System.out.print("\t\t MARMELO V. ABANTE INSTITUTE OF SCIENCE AND TECHNOLOGY ");
      System.out.println();
      System.out.print("\t\t 12 Mangga St., Brgy.Papaya, Tingloy, Batangas, Batangas City");
      System.out.println("\n");
      System.out.print("Enter your year level now : ");
      int year_level = input.nextInt();
          
      if (year_level == 1) {
          System.out.println();
          System.out.print("You are in a Freshman Status.");
          }
      if (year_level == 2) {
          System.out.println();
          System.out.println("You are in a Sophomore Status.");
         }
     if (year_level == 3) {
          System.out.println();
          System.out.print("You are in a Junior Status.");
         }
      if (year_level == '4') {
          System.out.println();
          System.out.print("You are in Senior Status.");
         }
      else if (year_level > 4 || year_level < 1) {
          System.out.println("Sorry You are out of school youth.");
      }  
     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");
  }
}




Sunday, July 19, 2015

Numbers To Roman Numeral in Java

A simple program in Java that will ask the user to give a number in integer format and then the program will convert the given decimal number into roman numeral equivalent.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

// decimal_romans.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 19, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com

import java.util.Scanner;

class decimal_romans
{
public static void main(String args[]) 
{
     Scanner input = new Scanner(System.in);
        
      char ch;
     
 do {

String thousands[]={"","M","MM","MMM","MMMM"};
String hundreds[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String tens[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
String units[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};

System.out.println();
System.out.print("\t  NUMBER TO ROMAN NUMERALS ");
System.out.println("\n");
System.out.print("Enter a Number : ");
int number = input.nextInt();

if(number>0 && number<5000)
{

int th=number/1000;
int h=(number/100)%10;
int t=(number/10)%10;
int u=number%10;

System.out.println("Roman Equivalent= "+thousands[th]+hundreds[h]+tens[t]+units[u]);
}
 else
System.out.println("nYou entered a number out of Range."
        + "Please enter a number in the range [1-4999] only");
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");
 }

}


Second Highest Number in Java

In this simple program it will ask the user to enter five numbers and then our program will check and determine which of the five number has the second highest value.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

// finding_second.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 19, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com

// Write a program in Java using one dimensional array that will ask the user
// to give five numbers and then the program will determine which of the five
// number is the second to the highest number.

import java.util.Scanner;
 
public class finding_second {
    
    public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      
     char ch;   
 do {
    int values[]=new int[5];
    int highest = Integer.MIN_VALUE;
    int highest2nd = Integer.MIN_VALUE;
    
     System.out.println();
      System.out.print("\t FINDING SECOND HIGHEST NUMBER");
      System.out.println("\n");
    for(int i=0;i<5;i++){
        int x=(i+1);
         System.out.print("Enter Value Number " + x + ": ");
          values[i]=input.nextInt();

    }
    for(int i=0;i<5;i++){
        if (values[i]>=highest) { 
            highest2nd = highest;
            highest = values[i];
        } else if (values[i]>= highest2nd)
            highest2nd =values[i];
    }
    System.out.println();
    System.out.println("The second highest number is " + highest2nd +"."); 
     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");
    }
}


Pascal Triangle in Java

A simple program that I wrote using Java that will display Pascal Triangle using the value that is being given by the user.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

// pascal_triangle.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 19, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com

import java.util.Scanner;

public class pascal_triangle{

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
                char ch;
         do {   
      System.out.println();
               System.out.print("\t Pascal Triangle Generator ");
               System.out.println("\n");
      
               System.out.print("Enter a number please  : "); 
              int value = input.nextInt();
     System.out.println();
              for(int i =0;i<value;i++) {

              int number = 1;

              System.out.format("%"+(value-i)*2+"s","");

            for(int j=0;j<=i;j++) {
                 System.out.format("%4d",number);
                 number = number * (i - j) / (j + 1);
            }
           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");
}
}

Number to Words in Java

A simple program that I wrote that will ask the user to enter decimal number and then our program will translate the given number into words using Java programming language.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

// numbers_words.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 19, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com

import java.util.Scanner;

public class numbers_words {

      

public static void main(String args[]) {
   
            Scanner input = new Scanner(System.in);
            char ch;
            
        do {
       int value=0,thousands=0,hundreds=0,tens=0,ones=0,zero=0,elevens=0;
             
    
        System.out.print("\t NUMBERS TO WORDS  ");
        System.out.println();
    System.out.print("Kindly Give a Number :  ");
        value = input.nextInt();

    if (value==0){

    switch (value){
    case 0: System.out.println("Zero");break;

    }
    }

    if ((value>=100) && (value<=10000)){

    thousands = value/1000;
    value = value%1000;
    hundreds = value/100;
    value= value%100;

    switch(thousands){

    case 1:System.out.print("One Thousand ");break;
    case 2:System.out.print("Two Thousand ");break;
    case 3:System.out.print("Three Thousand ");break;
                                case 4:System.out.print("Four Thousand ");break;
    case 5:System.out.print("Five Thousand ");break;
                                case 6:System.out.print("Six Thousand ");break;
    case 7:System.out.print("Seven Thousand ");break;
                                case 8:System.out.print("Eight Thousand ");break;
                                case 9:System.out.print("Nine Thousand ");break;
    case 10:System.out.print("Ten Thousand ");break;
    }


    switch (hundreds) {
    case 1:System.out.print("One Hundred ");break;
    case 2:System.out.print("Two Hundred ");break;
    case 3:System.out.print("Three Hundred ");break;
    case 4:System.out.print ("Four Hundred ");break;
    case 5:System.out.print ("Five Hundred ");break;
    case 6:System.out.print ("Six Hundred ");break;
    case 7:System.out.print("Seven Hundred ");break;
    case 8:System.out.print ("Eight Hundred ");break;
    case 9:System.out.print ("Nine Hundred ");break;


    }
    }


if ((value>10) && (value<20)){

tens = value/ 10;
ones = value;
elevens = value % 10;


switch (elevens){
case 1:System.out.print("Eleven ");break;
    case 2:System.out.print("Twelve ");break;
    case 3:System.out.print("Thirteen ");break;
    case 4:System.out.print ("Fourteen ");break;
    case 5:System.out.print ("Fifteen ");break;
    case 6:System.out.print ("Sixteen ");break;
    case 7:System.out.print("Seventeen ");break;
    case 8:System.out.print ("Eighteen ");break;
    case 9:System.out.print ("Nineteen ");break;
    }
}
if (value>10000){
System.out.print("INVALID INPUT");
}

else {
tens = value/10;
value = value%10;
ones = value;

switch (tens) {

case 1: System.out.print("Ten ");break;
case 2:System.out.print("Twenty ");break;
case 3:System.out.print("Thirty ");break;

case 4:System.out.print("Fourty ");break;
case 5:System.out.print("Fifty ");break;
case 6:System.out.print("Sixty ");break;
case 7:System.out.print("Seventy ");break;
case 8:System.out.print("Eighty ");break;
case 9: System.out.print("Ninety ");break;
}
switch (ones){

case 1: System.out.print("One ");break;
case 2:System.out.print("Two ");break;
case 3:System.out.print("Three ");break;

case 4:System.out.print("Four ");break;
case 5:System.out.print("Five ");break;
case 6:System.out.print("Six ");break;
case 7:System.out.print("Seven ");break;
case 8:System.out.print("Eight ");break;
case 9:System.out.print("Nine ");break;

                }

}
     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");
                 
}   

  }

Greatest Common Divisor in Java

A simple program that will ask the user to enter two integer number and then our program will check and compute the Greatest Common Divisor or GCD of the two numbers given by our user.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

// gcd.java
// Programmer : Mr. Jake R. Pomperada, MAED-IT
// Date       : July 19, 2015
// Tools      : Netbeans 8.0.2
// Email      : jakerpomperada@yahoo.com and jakerpomperada@gmail.com

// Write a program that will check and determine the greatest common divisor
// of two numbers given by the user.


import java.util.Scanner; 

public class gcd {

    static int gcd(int m, int n, int d)
    { if (d==-1) 
        d = m>n ? n : m; 
    if (m%d==0 && n%d==0) 
        return d; 
    else 
        return gcd(m, n, d-1); 
    } 
    
    public static void main(String args[])
    { 
        
        Scanner input = new Scanner(System.in); 
        char ch;
    do {
      int m=0, n=0; 
      System.out.println();
      System.out.print("\t GREATEST COMMON DIVISOR SOLVER ");
      System.out.println("\n");
      System.out.print("Enter first number: "); 
      m = input.nextInt();
      System.out.print("Enter second number: "); 
      n = input.nextInt(); 
      System.out.print("The Greatest Common Divisor of "+m+" and "+n+" is "); 
      System.out.print(gcd(m, n, -1)+ "."); 
      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");
    } 
}



Simple Interest Solver in Java

A simple program that I wrote in Java that will ask the user to give the amount loaned, time and interest in the amount and then I will compute the interest rate in the given amount which is being borrowed by the client or customer.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

// Problem : Write a program in Java that computes for simple interest for the amount // that is  being borrow from a bank or financial institution. 
// Date:  June 28, 2015
// Written By: Mr. Jake R. Pomperada, MAED-IT
// Email Address: jakerpomperada@yahoo.com and jakerpomperada@gmail.com

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

class interest {
    public static float compute_interest_rate(float principal_amount, float rate, float time)
    {
        float solve_interest = (principal_amount*rate*time)/100;
        return(solve_interest);
    }

public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
  DecimalFormat df = new DecimalFormat("###.##");
   char a;
do
    {

  System.out.println();
  System.out.println("===== SIMPLE AMOUNT INTEREST SOLVER =====");
  System.out.println();
  System.out.print("Enter principle amount being borrowed : PHP ");
  float amount = scan.nextFloat();
      
  System.out.print("Enter number of years to be paid      : ");
  float year = scan.nextFloat();
      
  System.out.print("Enter annual interest rate            : ");
  float rate = scan.nextFloat();
      
  float amount_to_be_paid = compute_interest_rate(amount, rate, year);
      
  System.out.println();

  System.out.print("The total amount of interest to be paid is PHP " + df.format(amount_to_be_paid) +"."); 
 
    System.out.println("\n\n");
    System.out.print("Do you Want To Continue (Y/N) :=> ");
    a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
     System.out.println("\n");
     System.out.println("\t ===== END OF PROGRAM ======");
     System.out.println("\n");
   }
  
  }  // End of Program



Saturday, July 18, 2015

Consonants Remover in Java

In this article I would like to share with you a sample program that will remove any consonants letters in a word or string in Java. The code is very simple and easy to understand.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.comand 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

/* remove_consonants.java */
/* Written By: Mr. Jake R. Pomperada, MAED-IT */
/* July 14, 2015 */
/* This program will remove consonants in a given word or string by the user */

import java.util.Scanner;
 
class remove_consonants
{
 
    private static String remove_Consonants(String s) {  
        String finalString = "";  
        for (int i = 0;i < s.length(); i++) {      
            if (!isConsonants(Character.toLowerCase(s.charAt(i)))) {  
                finalString = finalString + s.charAt(i);  
            }  
        }  
        return finalString;  
    }

    private static boolean isConsonants(char c) {  
        String consonants = "bcdfghjklmnpqrstvwxyz";   
        for (int i=0; i<21; i++) {   
            if (c == consonants.charAt(i))  
                return true;  
        }  
        return false;     
    }  
    
    
    public static void main(String args[])
   {
      String words;
      char ch;
      do {
      Scanner input = new Scanner(System.in);
      System.out.println();
      System.out.print("\t CONSONANTS REMOVER PROGRAM ");
      System.out.println("\n");
      System.out.print("Kindly enter a word :=> ");
      words= input.nextLine();
      System.out.println("The original words is " + words + ".");
      String final_words = remove_Consonants(words);
      System.out.println("The remaining letters is " + final_words + ".");
       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");
      
      }
}