Friday, 24 October 2014

ICSE PROJECT for accepting data of employees, searching for a particular employee, deleting a particular employee, displaying the data of a particular employee and finally exiting.

/* ICSE project for accepting data of employees, searching for a particular employee,  deleting a particular employee, displaying the data  of a  particular employee and finally exiting. */
           

import java.util.Scanner ;
public class Employee1
{
    // Declaration of instance variables
   
    private int empId;
    private String empName;
    private double empSalary;
    private String empAddress;
   
    //An araray of objects is being created
   
    private Employee1 arr[] ;
    private boolean emp_isDeleted ;
   
    private static Scanner sc = new Scanner(System.in);

    //  The default Constructor for objects of class Emplyoee

     public Employee1(){
        // initialise instance variables
        empId = 0;
        empName = new String();
        empSalary = 0.0;
        empAddress = new String();
        emp_isDeleted = false;
    }

    // Function  to accepts the data required for the object.
   
    public void input(){
        System.out.print("Enter Id : ");
        this.empId = sc.nextInt();
        System.out.print("Enter Salary : ");
        this.empSalary = sc.nextDouble();
        sc.nextLine();
        System.out.print("Enter the Name : ");
        this.empName = sc.nextLine();
        System.out.print("Enter the Address : ");
        this.empAddress = sc.nextLine();
        emp_isDeleted = false;
    }
       
    // A search funtion based on Linear search strategy
   
    public int search(int check_empId){
        int position=-1;
        for(int i = 0;i<arr.length;i++){
            if (arr[i].empId == check_empId)
            {
                position = i ;
                break;
            }
        }
        return position;
    }
   
    // The function creates, fills and returns an array of the Employee1
   
    public Employee1[] makeAndFillArray(){
        System.out.print("enter no. of Employee1s :");
        int num = sc.nextInt();
        arr = new Employee1[num];
        for(int i = 0;i<arr.length;i++){
            System.out.println("this is for the emplyoee number "+(i+1)+". :");
            arr[i] = new Employee1();
            arr[i].input();
        }
        return arr ;
    }
   
    //funtion to delete record based on empId
   
    public void delete(){
        if(emp_isDeleted){
            System.out.println("already deleted.");
        }
        else{
            emp_isDeleted = true;
            System.out.println("the Employee1 object has been deleted.");
        }
    }
   
    //Funtion to display the content
   
    public void display(){
        if(emp_isDeleted){
            System.out.println("The object of "+empName+", and of id : "+empId+" is deleted.");
        }
        else{
            System.out.println("Employee1 name : "+empName);
            System.out.println("Employee1 ID : "+empId);
            System.out.println("Employee1 Salary : "+empSalary);
            System.out.println("Employee1 Address : "+empAddress);
        }
    }
   
    // The main function to generate a menu based program
   
    public static void main(String[] args){
        Employee1 obj = new Employee1();
        int choice = 0;
        while(choice<5){
            System.out.println("          \t\t MAIN MENU :");
            System.out.println("---------------------------------");
            System.out.println("\t 1.INPUT DATA");
            System.out.println("\t 2.SEARCHING DATA");
            System.out.println("\t 3.DELETING DATA");
            System.out.println("\t 4.DISPLAYING DATA");
            System.out.println("\t 5.EXIT");
           
         
            do{
                System.out.print("enter choice(1 - 4) : ");
                choice = sc.nextInt();
            }while(choice<1 && choice>5);
           
           
            switch(choice){
                case 1:
                System.out.println("Accepting Data ");
                obj.makeAndFillArray();
                break;
               
                case 2:
                System.out.print("Enter the Employee1's id no. to be searched : ");
                int id = sc.nextInt();
                if(obj.search(id)>-1){
                    System.out.println("Search successful, Employee1 found at "+(obj.search(id)+1));
                    System.out.println("The details are : ");
                    obj.arr[obj.search(id)].display();
                }
                else{
                    System.out.println("Search unsuccessful");
                }
                break;
               
                case 3:
                System.out.print("Enter the id number to be deleted : ");
                int id1 = sc.nextInt();
                int position = obj.search(id1);
                obj.arr[position].delete();
                break ;
               
                case 4:
                System.out.println("Displaying data :");
                for(int i = 0;i<obj.arr.length;i++){
                    obj.arr[i].display();
                }
                break;
            }
        }
        System.out.println("The End of the Project");
    }
}

Find the longest and the smallest word in a sentence and print their length.

//Find the longest and the smallest word in a sentence and print their length.

