Showing posts with label ST II - (116). Show all posts
Showing posts with label ST II - (116). Show all posts

Tuesday, April 3, 2012

Java, MySQL and iReports (ST II Assignment)

For our ST II subject at SLIIT in the 1st semester of the 2nd year, we had to develop an application using Java, MySQL and iReports. I used NetBeans as the IDE for the development. Using the application, the user can insert, update and delete and view records in the database. The application is for adding employees, adding projects and assigning employees to the projects. The application also generates two iReports to view details of projects.

This is the initial form of the application. 

Some other forms are shown below. 



The database schema is attached in the project. First create the database with tables in MySQL server. You will have to change the database connection parameters in the project according to your server details. 


-Tharindu Edirisinghe-
-SLIIT 10'-

Thursday, February 10, 2011

Java program to validate an Email

This java program accepts an email address as a user input and it can validate and give a particular error message if the email is invalid.


import java.io.*;
public class EmailValidate
{
    public static void main(String args[]) throws IOException
    {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String email;
        boolean status = true;

        System.out.print("Enter your email address : ");
        email = br.readLine();

        char firstCharacter = email.charAt(0);

        if( ! Character.isLetter(firstCharacter))
        {
               System.out.println("Invalid Email ! First character must be a letter !");
               status = false;
        }

       if(email.indexOf('@') < 0)
       {
            System.out.println("Invalid Email ! '@' is not present !!!");
            status = false;
       }
       
       else if( email.indexOf('@') != email.lastIndexOf('@') )
       {
           System.out.println("Cannot Have more than one '@' characters !!!");
           status = false;
       }

        if(email.indexOf('.') < 0)
       {
            System.out.println("Invalid Email ! '.' is not present !!!");
            status = false;
       }
       
       else if( email.indexOf('.') != email.lastIndexOf('.') )
       {
           System.out.println("Cannot Have more than one '.' characters !!!");
           status = false;
       }
       if((email.indexOf('@') > email.indexOf('.')) & status)
       {
           System.out.println("Invalid Email ! '@' should come before '.' ");
           status = false;

       }
       
       int indexAt = email.indexOf('@');
       int indexDot = email.indexOf('.');
       int length = email.length();

       if(indexDot == indexAt + 1)
       {
           System.out.println("No service provider spacefied ! Invalid email !");
           status = false;
       }
       if(indexDot+2 > length)
       {
           System.out.println("No Domain name specified ! Invalid email !");
           status = false;
       }

       if(status == true)
        {
            

            char userName [] = new char[indexAt];
            char service [] = new char[indexDot - indexAt - 1];
            char domain [] = new char[length - indexDot - 1];

            for(int iuser = 0; iuser< indexAt; iuser++)
                userName[iuser] = email.charAt(iuser);

            int slimit = 0;
            for(int iservice = indexAt+1; iservice< indexDot; iservice++)
            {
                service[slimit] = email.charAt(iservice);
                slimit++;

            }

            int dlimit = 0;
            for(int idomain = indexDot+1; idomain< 1)
            {
                System.out.println("Invalid username !");
                status = false;
            }
            if(service.length < 1)
            {
                System.out.println("Invalid service provider !");
                status = false;
            }
            if(domain.length < 1)
            {
                System.out.println("Invalid Domain name !");
                status = false;
            }

       }
       if(status == true)
            System.out.println("Valid Email. Successfully Validated.");
        


    }
}


-Tharindu Edirisinghe-
-SLIIT 10'-

Tuesday, January 4, 2011

First Lab of Software Technology II subject

For the whole first year, we learned C++. This year we learn Java for the subject 'Software Technology II'. Today we had the very first lab session for this subject. I could complete all the lab exercises within the lab session it-self. Special Thanks to the authors of the blog 'අපි Java ඉගෙන ගනිමු'. During my 2 months holiday after the 1st year 2nd semester exam, I went through that blog and learned the basic syntax of Java.

class Exercise1
{
public static void main(String args[])
{
System.out.println();
System.out.println("Hello World !");

System.out.println();

System.out.println("It's been nice knowing you.");

System.out.println();

System.out.println("Goodbye world !");

System.out.println();
}
}




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

System.out.println("======================================");
System.out.println();
System.out.println("=         Student Information        =");
System.out.println(); 
System.out.println("======================================");
System.out.println();
System.out.println("= Name        :  ARDP Ranasinghe     =");
System.out.println();
System.out.println("= Reg No      :  DIS\\08\\M4\\1234      =");
System.out.println();
System.out.println("= Address     :  Malabe              =");
System.out.println();
System.out.println("======================================");
}
}


class Exercise3
{
public static void main(String args[])
{
System.out.println();
System.out.println();

System.out.println("* * * * *");
System.out.println();
System.out.println("* * * * *");
System.out.println();
System.out.println("* * * * *");
System.out.println();
System.out.println("* * * * *");
System.out.println();
System.out.println();
System.out.println("    *");
System.out.println();
System.out.println("   * *");
System.out.println();
System.out.println("  * * *" );
System.out.println();
System.out.println(" * * * *");
System.out.println();
System.out.println();

}
}




class Exercise4
{
public static void main(String args[])
{
System.out.println();
System.out.println();

System.out.println("* * * * *          *");
System.out.println();
System.out.println("* * * * *         * * ");
System.out.println();
System.out.println("* * * * *        * * *");
System.out.println();
System.out.println("* * * * *      * * * * *");

System.out.println();
System.out.println();
}

}

class Exercis3loops
{
public static void main(String args[])
{
System.out.println();
System.out.println();

for(int row=1; row<=4; row++)
{

for(int i=1; i<=5; i++)
{
System.out.print("* ");
}
System.out.println();
}

System.out.println();


for(int r=1; r<=5; r++)
{
for(int x=6; x>=r; x--)
{
System.out.print(" ");
}

for(int s=1; s<=r; s++)
System.out.print("* ");

System.out.println();
}

System.out.println();
}
}

P.S - Recently I closed the blog as I was continuously receiving bad comments from 'Anonymous' people. But after much thought I decided to continue writing my blog.

-Tharindu Edirisinghe-
-SLIIT 10'-