Saturday, July 25, 2015

Sum of Numbers Using While Loop

A simple program that will sum up the  series of number using while looping statement in Java.

If you have some questions about programming, about my work please send mu 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

/*
while_loops.java
Programmer By: Mr. Jake R. Pomperada, MAED-IT
Date : July 21, 2015

Problem No. 1:
  
Design a program that calculates the sum of the input given
number of N using while loop statement.

*/


import java.util.Scanner;

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

    Scanner input = new Scanner(System.in);

    int sum=0,b=0;
    System.out.print("\t Sum of Numbers Using While Loop");
    System.out.println();
    System.out.print("Enter your desired looping number : ");
    int value = input.nextInt();
    while (b<=value) {
      System.out.print(" " + b + " ");
        sum+=b;
        b++;
    }   
    System.out.println();
    System.out.println("The total sum is  " + sum +".");
    System.out.println();
    System.out.println(" END OF PROGRAM"); 
    System.out.println();
  }
}

Word Count in Java

A program that I wrote in Java that will ask the user to enter a sentence and then our program will count the number of words in a given sentence.

If you have some questions about programming, about my work please send mu 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

/* word_count.java */
/* Written By: Mr. Jake R. Pomperada, MAED-IT */
/* July 15, 2015 */
/* This program will count the number of words in a given sentence by the user */

import java.util.Scanner;

class word_count {

    
    private static int word_count(String phrase)
    {
    if (phrase == null)
       return 0;
    return phrase.trim().split("\\s+").length;
    }

public static void main(String args[])
   {
      String words;
      char ch;

      do {
          Scanner input = new Scanner(System.in);
          System.out.println();
          System.out.print("\t WORD COUNT PROGRAM ");
          System.out.println("\n");
          System.out.print("Kindly enter a word :=> ");
          words= input.nextLine();
          System.out.println();
          System.out.print("The total number of words is " + word_count(words) +".");
          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");    
   }
}


Database Connection in JSP and MySQL

In this article I would like to share with you a code to check whether JSP and MySQL is connected to one another or not. This code is very useful if you want to know if JSP and MySQL are working together.

If you have some questions about programming, about my work please send mu 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.


Program Listing


dbconnect.jsp


<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<html> 
<head> 
<title>Connection with mysql database</title>
</head> 
<body>
<h1>Connection status</h1>
<%
Connection conn=null;
ResultSet result=null;
Statement stmt=null;
ResultSetMetaData rsmd=null;
try {
  Class c=Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){
  out.write("Error!!!!!!" + e);
}
try {
  conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/users",
   "root","");
  out.write("Connected!");
}
catch(SQLException e) {
  System.out.println("Error!!!!!!" + e);
}
%>
</body> 
</html>

Login and Registration in JSP and MySQL

In this article I am very happy to share with you my readers of my site a simple program that I wrote how to write a system using Java Server Pages and MySQL to login and register a user for our website. Basically an JSP code or snipplets is also a servlet used primarily for presentation in Java. This program will allow the visitor of the website to register their user name and password. After they are registered they can able to login in the website.

I make sure the code is not very long and very easy to understand. I hope you will find my wok useful in your programming projects and assignments.

If you have some questions about programming, about my work please send mu 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

<!-- login.jsp -->
<!-- Written By: Mr. Jake R. Pomperada,MAED-IT -->
<!-- Date      : July 24, 2015                 -->
<!-- Tools     : Netbeans IDE 8.0.2, Java SE 8 and Apache Tomcat Server -->
<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<style>
    table, td, th,h3 {
    border: 1px solid green;
    font-family: arial;
    color: blue;
}

table {
    background-color: lightgreen;
   }
</style>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
    <h3> Login System and Registration System in JSP and MySQL </h3>  
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Login"></td></tr>
<tr><td></td><td><a href="register.jsp" title="Click here to register account">
Register </a></td></tr>
</table>
</form>
</html>


// check.jsp
// Written By: Mr. Jake R. Pomperada,MAED-IT
// Date      : July 24, 201
// Tools     : Netbeans IDE 8.0.2, Java SE 8 and Apache Tomcat Server

<%@page import="java.sql.*"%>
<%
try{
String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/users","root","");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
           int count=0;
           while(rs.next()){
           count++;
          }
          if(count>0){
           out.println("<body bgcolor='lightgreen'>");   
           out.println("<h1> Welcome  "+ user + " in the website. </h1>");
           out.println("</body>");
          }
          else{
           response.sendRedirect("login.jsp");
          }
        }
    catch(Exception e){
    System.out.println(e);
}
%>