import java.io.*;
class LongestSmallest1
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string");
String s=br.readLine();
s=s+" ";
int l=s.length();
String word="", lword="", sword="";
int max=0,min=0;

for(int i=0;i<l;i++)
{
char x=s.charAt(i);
if(x!=' ')
word=word+x;
else
{
if(word.length()>max)
{
max=word.length();
lword=word;
    }
 word="";
    }
    }
     
for(int i=0;i<l;i++)
{
char x=s.charAt(i);
if(x!=' ')
min=min+x;
else
break;
    }
    
for(int i=0;i<l;i++)
{    
char x=s.charAt(i);
if(x!=' ')
word=word+x;
else
{
if(word.length()< min)
{
min=word.length();
sword=word;
    }
 word="";
    }
    }
    System.out.println("Longest word : " + lword);
    System.out.println("Length of Longest word : " + max);
    System.out.println("Smallest word : " + sword);
    System.out.println("Length of Smallest word : " + min);
    }
    }

Program to find the sum of positive even numbers, positive odd numbers and negative numbers from a list of numbers entered.


/*Program to find the sum of positive even numbers,positive odd numbers and negative numbers from
  a list of numbers entered*/
 
  import java.io.*;
  public class sum_num
  {
      public static void main(String args[])throws IOException
      {
          InputStreamReader read=new InputStreamReader(System.in);
          BufferedReader in=new BufferedReader(read);
          int num,sum_e,sum_o,sum_n;
          sum_e=0;sum_o=0;sum_n=0;
          System.out.println("Enter 0 to terminate the list:");
        do
        {
            System.out.println("Enter a number:");
            num=Integer.parseInt(in.readLine());
            if(num>0)
            {
                if(num%2==0)
                sum_e=sum_e+num;
                else
                sum_o=sum_o+num;
            }
            if(num<0)
            sum_n=sum_n+num;
        }
        while(num!=0);
        System.out.println("Sum of positive even numbers:"+sum_e);
        System.out.println("Sum of positive odd numbers:"+sum_o);
        System.out.println("Sum of negative numbers:"+sum_n);
    }
}
       
  

Program to find the total numbers of characters vowels and reverse of string.

/* Program to find the total numbers of characters vowels and reverse of string */

import java.io.*;
public class count_reverse
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader read= new InputStreamReader(System.in);
        BufferedReader in =new BufferedReader(read);
        String st,uc,rev=" ";
        int len,i,count=0;
        char ch;
        System.out.println("Enter String:");
        st=in.readLine();
        uc=st.toUpperCase();
        len=st.length();
        for(i=0;i<len;i++)
        {
            ch=uc.charAt(i);
            if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
            count++;
        }
        for(i=len-1;i>=0;i--)
        {
            ch=uc.charAt(i);
            rev=rev+ch;
        }
        System.out.println("Total number of characters:"+len);
        System.out.println("Numbers of vowels:"+count);
        System.out.println("Reverse of String:"+rev);
    }
}
       

     
 

 

Program to print the day of the date entered by the user in the form of dd-MON-2014 for the year 2014 only.

/* Program to print the day of the date entered by the user
in the form of dd-MON-2014 for the year 2014 only */

