User talk:Sankarami

////////INTEGERS TO WORD

class TestNew { // public static int getLargestLength(int[] numArray) {  if(numArray==null || numArray.length==0) return -1; int largest=findLargest(numArray),index,finalResult=0; String tempString=""; for(index=0;index<numArray.length;index++) {    if(numArray[index]<0) return -1; }  tempString=tempString+largest; String resultString=convertToWords(largest); finalResult=resultString.length-1; return finalResult; } //To convert a number to a string public static String convertToWords(int num) { int index; //if(checkNull(num)) //return null; String str=""+num; String resultString=""; for(index=0;index<str.length;index++) {    switch(str.charAt(index)) {     case '0': resultString=resultString+"zero "; break; case '1': resultString=resultString+"one "; break; case '2': resultString=resultString+"two "; break; case '3': resultString=resultString+"three "; break; case '4': resultString=resultString+"four "; break; case '5': resultString=resultString+"five "; break; case '6': resultString=resultString+"six "; break; case '7': resultString=resultString+"seven "; break; case '8': resultString=resultString+"eight "; break; case '9': resultString=resultString+"nine "; break; }  }    return resultString; } // public static int findLargest(int[] numArray) { int index,largest=numArray[0]; for(index=0;indexlargest) largest=numArray[index]; } return largest; } // public static String writeInWords(int num) { if(checkNull(num)) return "dhus"; else return null; } // public static boolean checkNull(int num) { //int length=-1; if(num<0 || num>9999) return false; else return true; } }

///compare date

class TestCompareDate1 { public static int compareDates(String date1,String date2) {   if(date1==null || date2==null || toArray(date1)==null || toArray(date2)==null) return -2; int[] dateArr1=toArray(date1); int[] dateArr2=toArray(date2); if(dateArr1[2]>dateArr2[2]) return 1; if(dateArr1[2]==dateArr2[2] && dateArr1[1]>dateArr2[1]) return 1; if(dateArr1[2]==dateArr2[2] && dateArr1[1]==dateArr2[1] && dateArr1[0]>dateArr2[0]) return 1; if(dateArr1[2]==dateArr2[2] && dateArr1[1]==dateArr2[1] && dateArr1[0]==dateArr2[0]) return 0; return -1; } //helper function to convert a date string to an integer array //and check if a date is valid or not public static int[] toArray(String date) {   String[] temp=date.split("/"); if(temp.length!=3) return null; if(temp[0].length!=2 || temp[1].length!=2 || temp[2].length!=4) return null; int[] array=new int[3]; for(int index=0;index<3;index++) array[index]=Integer.parseInt(temp[index]); int day=array[0]; int month=array[1]; int year=array[2]; if(day<1 || day>31 || month<1 || month>12 || year<1) return null; if(month==4 || month==6 || month==9 || month==11) if(day>30) return null; if(month==2) {     if(isLeap(year) && day>29) return null; if(!isLeap(year) && day>28) return null; }       return array; } //helper function to check if a year is a leap year or not public static boolean isLeap(int year) {   if(year%100==0 && year%400!=0) return false; if(year%100!=0 && year%4!=0) return false; return true; } }

kerosene

class Test1 { public static double findQty(char gender,int age,String category,int specialcode,int members) {   double sum=members*1; if(specialcode==0) {     if(category.equals("sc")||category.equals("st")) {       if(gender=='F'|| age>=60) sum=sum+1+0.2*members; else sum=sum+0.2*members; }     else {       if(gender=='F'|| age>=60) sum=sum+1; else sum=sum; }   }    else if(specialcode==1||specialcode==2) {    if(gender=='F'|| age>=60) sum=sum+1+0.3*members; else sum=sum+0.3*members; }   else if(specialcode==3) {    if(gender=='F'|| age>=60) sum=sum+1+5; else sum=sum+5; }   else return -1; return sum; } }

makepalindrome

class Test2 { public static int[] makePalindrome(int numarr[]) { String str[]=new String[numarr.length]; int finalresult[]=new int[numarr.length]; int i,temp,remainder,reverse=0; String str1="",str2="",result; //int arr[]=new int[numarr.length]; for(i=0;i4) {     finalresult[i]=0; }   else {      temp=numarr[i]; while(temp!=0) {        remainder=temp%10; reverse=(reverse*10)+remainder; temp=temp/10; }       str1=str1+numarr[i];str2=str2+reverse; result=str1+str2.substring(1,str2.length); finalresult[i]=Integer.parseInt(result); }  }   return finalresult; } public static int calcLength(int num) { int i=0,temp=num; while(temp!=0) {  temp=temp/10; i++; }  return i; } public static boolean checkPalindrome(int num) { int reverse=0,temp=num,count,remainder=0; while(temp!=0) {  remainder=temp%10; reverse=(reverse*10)+remainder; temp=temp/10; } if(reverse==num) return true; else return false; } }

//aray calculator

class Test3 { // public static int arrayCalculator(int[] numArray,String operation) { if(operation.equals("sum")) {   return(findSum(numArray)); } else if(operation.equals("max")) {  return(findMax(numArray)); } else if(operation.equals("countunique")) {   return countUnique(numArray); } else {  return -1; } } //max public static int findMax(int[] arr) {   int max=arr[0],index; for(index=1;indexarr[index]) max=max; else max=arr[index]; }   return max; } //find the sum of factors of the numbers public static int findSum(int[] arr) {   int index1,index2,sum=0; for(index1=0;index1<arr.length;index1++) {     for(index2=1;index2<=arr[index1];index2++) {      if(arr[index1]%index2==0) sum=sum+index2; }   }    return sum; } //count unique elements in an array public static int countUnique(int[] arr) {   int index1,index2,uniqueElement=0; for(index1=0;index1<arr.length;index1++) {     int count=0; for(index2=0;index2<=index1;index2++) {      if(arr[index1]==arr[index2]) count++; }     if(count==1) uniqueElement++; }   return uniqueElement; } }

//find palindrome

class Test1 { public static int findPalindrome(int[] numArray) {  int index,count=0; for(index=0;index<numArray.length;index++) {     if(numArray[index]<0 || calcLength(numArray[index])==1) return -1; }  for(index=0;index<numArray.length;index++) {     if(checkPalindrome(numArray[index])) count++; }  return count; } public static boolean checkPalindrome(int num) { int reverse=0,temp=num,count,remainder=0; while(temp!=0) {  remainder=temp%10; reverse=(reverse*10)+remainder; temp=temp/10; } if(reverse==num) return true; else return false; } //  public static int calcLength(int num) { int i=0,temp=num; while(temp!=0) {  temp=temp/10; i++; }  return i; } }

///file xtension

class Test2 { public static String verifyFileExtension(String filename,String [] exList) { int i,index;String str1; i=filename.indexOf('.'); if(i==0||i==-1) return "-1"; else {   str1=filename.substring(i+1);//return str1; /*if(str1.equals("doc")||str1.equals("xlsx")||str1.equals("jpg")||str1.equals("txt")||str1.equals("bat")) return "valid document"; else return "invalid ";*/ for(index=0;index<exList.length;index++) {     if(str1.equals(exList[index])) return "valid"; } }  return "invalid"; } }

//time unit

class Test3 { public static int[] convertTimeUnit(long time) {  int result[]=new int[6],temp=0; if(time<0) return null; result[0]=(int)(time/(365*24*60*60*1000)); temp=(int)time%(365*24*60*60*1000); result[1]=(int)temp/(24*60*60*1000); temp=(int)temp%(24*60*60*1000); result[2]=(int)temp/(60*60*1000); temp=(int)temp%(60*60*1000); result[3]=(int)temp/(60*1000); temp=(int)temp%(60*1000); result[4]=(int)temp/1000; temp=(int)temp%1000; result[5]=temp; return result; } }

//sort ascending

class Test1 { public static String sortAscending(String s)  { char[] ch=new char[s.length]; char temp; String s1=""; int i,j; for(i=0;i=48 && s.charAt(i)<=57) count++; int[] a=new int[count]; String s1=""; j=0; for(i=0;i=48 && s.charAt(i)<=57) {       s1=s.charAt(i)+""; a[j++]=Integer.parseInt(s1); }   for(i=0;i<a.length;i++) for(j=0;j<a.length;j++) if(a[i]<a[j]) {        count=a[i]; a[i]=a[j]; a[j]=count; }   return a;  } public static int[] countWord(String s,String o)  { int i,j,k,c,count=0,count1=0; int[] a=new int[2]; for(i=0;i<s.length;i++) {      for(j=0;j='a' && ch<='z') { j= j-32; ch=(char)j; str1=str1+ch+"";} else if(ch>='A' && ch<='Z') {j=j+32; ch=(char)j; str1=str1+ch+"";} else str1=str1+ch+""; }   return str1; } }

//separate vowel

class P2 { public static String separateVowelsConsonants(String str) {   String sv="",sc="",str1=""; char ch; str1=str.toUpperCase; for(int i=0;imax) max=count; }   }      for(int i=0;i<arr.length;i++) if(arr[i]==max) temp=i; return str.charAt(temp); }   }

class Q2 { public static String formUnique(String str) {   int index=0,index1=0; String str1=""; for(index=0;index1) str1=str1+str.charAt(index); }   return str1; } }

///pension /*Write your program in this file: (DO NOT change the class name) (Function name should be as given in the problem statement) --- CONTRACT: PURPOSE: HEADER: EXAMPLE: DRY RUN: ---*/

//PROGRAM IMPLEMENTATION:

public class Test1 { //Write your code here public static int calcOptimalPension(int[]premiums) {  if( premiums==null||premiums.length==0) return -1; int index; for(index=0;index20000) return -1; }  int []sortedPremiums=new int[premiums.length]; int premiumValue=0,length=0,interestRate,optimalPensionAmount=0,T=20,position; sortedPremiums=sortArray(premiums); length=premiums.length; if(checkEvenOdd(length).equals("odd")) {   position=(length-1)/2; }  else {   position=length/2-1; }  premiumValue=premiums[position]; if(premiumValue>=1 && premiumValue<=5000) interestRate=20; else if(premiumValue>=5001 && premiumValue<=10000) interestRate=15; else if(premiumValue>=10001 && premiumValue<=15000) interestRate=10; else if(premiumValue>=15001 && premiumValue<=20000) interestRate=5; else return -1; optimalPensionAmount=(20*premiumValue)+((premiumValue*interestRate*T)/100); return optimalPensionAmount; } //  public static int[] sortArray(int[]premiums) {   int index1,index2,temp; for(index1=0;index1<premiums.length;index1++) {    for(index2=0;index2<index1;index2++) {     if(premiums[index1]<premiums[index2]) {      temp=premiums[index1]; premiums[index1]=premiums[index2]; premiums[index2]=temp; }    }    }    return premiums; } //  public static String checkEvenOdd(int num) {  if(num%2==0) return "even"; else return "odd"; }

}

/*-- TEST CASES:



////aliquot

class Aliquot { public static int[] sumAliquot(int num,int times) {   if(num<0||times<0) {     return null; }   int [] arr=new int[times]; arr[0]=num; for(int i=1;i<times;i++) {    arr[i]=factor(num); if(arr[i]==arr[0]) arr[i]=0; num=arr[i]; }   return arr; } //  public static int factor(int a)  { int num=0; for(int i=1;i<a;i++) {     if(a%i==0) {     num=num+i; }   }    return num; } }