Friday, 24 October 2014

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

No comments:

Post a Comment