import java.io.*;
public class dayofdate
{
    public static void main(String args[])throws IOException
    {
        InputStreamReader read = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(read);
        String dt = "", dd, mnth;
        int dd1, res;
        System.out.println("Enter the date : (dd-MON-2014)");
        dt=in.readLine();
        //fetching the dd of the given date
        dd=dt.substring(0,2);
        dd1=Integer.parseInt(dd);      
        res=dd1%7;
       
        //fetching the mon of the given date
        mnth=dt.substring(3,6);
        mnth=mnth.toUpperCase();
     
        // Fetching the day for the month of January or October
        if(mnth.equals("JAN") || mnth.equals("OCT"))
        {
            if(dd1>0 && dd1<=31)
            {
            if(res==1)
                System.out.println(dt + " is Wednesday. ");
            else if(res==2)
                System.out.println(dt + " is Thursday. ");
            else if(res==3)
                System.out.println(dt + " is Friday. ");
            else if(res==4)
                System.out.println(dt + " is Saturday. ");
            else if(res==5)
                System.out.println(dt + " is Sunday. ");
            else if(res==6)
                System.out.println(dt + " is Monday. ");
            else
                System.out.println(dt + " is Tuesday. ");
            }
            else
            {
                if(mnth.equals("JAN"))
                    System.out.println(dt + " : Invalid date!!! January has dates from 1 to 31 only ");
                if(mnth.equals("OCT"))
                    System.out.println(dt + " : Invalid date!!! October has dates from 1 to 31 only ");  
            }
               
        }
        // Fetching the day for the month of February or March or November
        else if(mnth.equals("FEB") || mnth.equals("MAR") || mnth.equals("NOV"))
        {
            if((mnth.equals("FEB") && dd1>0 && dd1<=28) || (mnth.equals("MAR") && dd1>0 && dd1<=30) || (mnth.equals("NOV") && dd1>0 && dd1<=30))
            {
            if(res==1)
                System.out.println(dt + " is Saturday. ");
            else if(res==2)
                System.out.println(dt + " is Sunday. ");
            else if(res==3)
                System.out.println(dt + " is Monday. ");
            else if(res==4)
                System.out.println(dt + " is Tuesday. ");
            else if(res==5)
                System.out.println(dt + " is Wednesday. ");
            else if(res==6)
                System.out.println(dt + " is Thursday. ");
            else
                System.out.println(dt + " is Friday. ");
            }
            else
            {
                if(mnth.equals("FEB"))
                    System.out.println(dt + " : Invalid date!!! February has dates from 1 to 28 ");
                if(mnth.equals("MAR"))
                    System.out.println(dt + " : Invalid date!!! March has dates from 1 to 30 ");
                if(mnth.equals("NOV"))
                    System.out.println(dt + " : Invalid date!!! November has dates from 1 to 30 ");
            }
        }
        // Fetching the day for the month of April or July
        else if(mnth.equals("APR") || mnth.equals("JUL"))
        {
            if(dd1>0 && dd1<=30)
            {
            if(res==1)
                System.out.println(dt + " is Tuesday. ");
            else if(res==2)
                System.out.println(dt + " is Wednesday. ");
            else if(res==3)
                System.out.println(dt + " is Thursday. ");
            else if(res==4)
                System.out.println(dt + " is Friday. ");
            else if(res==5)
                System.out.println(dt + " is Saturday. ");
            else if(res==6)
                System.out.println(dt + " is Sunday. ");
            else
                System.out.println(dt + " is Monday. ");
            }
            else
            {
                if(mnth.equals("APR"))
                    System.out.println(dt + " : Invalid date!!! April has dates from 1 to 30 only ");
                if(mnth.equals("JUL"))
                    System.out.println(dt + " : Invalid date!!! July has dates from 1 to 30 only ");  
            }
        }
        // Fetching the day for the month of May
        else if(mnth.equals("MAY"))
        {
            if(dd1>0 && dd1<=31)
            {          
            if(res==1)
                System.out.println(dt + " is Thursday. ");
            else if(res==2)
                System.out.println(dt + " is Friday. ");
            else if(res==3)
                System.out.println(dt + " is Satday. ");
            else if(res==4)
                System.out.println(dt + " is Sunday. ");
            else if(res==5)
                System.out.println(dt + " is Monday. ");
            else if(res==6)
                System.out.println(dt + " is Tuesday. ");
            else
                System.out.println(dt + " is Wednesday. ");
            }
            else
            {
                if(mnth.equals("MAY"))
                    System.out.println(dt + " : Invalid date!!! May has dates from 1 to 31 only ");
            }
        }
        // Fetching the day for the month of June
        else if(mnth.equals("JUN"))
        {
           if(dd1>0 && dd1<=30)
            {
            if(res==1)
                System.out.println(dt + " is Sunday. ");
            else if(res==2)
                System.out.println(dt + " is Monday. ");
            else if(res==3)
                System.out.println(dt + " is Tuesday. ");
            else if(res==4)
                System.out.println(dt + " is Wednesday. ");
            else if(res==5)
                System.out.println(dt + " is Thursday. ");
            else if(res==6)
                System.out.println(dt + " is Friday. ");
            else
                System.out.println(dt + " is Saturday. ");
            }
            else
            {
                if(mnth.equals("JUN"))
                    System.out.println(dt + " : Invalid date!!! June has dates from 1 to 30 only ");
            }
        }
        // Fetching the day for the month of August
        else if(mnth.equals("AUG"))
        {
            if(dd1>0 && dd1<=30)
            {
            if(res==1)
                System.out.println(dt + " is Friday. ");
            else if(res==2)
                System.out.println(dt + " is Saturday. ");
            else if(res==3)
                System.out.println(dt + " is Sunday. ");
            else if(res==4)
                System.out.println(dt + " is Monday. ");
            else if(res==5)
                System.out.println(dt + " is Tuesday. ");
            else if(res==6)
                System.out.println(dt + " is Wednesday. ");
            else
                System.out.println(dt + " is Thursday. ");
            }
            else
            {
                if(mnth.equals("AUG"))
                    System.out.println(dt + " : Invalid date!!! August has dates from 1 to 30 only ");
            }
        }
        // Fetching the day for the month of September or December
        else if(mnth.equals("SEP") || mnth.equals("DEC"))
        {
            if((mnth.equals("SEP") && dd1>0 && dd1<=30) || (mnth.equals("DEC") && dd1>0 && dd1<=31))
            {
            if(res==1)
                System.out.println(dt + " is Monday. ");
            else if(res==2)
                System.out.println(dt + " is Tuesday. ");
            else if(res==3)
                System.out.println(dt + " is Wednesday. ");
            else if(res==4)
                System.out.println(dt + " is Thursday. ");
            else if(res==5)
                System.out.println(dt + " is Friday. ");
            else if(res==6)
                System.out.println(dt + " is Saturday. ");
            else
                System.out.println(dt + " is Sunday. ");
            }
            else
            {
                if(mnth.equals("SEP"))
                    System.out.println(dt + " : Invalid date!!! September has dates from 1 to 30 only ");
                if(mnth.equals("DEC"))
                    System.out.println(dt + " : Invalid date!!! December has dates from 1 to 31 only ");
            }
        }
       
        // Validating month name
        else
            System.out.println(dt + " : Invalid month!!! Enter the correct month ");
    }                           // end of  main
}
    

