From 0d8e9c440e469ebfa44891b14c24581f4ce65751 Mon Sep 17 00:00:00 2001 From: Nirav Radadiya <nradadiya5813@gmail.com> Date: Tue, 22 Mar 2022 11:53:59 -0300 Subject: [PATCH 1/3] Refactored Code --- Collections/.project | 11 ++ .../collectionsutils/CollectionsDemo.java | 94 +++++++++++------- .../threadsafe/EmployeeRunnable.java | 12 +-- .../collections/threadsafe/MainProgram.java | 69 ++++++++++--- .../threadsafe/StudentRunnable.java | 17 ++-- EncryptionDecryption/.project | 11 ++ EncryptionDecryption/bin/.gitignore | 1 - .../com/cdac/encrypt/aes/AESEncryption.class | Bin 3725 -> 1361 bytes .../com/cdac/encrypt/aes/encryptdecrypt.class | Bin 0 -> 3179 bytes .../bin/snippet/Snippet.class | Bin 0 -> 262 bytes .../com/cdac/encrypt/aes/AESEncryption.java | 26 +++-- EncryptionDecryption/src/snippet/Snippet.java | 6 +- ExceptionHandling/.project | 11 ++ FileIO/.project | 11 ++ Generics/.project | 11 ++ InterviewPrograms/.project | 11 ++ .../src/com/java/strings/CountVowels.java | 74 +++++++++++--- JavaEnums/.project | 11 ++ Networking/.project | 11 ++ Reflections/.project | 11 ++ Threads/.project | 11 ++ 21 files changed, 316 insertions(+), 93 deletions(-) delete mode 100644 EncryptionDecryption/bin/.gitignore create mode 100644 EncryptionDecryption/bin/com/cdac/encrypt/aes/encryptdecrypt.class create mode 100644 EncryptionDecryption/bin/snippet/Snippet.class diff --git a/Collections/.project b/Collections/.project index c461daf..5ea0f58 100644 --- a/Collections/.project +++ b/Collections/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731126</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java b/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java index 954db7a..8b5f045 100644 --- a/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java +++ b/Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java @@ -8,8 +8,8 @@ import java.util.Map; import java.util.Set; -public class CollectionsDemo { - +public class CollectionsDemo +{ public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("One"); @@ -51,14 +51,14 @@ public static void main(String[] args) { String min = Collections.min(list); System.out.println("Min Element in the List : "+min); - List<Integer> iList = new ArrayList<>(); - iList.add(10); - iList.add(20); - iList.add(40); - iList.add(30); + List<Integer> indexList = new ArrayList<>(); //iList name is not understadable can be converted to List 2 or IndexList + indexList.add(10); + indexList.add(20); + indexList.add(40); + indexList.add(30); //Binary Search in List Collection - int index = Collections.binarySearch(iList, 190); + int index = Collections.binarySearch(indexList, 190); System.out.println("Binary Search of 190 index is : "+index); //Copy one list to another list @@ -71,36 +71,60 @@ public static void main(String[] args) { newList.add(14); newList.add(15); //newList should have minimum size as iList - Collections.copy(newList, iList); + Collections.copy(newList, indexList); System.out.println("Copying the list from another list : "+newList); - //Creating Immutable Collection - Set<String> emptySet = Collections.emptySet(); - List<String> emptyList = Collections.emptyList(); - Map<String, String> emptyMap = Collections.emptyMap(); - System.out.println("Creating immutable collection (list, set, map)"); - System.out.println("Empty Set : "+emptySet.size()); - //emptySet.add("Try"); //not allowed its immutable - - //replacing all the elements with the new value - Collections.replaceAll(iList, 10, 100); - System.out.println("Replacing all the 10 in the list with 100 :"); - System.out.println(iList); - - //shuffling the list - Collections.shuffle(iList); - System.out.println("Shuffle the Elements in the List : "); - System.out.println(iList); + + + methodCalling(indexList); //Calling all methods from one place - //Creating singleton Collection Set, List, Map - Set<String> singletonSet = Collections.singleton("Java"); - System.out.println("Creating singleton Collection : "); - System.out.println(singletonSet); -// singletonSet.add("Hello"); //not supported its immutable + } + + static void methodCalling(List<Integer> indexList) + { + immutableCollection(); // Extracted Method + replaceAndShuffle(indexList); // Extracted Method + singletonCollection(); // Extracted Method + synchronizedCollection(); // Extracted Method + } + static void immutableCollection() + { + //Creating Immutable Collection + Set<String> emptySet = Collections.emptySet(); + List<String> emptyList = Collections.emptyList(); + Map<String, String> emptyMap = Collections.emptyMap(); + System.out.println("Creating immutable collection (list, set, map)"); + System.out.println("Empty Set : "+emptySet.size()); + //emptySet.add("Try"); //not allowed its immutable + } + + static void replaceAndShuffle(List<Integer> indexList) + { + //replacing all the elements with the new value + Collections.replaceAll(indexList, 10, 100); + System.out.println("Replacing all the 10 in the list with 100 :"); + System.out.println(indexList); + + //shuffling the list + Collections.shuffle(indexList); + System.out.println("Shuffle the Elements in the List : "); + System.out.println(indexList); + } + + static void singletonCollection() + { + //Creating singleton Collection Set, List, Map + Set<String> singletonSet = Collections.singleton("Java"); + //singletonSet.add("Hello"); //not supported its immutable + System.out.println("Creating singleton Collection : "); + System.out.println(singletonSet); + } - //Creating synchronized Collection List, Set, Map - Map<Integer, String> map = new HashMap<>(); - map = Collections.synchronizedMap(map); - System.out.println("Creating synchronizing Collection : "); + static void synchronizedCollection() + { + //Creating synchronized Collection List, Set, Map + Map<Integer, String> map = new HashMap<>(); + map = Collections.synchronizedMap(map); + System.out.println("Creating synchronizing Collection : "); } } \ No newline at end of file diff --git a/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java b/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java index 4670969..b528193 100644 --- a/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java +++ b/Collections/src/com/cdac/collections/threadsafe/EmployeeRunnable.java @@ -2,7 +2,8 @@ import java.util.ArrayList; -public class EmployeeRunnable implements Runnable{ +public class EmployeeRunnable +{ ArrayList<String> names; @@ -10,9 +11,6 @@ public EmployeeRunnable(ArrayList<String> list) { this.names = list; } - @Override - public void run() { - for(int i=0;i<100;i++) - names.add("Employee :: "+i); - } -} \ No newline at end of file + +} +//run method moved to MainProgram.java \ No newline at end of file diff --git a/Collections/src/com/cdac/collections/threadsafe/MainProgram.java b/Collections/src/com/cdac/collections/threadsafe/MainProgram.java index 29775ed..583212f 100644 --- a/Collections/src/com/cdac/collections/threadsafe/MainProgram.java +++ b/Collections/src/com/cdac/collections/threadsafe/MainProgram.java @@ -1,22 +1,65 @@ package com.cdac.collections.threadsafe; - import java.util.ArrayList; +// import com.cdac.collections.bean.Student; +// Applying move method run to main program, decreases the complexity of tread running +public class MainProgram implements Runnable +{ + public static void main(String[] args) throws CloneNotSupportedException { -import com.cdac.collections.bean.Student; - -public class MainProgram { - public static void main(String[] args) throws CloneNotSupportedException { - ArrayList<String> list = new ArrayList<>(); - EmployeeRunnable employeeRunnable = new EmployeeRunnable(list); - StudentRunnable studentRunnable = new StudentRunnable(list); - - Thread t1 = new Thread(employeeRunnable); - Thread t2 = new Thread(studentRunnable); + Thread t1 = new Thread(); + Thread t2 = new Thread(); t1.start(); t2.start(); + ArrayList<String> list = new ArrayList<>(); + EmployeeRunnable employeeRunnable = new EmployeeRunnable(list); + StudentRunnable studentRunnable = new StudentRunnable(list); - + + } + public void run() + { + ArrayList<String> Employeenames = null; + ArrayList<String> Studentnames = null; + for(int i=0;i<100;i++) + { + Employeenames.add("Employee :: "+i); + } + for(int j =100; j<200;j++) + { + Studentnames.add("Student :: "+j); + } } -} \ No newline at end of file + +} +// class EmployeeRunnable implements Runnable +// { + +// ArrayList<String> names; + +// public EmployeeRunnable(ArrayList<String> list) { +// this.names = list; +// } + +// @Override +// public void run() { +// for(int i=0;i<100;i++) +// names.add("Employee :: "+i); +// } +// } + +// class StudentRunnable implements Runnable +// { + +// ArrayList<String> names; + +// public StudentRunnable(ArrayList<String> list) { +// this.names = list; +// } +// @Override +// public void run() { +// for(int i=100;i<200;i++) +// names.add("Student :: "+i); +// } + diff --git a/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java b/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java index 918a0c5..192b510 100644 --- a/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java +++ b/Collections/src/com/cdac/collections/threadsafe/StudentRunnable.java @@ -2,17 +2,12 @@ import java.util.ArrayList; -public class StudentRunnable implements Runnable{ - +public class StudentRunnable +{ ArrayList<String> names; - - public StudentRunnable(ArrayList<String> list) { + public StudentRunnable(ArrayList<String> list) + { this.names = list; } - @Override - public void run() { - for(int i=100;i<200;i++) - names.add("Student :: "+i); - } - -} \ No newline at end of file +} +//run method moved to MainProgram.java \ No newline at end of file diff --git a/EncryptionDecryption/.project b/EncryptionDecryption/.project index 2197d2e..18368b6 100644 --- a/EncryptionDecryption/.project +++ b/EncryptionDecryption/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731142</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/EncryptionDecryption/bin/.gitignore b/EncryptionDecryption/bin/.gitignore deleted file mode 100644 index d728ce5..0000000 --- a/EncryptionDecryption/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/snippet/ diff --git a/EncryptionDecryption/bin/com/cdac/encrypt/aes/AESEncryption.class b/EncryptionDecryption/bin/com/cdac/encrypt/aes/AESEncryption.class index 86148c98c542a0320022dfd23aa82214efb050b1..b328de9ac4fc51578c58b451904041f156cfec77 100644 GIT binary patch delta 729 zcmZ9KT~8BH5Qd+#3*Bv5wQO5Up};~#r3$4Af<@)q&w?OEgNYZ7Z3w2eglts2;TL$( z?6p5aFA9-_YvY~wM*oR%wp%qZCpk0o&O3A7Ip@6Z{}zdS{q^|-m}IjNnQxr*gu)h` zgc{%9q`DRM>b~Pv-nx!kcPh0Pd;7btNzALN(QtyK!C6J75lzI}xpJjNvFIV?eNdT! zKKc#Pis;MI>r$>-s%_^s-MyXKw#5L0-Vf!N35G0&$#@}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Y^An4Mv=-z8tp!ohJ~)etb}C2KjT~7N97Toj(Zk;@T%|ZF z95;2WVCxM|0(cjHLvnK~Vw`K90JdWXR}t*QF7AlK|Dm}Sj#jL7Jk~Z5YpY>zthI^< zYdC!VCK9n!6~{T=M&Dele+2_IJX*zjs~F}!=aWe(ds@g!nK8<6&zGq0o|7jh8vA$M zJjOx?oea{s5Z&8M=XTJ&eQ4!VbvOFahR3i6v)GFgcSSfIp39iR`?w0CfcFy@CK7pM zI1BL9NlbGVWUzc)dBG|n;wli<mGO?)Ocm#EVV)k|#QdEqJ`{VZhU|DJS5+*n`68o; z&+$uaW(5UCejAoteq;sCEx1>)ZQ^JZPhUk?j32u}7XoxI!z)0H^K9WknUy}K4LHQz zBMkKs2HVcS5;%-bCh{oX9ZAX`qw^`A>cRya$5ZH86}FB~ND>6_B%Z}58QL`Acn;4~ z=LI?Y6lb5Nl~x4*M;8Jr;wmpfMaAVaDxPT}CVWQt1Q4V6Yq^ORu5(;Xo<3<dz}<)_ z0{=u0M~`o}@WS0h3fO@GdN3%D)j9VW>1{+jxO@exOuoF{<f&CA*^ru;e0jaeG))e# zG5LAlB%iy!f)&b$%%@|o)bNGzPDbli@s&=G2334xqK0oXb3d%%>Q!Eub>6-~-gZ{; ziw1F(>oWF-nZ9d&N)NC~fiq;^S(elo`T95?<mZ^&aWZ#Odgd`UEqN+Rb3cBCUsF>X zJ-yBv4^X;|NxZ>5kvjf|wxHr#8-eGG(GTJc(pO-dj@^_&Z1RG*jrd$=4ZrEAqQ*#8 z@cSD6xH^bGzk?w5&?%5CA+l);W*ERMT{_PI=41eI4?bB`s{^=)+X4KQ>H_#1{?0MR R*_&+Q|6n+;bNnYF{|Dz9dK3Tv diff --git a/EncryptionDecryption/bin/com/cdac/encrypt/aes/encryptdecrypt.class b/EncryptionDecryption/bin/com/cdac/encrypt/aes/encryptdecrypt.class new file mode 100644 index 0000000000000000000000000000000000000000..ba1137f2f5749075fd5a56b4dd3689555caecf80 GIT binary patch literal 3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qV AIsgCw literal 0 HcmV?d00001 diff --git a/EncryptionDecryption/bin/snippet/Snippet.class b/EncryptionDecryption/bin/snippet/Snippet.class new file mode 100644 index 0000000000000000000000000000000000000000..d3e0080c42a80935678db40fc18502212b3d28ac GIT binary patch literal 262 zcmZ8by%ND-5Zud;5J7kY9SUi5jK+*AL&503#5a7INKAzHQkhYB01su{hf1@1yEk{c z&)59{U<BWRL1>*abv(*4Sbf=nMeq}G5kV@lU9gN28JC30L}jX+63kwIL$GG~R=O}z z^I)UGe?pbX#rY7)VlARn5;|cXi*zFjrS;FW%Dp-f+Tma9nBcDRa}mqA(#PJf&QLc& r7o5wb!Av@j(P0&QG++;Is9xDH;4<np_@K_{eP)}v!HUpiG|+kjvm`X< literal 0 HcmV?d00001 diff --git a/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java b/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java index b0db7ce..7169df9 100644 --- a/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java +++ b/EncryptionDecryption/src/com/cdac/encrypt/aes/AESEncryption.java @@ -14,25 +14,33 @@ */ public class AESEncryption { - public static void main(String[] args) { - final String strToEncrypt = "My text to encrypt"; + public static void main(String[] args) + { + final String strToEncrypt = "My text to encrypt"; final String strPssword = "f2fc2007-b24b-4ab5-b62f-8dba873d0341"; - AESEncryption.setKey(strPssword); - AESEncryption.encrypt(strToEncrypt.trim()); + encryptdecrypt.setKey(strPssword); + //encryptdecrypt is called from main funcation + encryptdecrypt.encrypt(strToEncrypt.trim()); System.out.println("String to Encrypt: " + strToEncrypt); - System.out.println("Encrypted: " + AESEncryption.getEncryptedString()); - final String strToDecrypt = AESEncryption.getEncryptedString(); - AESEncryption.decrypt(strToDecrypt.trim()); + System.out.println("Encrypted: " + encryptdecrypt.getEncryptedString()); + final String strToDecrypt = encryptdecrypt.getEncryptedString(); + encryptdecrypt.decrypt(strToDecrypt.trim()); System.out.println("String To Decrypt : " + strToDecrypt); - System.out.println("Decrypted : " + AESEncryption.getDecryptedString()); + System.out.println("Decrypted : " + encryptdecrypt.getDecryptedString()); } +} +//class encryptdecrypt increases the readability of the code. So, it is extracted to another new class. +//funcationality remains the same besides having refactoring +class encryptdecrypt +{ private static SecretKeySpec secretKey; private static byte[] key; private static String decryptedString; private static String encryptedString; - public static void setKey(String myKey) { + public static void setKey(String myKey) + { MessageDigest sha = null; try { key = myKey.getBytes("UTF-8"); diff --git a/EncryptionDecryption/src/snippet/Snippet.java b/EncryptionDecryption/src/snippet/Snippet.java index 7aaeb24..9ed82b4 100644 --- a/EncryptionDecryption/src/snippet/Snippet.java +++ b/EncryptionDecryption/src/snippet/Snippet.java @@ -1,6 +1,8 @@ package snippet; -public class Snippet { - Divisors are +public class Snippet +{ + //Divisors are } +//changed snippet.java as code is giving error diff --git a/ExceptionHandling/.project b/ExceptionHandling/.project index d1a8803..d585cd8 100644 --- a/ExceptionHandling/.project +++ b/ExceptionHandling/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731166</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/FileIO/.project b/FileIO/.project index 178ff18..46e10c7 100644 --- a/FileIO/.project +++ b/FileIO/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731181</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/Generics/.project b/Generics/.project index 35f7874..9b430bc 100644 --- a/Generics/.project +++ b/Generics/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731191</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/InterviewPrograms/.project b/InterviewPrograms/.project index faaf7d1..a765cf4 100644 --- a/InterviewPrograms/.project +++ b/InterviewPrograms/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731205</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/InterviewPrograms/src/com/java/strings/CountVowels.java b/InterviewPrograms/src/com/java/strings/CountVowels.java index 278b85f..0dd4a2a 100644 --- a/InterviewPrograms/src/com/java/strings/CountVowels.java +++ b/InterviewPrograms/src/com/java/strings/CountVowels.java @@ -31,30 +31,74 @@ * by, cry, crypt, fry, gym, psych, spy */ -public class CountVowels { +public class CountVowels extends countVow { public static void main(String[] args) { // String line = "Java Interview Programs"; // String line = "Hello World!"; String line = "Rhythm"; - int count = 0; + System.out.println("Given String is :"+line); line = line.toLowerCase(); - for(char ch : line.toCharArray()){ - switch (ch) { - case 'a': - case 'e': - case 'i': - case 'o': - case 'u': - count++; - break; - default: - break; - } - } + + countVow c = new CountVowels(); + c.count(line); System.out.println("Number of Vowels are :"+count); } + + @Override + void count(String line) { + // TODO Auto-generated method stub + + } +} + +//extract class +abstract class countVow +{ + static int count = 0; + abstract void count(String line); + +} +class a extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class e extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class i extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class o extends countVow +{ + @Override + public void count(String line) + { + count++; + } +} +class u extends countVow +{ + @Override + public void count(String line) + { + count++; + } } /* OUTPUT diff --git a/JavaEnums/.project b/JavaEnums/.project index 36a5aea..3e26146 100644 --- a/JavaEnums/.project +++ b/JavaEnums/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731215</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/Networking/.project b/Networking/.project index bf949aa..2ddd01c 100644 --- a/Networking/.project +++ b/Networking/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731223</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/Reflections/.project b/Reflections/.project index d5dae35..92518f1 100644 --- a/Reflections/.project +++ b/Reflections/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731243</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> diff --git a/Threads/.project b/Threads/.project index 35e7365..bf2e10d 100644 --- a/Threads/.project +++ b/Threads/.project @@ -14,4 +14,15 @@ <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> + <filteredResources> + <filter> + <id>1647954731264</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> </projectDescription> From 380d541eedbabf17a78a2b75b8d910db332fc12a Mon Sep 17 00:00:00 2001 From: Nirav Radadiya <nradadiya5813@gmail.com> Date: Tue, 22 Mar 2022 12:03:18 -0300 Subject: [PATCH 2/3] Refactored Code --- .../src/com/java/strings/CountVowels.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/InterviewPrograms/src/com/java/strings/CountVowels.java b/InterviewPrograms/src/com/java/strings/CountVowels.java index 0dd4a2a..6c89d13 100644 --- a/InterviewPrograms/src/com/java/strings/CountVowels.java +++ b/InterviewPrograms/src/com/java/strings/CountVowels.java @@ -32,24 +32,21 @@ */ public class CountVowels extends countVow { - public static void main(String[] args) { + public static void main(String[] args) + { // String line = "Java Interview Programs"; -// String line = "Hello World!"; - String line = "Rhythm"; - - + String line = "Hello World!"; + // String line = "Rhythm"; System.out.println("Given String is :"+line); line = line.toLowerCase(); - countVow c = new CountVowels(); c.count(line); - System.out.println("Number of Vowels are :"+count); } - @Override - void count(String line) { - // TODO Auto-generated method stub - + int count(String line) + { + System.out.println("Number of Vowels are :"+count); + return 0; } } @@ -57,47 +54,46 @@ void count(String line) { abstract class countVow { static int count = 0; - abstract void count(String line); - + abstract int count(String line); } class a extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class e extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class i extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class o extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } class u extends countVow { @Override - public void count(String line) + public int count(String line) { - count++; + return count++; } } /* From ce5f417dbfac751ff60e474119b39832896048e6 Mon Sep 17 00:00:00 2001 From: Nirav Radadiya <nradadiya5813@gmail.com> Date: Tue, 22 Mar 2022 12:12:30 -0300 Subject: [PATCH 3/3] Refactored Code 2 --- .../src/com/java/strings/CountVowels.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/InterviewPrograms/src/com/java/strings/CountVowels.java b/InterviewPrograms/src/com/java/strings/CountVowels.java index 6c89d13..a71d3c3 100644 --- a/InterviewPrograms/src/com/java/strings/CountVowels.java +++ b/InterviewPrograms/src/com/java/strings/CountVowels.java @@ -35,8 +35,8 @@ public class CountVowels extends countVow { public static void main(String[] args) { // String line = "Java Interview Programs"; - String line = "Hello World!"; - // String line = "Rhythm"; + // String line = "Hello World!"; + String line = "Rhythm"; System.out.println("Given String is :"+line); line = line.toLowerCase(); countVow c = new CountVowels(); @@ -61,7 +61,7 @@ class a extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class e extends countVow @@ -69,7 +69,7 @@ class e extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class i extends countVow @@ -77,7 +77,7 @@ class i extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class o extends countVow @@ -85,7 +85,7 @@ class o extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } class u extends countVow @@ -93,7 +93,7 @@ class u extends countVow @Override public int count(String line) { - return count++; + return count++; // refactored with Replace conditional with polymorphism } } /*