<!-- register.jsp -->
<!-- Written By: Mr. Jake R. Pomperada,MAED-IT -->
<!-- Date      : July 24, 2015                 -->
<!-- Tools     : Netbeans IDE 8.0.2, Java SE 8 and Apache Tomcat Server -->

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>
<html>
<head>
<title>Registration Page </title>
</head>
<body>
<style>
    table, td, th {
    border: 1px solid green;
    font-family: arial;
    color: blue;
}

table {
    background-color: lightgreen;
   }
</style>
<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>

<table border="1" width="50%">
<tr>
<td width="100%">
<form method="POST" action="save_login.jsp">

<h2 align="center">Register User Name and Password</h2>
<table border="1" width="100%">
<tr>
<td width="50%"><b>Username:</b></td>
<td width="50%"><input type="text" name="username" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Password:</b></td>
<td width="50%"><input type="text" name="password" size="20"></td>
</tr>
<tr>
</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</form>
</td>
</tr>
</table>
<% out.println("<br>");
out.println("<a href='login.jsp'> RETURN TO LOGIN PAGE </a>");
%>
</body>
</html>

// save_login.jsp
// Written By: Mr. Jake R. Pomperada,MAED-IT
// Date      : July 24, 201
// Tools     : Netbeans IDE 8.0.2, Java SE 8 and Apache Tomcat Server

<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<%
out.println("<style>  p {font-family: arial;"
           + " color: red; font-size: 16;   }; "
           + "</style>");
out.println("<style>  a,b {font-family: arial;"
           + " color: blue; font-size: 16;   }; "
           + "</style>");