Program to enter a token/word in a mixed case and display the new token after deleting all the consonants

/* Program to enter a token/word in a mixed case and display the new token
  after deleting all the consonants*/
 
import java.util.Scanner;
public class vowels
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
       
        String st, ns="";
        int i,len;
        char ch;
       
        System.out.println("Enter a token/word");
        st=sc.next();
        len=st.length();
       
        // Extracting only consonants leaving vowels from the entered token
        for(i=0;i<len;i++)
        {
            ch=st.charAt(i);
            if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
                ns=ns+ch;
        }
       
        System.out.println();
        System.out.println();
       
        // Printing the new token with consonants only
        System.out.println("The new token after deleting all the consonants : "+ns);
         
    }
}
        

ICSE Bluej Project

// Menu based Java Project to find a. the length of a string.   b. To count vowels & consonent.  c. To count number of words.

import java.io.* ;
public class Project
{
   
     
    public static void main(String[] args)throws IOException
        {
        InputStreamReader read=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(read);
        Project obj=new Project();
        int choice = 0;
        String str;
       
         System.out.println("Enter the string");
         str=br.readLine();
           
        while(choice<4){
            System.out.println("          \t\t MAIN MENU :");
            System.out.println("---------------------------------");
            System.out.println("\t 1.LENGTH OF THE SENTENCE");
            System.out.println("\t 2.VOWEL & CONSONENT COUNT");
            System.out.println("\t 3.WORD COUNT");
            System.out.println("\t 4.EXIT");
                     
          do{
                System.out.print("enter choice(1 - 4) : ");
                choice = Integer.parseInt(br.readLine());
            }while(choice<1 && choice>4);
           
         
            switch(choice){
                case 1:
                       int l=str.length();
                       System.out.println("Length of the String = "+l);
                break;
               
                case 2:
                      int vcount=0,ccount=0;
                      str=str.toLowerCase();
                      System.out.println(str);
                      for(int i=0 ;i<str.length(); i++)
                      {
                          char c=str.charAt(i);
                          if(c=='a' ||c=='e' || c=='i' || c=='o' || c=='u')
                          vcount=vcount+1;
                          if(c>=97 && c<=122)
                          ccount=ccount+1;
                        }
                        ccount=ccount-vcount;
                        System.out.println("Total no. of vowels  = "+ vcount);
                        System.out.println("Total no. of consonent = "+ ccount);
                        break;
             
                case 3:
                int wcount=0,bcount=0;
                      for(int i=0 ;i<str.length(); i++)
                      {
                          char c=str.charAt(i);
                          if(c==' ')
                          bcount=bcount+1;
                       }
                        wcount=bcount+1;
                        System.out.println("Total no. of words  = "+ wcount);
                        System.out.println("Total no. of blanks = "+ bcount);
                        break;              
                case 4:
                        System.out.println("The End of the Project");
                        break;
                    }//end of switch case
                }//end of while loop
            }// end of main
        }// end of class