Overloading - Coder's point

Monday, March 25, 2019

Overloading

 import java.io.*;  
 class overloaddemo  
 {  
   int upperCaseCounter=0,lowerCaseCounter=0,digitCounter=0,whiteSpaceCounter=0,specialCounter=0;  
   String data;  
   overloaddemo()  
   {  
     data="Hello from KCCOE !!!!";  
   }  
   overloaddemo(String a)  
   {  
     data=a;  
   }  
   void analysis()  
   {  
     for(int i=0;i<data.length();i++)  
     {  
       char ch=data.charAt(i);  
       if(Character.isAlphabetic(ch))  
       {  
         if(Character.isUpperCase(ch))  
         {  
           upperCaseCounter+=1;  
         }  
         else  
         {  
           lowerCaseCounter+=1;  
         }  
       }  
       else if(Character.isDigit(ch))  
       {  
         digitCounter+=1;  
       }  
       else  
       {  
         if(Character.isWhitespace(ch))  
         {  
           whiteSpaceCounter+=1;  
         }  
         else  
         {  
           specialCounter+=1;  
         }  
       }  
     }  
     System.out.println("number of uppercase letter: "+upperCaseCounter);  
     System.out.println("number of lowercase letter: "+lowerCaseCounter);  
     System.out.println("number of digits: "+digitCounter);  
     System.out.println("number of white Spaces: "+whiteSpaceCounter);  
     System.out.println("number of special characters: "+specialCounter);  
   }  
   public static void main(String args[])throws IOException  
   {  
     int upperCaseCounter=0,lowerCaseCounter=0,digitCounter=0,whiteSpaceCounter=0,specialCounter=0;  
     overloaddemo obj1=new overloaddemo();  
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  
     System.out.println("Enter the string:");  
     String str=br.readLine();  
     overloaddemo obj2=new overloaddemo(str);  
     System.out.println("Analysis of predefined string(default constructor)");  
     System.out.println("Hello from KCCOE !!!!");  
     obj1.analysis();  
     System.out.println("Analysis of user defined string(parameterimzed constructor)");  
     System.out.println(str);  
     obj2.analysis();  
   }  
 }  
OUTPUT :
Enter the string:
Hello Welcome to Java Tutorials
Analysis of predefined string(default constructor)
Hello from KCCOE !!!!
number of uppercase letter: 6
number of lowercase letter: 8
number of digits: 0
number of white Spaces: 3
number of special characters: 4
Analysis of user defined string(parameterimzed constructor)
Hello Welcome to Java Tutorials
number of uppercase letter: 4
number of lowercase letter: 23
number of digits: 0
number of white Spaces: 4
number of special characters: 0

No comments:

Post a Comment