%>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "users";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","");
try{
Statement st = con.createStatement();
String username=request.getParameter("username");
String password=request.getParameter("password");


int val = st.executeUpdate("INSERT login "
        + "VALUES(id,'"+username+"','"+password+"')");

con.close();
out.println("<p> The record is successfully saved. </p>");
out.println("<br>");
out.println("<a href='login.jsp'> RETURN TO LOGIN PAGE </a>");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

%>




Thursday, July 23, 2015

Passed and Failed Program in Java

This is a program in Java that I wrote using one dimensional array as my data structure that will check the number of passing and failing grade of students. The code is very simple yet very useful for students and other people who are getting started learning Java programming.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu 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

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

Problem No. 4:
  
Write a program that will ask the user to give ten grades and then
the program will enumerate the passing and failing grade based on
the grades given by the user. Take note the passed grade is 75%.
*/
              

import java.util.Scanner;

class pass_failed_grades_array{
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
        
  do { 
      int [] values; 
      values  = new int[10];  
      int x=0;
      int no_passed=0, no_failed=0;
      System.out.print("PASS AND FAILED GRADE PROGRAM");
      System.out.println();
      for (int a=0; a<10; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no. " + x + " : ");
         values[a] = input.nextInt();
        }       
         System.out.println(); 
         System.out.print("LIST OF PASSING GRADES");
         System.out.println();
      for (int a=0; a<10; a++)
      {
         if(values[a]>= 75) {
                System.out.print(" " + values[a]+ " ");
                no_passed++;  
           }
       
      }        
      System.out.println(); 
      System.out.print("LIST OF FAILING NUMBERS ");
      System.out.println(); 
      for (int a=0; a<10; a++)
      {
         if(values[a] < 75) {
               System.out.print(" " + values[a]+ " ");
               no_failed++;  
              }
      }     
     System.out.println("\n\n");  
     System.out.println("Number of Passing Grade is " + no_passed + ".");
     System.out.println("Number of Failing Grade is " + no_failed + ".");
     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");
  }
} // End of Code
    

Positive and Negative Numbers in Java

This simple program will give you a first hand idea how to use one dimensional array in Java. What the program does is to ask the user to give a series of numbers and then the program will display the positive and negative numbers that is being 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 mu 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

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

Problem No. 4:
  
Write a program that will ask the user to give ten numbers and then
the program will enumerate the positive and negative numbers based 
on the given numbers by the user.
*/
              

import java.util.Scanner;

class positive_negative_numbers_array{
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
        
  do { 
      int [] values; 
      values  = new int[10];  
      int x=0;
      System.out.print("POSITIVE AND NEGATIVE NUMBERS PROGRAMS");
      System.out.println();
      for (int a=0; a<10; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no. " + x + " : ");
         values[a] = input.nextInt();
        }       
         System.out.println(); 
         System.out.print("LIST OF POSITIVE NUMBERS");
         System.out.println();
      for (int a=0; a<10; a++)
      {
         if(values[a]>= 0) {
                System.out.print(" " + values[a]+ " ");
                }
       
      }        
      System.out.println(); 
      System.out.print("LIST OF NEGATIVE NUMBERS ");
      System.out.println(); 
      for (int a=0; a<10; a++)
      {
         if(values[a] < 0) {
               System.out.print(" " + values[a]+ " ");
                }
      }     
     System.out.println("\n\n"); 
     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");
  }
} // End of Code
    

Odd and Even Numbers in Java

I this article I would like to share with you a program that I wrote in Java SE I called this program Odd and Even Numbers Program that will ask the user to enter a series of numbers and then our program will list down the even and odd numbers using one dimensional array as our data structure.

I hope you will find my work useful and beneficial. If you have some questions about programming, about my work please send mu 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

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

Problem No. 3:
  
Write a program that will ask the user to give ten numbers and then
the program will enumerate the odd and even numbers based on the 
given numbers by the user.
*/
              

import java.util.Scanner;

class odd_even_numbers_array {
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
        
  do { 
      int [] values; 
      values  = new int[10];  
      int x=0;
      System.out.print("ODD AND EVEN NUMBERS PROGRAMS");
      System.out.println();
      for (int a=0; a<10; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no. " + x + " : ");
         values[a] = input.nextInt();
        }       
         System.out.println(); 
         System.out.print("LIST OF EVEN NUMBERS");
         System.out.println();
      for (int a=0; a<10; a++)
      {
         if(values[a]%2 == 0) {
                System.out.print(" " + values[a]+ " ");
                }
      }        
      System.out.println(); 
      System.out.print("LIST OF ODD NUMBERS ");
      System.out.println(); 
      for (int a=0; a<10; a++)
      {
         if(values[a]%2 != 0) {
               System.out.print(" " + values[a]+ " ");
                }
      }     
     System.out.println("\n\n"); 
     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");
  }
} // End of Code
    


Grade Solver in Java

A program that I wrote in Java that will compute the average grade of the student in different subjects. I am using one dimensional array in this sample program 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 mu 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

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

Problem No. 2:
  
Write a program that will ask the user to give eight grades for
eight subjects and then our program will find average grade of 
the student from the eight subjects.
*/
              

import java.util.Scanner;

class grade_array {
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
     String[] subjects = new String[]
     {"Computer", "Math", "English","Physical Education",
      "History","Science","Music and Arts","Filipino"};
     
  do { 
      int [] values; 
      values  = new int[8];  
      int x=0,average_grade=0,total_sum=0;
      System.out.print("Average Grade Solver");
      System.out.println();
      for (int a=0; a<8; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter your subject grade on " + subjects[a] + " : ");
         values[a] = input.nextInt();
         total_sum+=values[a];
         average_grade = total_sum/8;
      }
     System.out.println(); 
     System.out.println();
     System.out.print("Your average grade is 8 subject is " + average_grade + ".");
     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");
  }
} // End of Code

Sum and Average of Five Numbers in Java

In this article I would like to share with you a very simple programs intended for beginners I called this program Sum and Average of Five Numbers in Java that uses one dimensional array. What does this program will do is ask the user to enter five numbers and then it will find the sum and average of the given numbers 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

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

Problem No. 1:
  
Write a program that will ask the user to give five numbers 
and then our program will find the total sum and average of
five numbers using an array.
*/


import java.util.Scanner;

class average_array {
    
public static void main(String[] args) {
      
     Scanner input = new Scanner(System.in);
     char ch;
   
  do { 
      int [] values; 
      values  = new int[5];  
      int x=0, total_sum=0, average=0;
      System.out.print("Sum and Average of Five Numbers");
      System.out.println();
      for (int a=0; a<5; a++)
      {
         x=1;
         x+=a;
         System.out.print("Enter value in item no." + x + " : ");
          
         values[a] = input.nextInt();
         total_sum += values[a];
         average = total_sum/5;
      }
     System.out.println(); 
     System.out.print("The total sum is " + total_sum + ".");
     System.out.println();
     System.out.print("The average of five numbers is " + average + ".");
     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");
  }
}