├── .gitignore ├── .idea ├── .gitignore ├── misc.xml ├── modules.xml └── vcs.xml ├── Java Notes.pdf ├── Leacture Code ├── 10 Exception and File Handling │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ ├── java-course.txt │ │ └── src │ │ └── in │ │ └── kgcoding │ │ ├── exception │ │ └── Calculator.java │ │ └── file │ │ ├── KgCodingReader.java │ │ └── KgCodingWriter.java ├── 11 Collection and Generics │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ └── in │ │ └── kgcoding │ │ ├── collection │ │ ├── TestingCollections.java │ │ ├── TestingList.java │ │ ├── TestingQueue.java │ │ ├── TestingSet.java │ │ └── Utility.java │ │ ├── enums │ │ ├── Grade.java │ │ ├── TestingEnums.java │ │ └── TrafficLight.java │ │ ├── map │ │ └── TestingMaps.java │ │ ├── varargs │ │ └── VarArgs.java │ │ └── wrapper │ │ └── TestingWrapper.java ├── 12 Multithreading and Executor Service │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ └── in │ │ └── kgcoding │ │ ├── executor │ │ ├── PrintTask.java │ │ ├── TestingMultipleThreadExecutor.java │ │ ├── TestingSingleThreadExecutor.java │ │ └── future │ │ │ ├── FetchName.java │ │ │ └── TestingFutures.java │ │ └── multithreading │ │ ├── NeedOfMultiThreading.java │ │ ├── TestingPriority.java │ │ ├── join │ │ └── TestingJoin.java │ │ ├── runnable │ │ ├── PrintTask.java │ │ └── TestingRunnables.java │ │ ├── sleep │ │ └── TestingSleep.java │ │ ├── synchronize │ │ ├── Counter.java │ │ ├── TestingSynchronize.java │ │ └── UpdaterThread.java │ │ └── threadclass │ │ ├── ExtendingThreadClass.java │ │ ├── FirstTask.java │ │ ├── SecondTask.java │ │ └── ThirdTask.java ├── 13 Functional Programming │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ └── in │ │ └── kgcoding │ │ ├── filterandreduce │ │ ├── TestingFilter.java │ │ └── TestingReduce.java │ │ ├── lambda │ │ └── TestingLambda.java │ │ ├── methodreferences │ │ └── TestingMethodInterface.java │ │ └── optional │ │ └── TestingOptional.java ├── 2 Java Basics │ ├── FirstProgram.java │ ├── FirstProject │ │ ├── .gitignore │ │ ├── .idea │ │ │ ├── .gitignore │ │ │ ├── misc.xml │ │ │ └── modules.xml │ │ ├── FirstProject.iml │ │ └── src │ │ │ └── Main.java │ └── Variables.java ├── 3 Data Types Variables and Input │ └── Three │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ │ ├── Three.iml │ │ └── src │ │ ├── Escape.java │ │ ├── TypeConversion.java │ │ ├── UserInput.java │ │ └── Variables.java ├── 4 Operators If-else and Number System │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ ├── Arithmetic.java │ │ ├── Assignment.java │ │ ├── LearningIf.java │ │ ├── Logical.java │ │ ├── OrderOfOperation.java │ │ ├── Relational.java │ │ ├── Shorthand.java │ │ └── Unary.java ├── 5 While loop, Methods and Arrays │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ ├── Array.java │ │ ├── ArraySearching.java │ │ ├── Car.java │ │ ├── Comments.java │ │ ├── Function.java │ │ ├── Loop.java │ │ ├── Parameter.java │ │ ├── Return.java │ │ └── TwoDimensionalArray.java ├── 6 Class and Object │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ ├── Car.java │ │ └── Driver.java ├── 7 Control Statements Math and String │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ ├── BreakAndContinue.java │ │ ├── Car.java │ │ ├── DoWhile.java │ │ ├── ForEachLoop.java │ │ ├── ForLoop.java │ │ ├── KGMath.java │ │ ├── Recursion.java │ │ ├── StringFormat.java │ │ ├── StringTest.java │ │ ├── Switch.java │ │ ├── TernaryOperator.java │ │ └── TestingFinal.java ├── 8 Encapsulation and Inheritance │ └── Leacture │ │ ├── .gitignore │ │ ├── .idea │ │ ├── .gitignore │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── uiDesigner.xml │ │ └── vcs.xml │ │ ├── Leacture.iml │ │ └── src │ │ └── in │ │ ├── gettersetter │ │ └── Car.java │ │ ├── kgcoding │ │ ├── AccessTest.java │ │ ├── Car.java │ │ ├── Default.java │ │ ├── Packages.java │ │ ├── TwoWheeler.java │ │ ├── equals │ │ │ ├── EqualsAndHashCodeTest.java │ │ │ └── Person.java │ │ ├── inheritance │ │ │ ├── InheritanceTest.java │ │ │ ├── MotorCycle.java │ │ │ └── Vehicle.java │ │ ├── nested │ │ │ └── Car.java │ │ ├── passby │ │ │ ├── TestPassByReference.java │ │ │ └── TestPassByValue.java │ │ └── polymorphism │ │ │ ├── Car.java │ │ │ ├── Overloading.java │ │ │ ├── Plane.java │ │ │ ├── TestTransportation.java │ │ │ └── Vehicle.java │ │ └── knowledgegate │ │ ├── DefaultTest.java │ │ ├── GetterTest.java │ │ └── Packages.java └── 9 Abstraction and Polymorphism │ └── Leacture │ ├── .gitignore │ └── src │ └── in │ └── kgcoding │ └── abstraction │ ├── Car.java │ ├── TestAbstraction.java │ ├── Transport.java │ └── Vehicle.java ├── Programming Challenge ├── .gitignore ├── .idea │ ├── .gitignore │ ├── misc.xml │ ├── modules.xml │ ├── uiDesigner.xml │ └── vcs.xml ├── Programming Challenge.iml ├── java-course.txt └── src │ ├── 1 Morning.java │ ├── 10 Perimeter.java │ ├── 11 TriangleArea.java │ ├── 12 SimpleInterest.java │ ├── 13 CompoundInterest.java │ ├── 14 FahrenheitToCelsius.java │ ├── 15 PositiveNegativeZero.java │ ├── 16 OddEven.java │ ├── 17 GreatestOfThree.java │ ├── 18 LeapYear.java │ ├── 19 Grading.java │ ├── 2 Subscribe.java │ ├── 20 AgeCalculator.java │ ├── 21 BitwiseAnd.java │ ├── 22 BitwiseOr.java │ ├── 23 BitwiseXor.java │ ├── 24 BitwiseCompliment.java │ ├── 25 LeftShift.java │ ├── 26 RightShift.java │ ├── 27 OddEvenBitWise.java │ ├── 28 MultiplicationTable.java │ ├── 29 OddSum.java │ ├── 3 Pattern.java │ ├── 30 Factorial.java │ ├── 31 SumOfDigits.java │ ├── 32 LCM.java │ ├── 33 GCD.java │ ├── 34 Prime.java │ ├── 35 ReverseTheDigits.java │ ├── 36 Fibonacci.java │ ├── 37 ArmstrongNumber.java │ ├── 38 PalindromeNumber.java │ ├── 39 LoopPatterns.java │ ├── 4 SingleLine.java │ ├── 40 ArraySumAverage.java │ ├── 41 OccurrencesArray.java │ ├── 42 MaxMinArray.java │ ├── 43 IsSortedArray.java │ ├── 44 DeleteFromArray.java │ ├── 45 ReverseArray.java │ ├── 46 PalindromeArray.java │ ├── 47 MergeTwoSortedArray.java │ ├── 48 Search2DArray.java │ ├── 49 SumAverage2dArray.java │ ├── 5 Welcome.java │ ├── 50 DiagonalSum2DArray.java │ ├── 51 Book.java │ ├── 52 Course.java │ ├── 53 MinimumTernary.java │ ├── 54 OddEvenTernary.java │ ├── 55 AbsoluteTernary.java │ ├── 56 StudentScoreTernary.java │ ├── 57 MonthSwitch.java │ ├── 58 CalculatorSwitch.java │ ├── 59 PasswordChecker.java │ ├── 6 Sum.java │ ├── 60 NumberGuessingGame.java │ ├── 61 MultiplicationTableFor.java │ ├── 62 PrimeFor.java │ ├── 63 MaxArray.java │ ├── 64 OccurrencesForEach.java │ ├── 65 ExitOnExit.java │ ├── 66 SumPositive.java │ ├── 67 PrintEven.java │ ├── 68 FibonacciRecursion.java │ ├── 69 PalindromeRecursion.java │ ├── 7 Swap.java │ ├── 70 StudentToString.java │ ├── 71 StringManipulation.java │ ├── 72 Circle.java │ ├── 73 DiceRoll.java │ ├── 74 GuessingGame.java │ ├── 75 ArrayToString.java │ ├── 76 CarFinal.java │ ├── 8 Arithmetic.java │ ├── 89 VarArgs.java │ ├── 9 FloatMultiplication.java │ ├── 90 Comparator.java │ ├── 91 Frequency.java │ ├── 92 ListSwapping.java │ ├── 93 ListReverse.java │ ├── 94 StudentPriorityQueue.java │ ├── 95 UniqueCharacters.java │ ├── 98 CountryMap.java │ ├── ArrayUtility.java │ └── in │ └── kgcoding │ ├── challenge100 │ ├── Main.java │ └── ThreadState.java │ ├── challenge101 │ ├── PrintThread.java │ └── TestingJoin.java │ ├── challenge102 │ ├── Road.java │ ├── TrafficColor.java │ └── TrafficLightThread.java │ ├── challenge103 │ ├── PrintNumbers.java │ └── SingleThreadService.java │ ├── challenge104 │ ├── MultiThreadExecutorService.java │ └── SleepTask.java │ ├── challenge105 │ ├── FactorialCalculator.java │ └── TestingFactorial.java │ ├── challenge106 │ └── LambdaMultiplication.java │ ├── challenge107 │ └── StreamTest.java │ ├── challenge108 │ └── StringFilterAndConcatenate.java │ ├── challenge109 │ └── OddNumbers.java │ ├── challenge110 │ ├── Candidate.java │ └── TestingFunctionalInterface.java │ ├── challenge111 │ └── TestingFactorial.java │ ├── challenge112 │ └── OptionalString.java │ ├── challenge113 │ └── TestingDistinct.java │ ├── challenge114 │ ├── Employee.java │ └── TestingSorting.java │ ├── challenge115 │ └── FinalTest.java │ ├── challenge77 │ ├── geometry │ │ ├── Circle.java │ │ └── Rectangle.java │ └── utils │ │ └── Calculator.java │ ├── challenge78 │ ├── BankAccount.java │ └── Customer.java │ ├── challenge79 │ ├── Employee.java │ └── TestEmployee.java │ ├── challenge80 │ ├── Book.java │ ├── DVD.java │ ├── LibraryItem.java │ └── Magazine.java │ ├── challenge82 │ ├── ArrayOperations.java │ └── TestArray.java │ ├── challenge83 │ ├── Circle.java │ ├── Shape.java │ ├── Square.java │ └── TestShapes.java │ ├── challenge84 │ ├── Bird.java │ ├── Eagle.java │ ├── Flyable.java │ └── TestFly.java │ ├── challenge85 │ └── Calculator.java │ ├── challenge86 │ ├── Car.java │ ├── Test.java │ └── Vehicle.java │ ├── challenge87 │ └── Calculator.java │ ├── challenge88 │ └── RobustFileReader.java │ ├── challenge96 │ ├── Day.java │ └── EnumTest.java │ ├── challenge97 │ ├── Day.java │ └── EnumTest.java │ └── challenge99 │ ├── HelloThread.java │ └── Main.java └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.nar 19 | *.ear 20 | *.zip 21 | *.tar.gz 22 | *.rar 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | replay_pid* 27 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Java Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/Java_Complete_Youtube/0351665e51429236f64363acb1800ef499ecbe76/Java Notes.pdf -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/java-course.txt: -------------------------------------------------------------------------------- 1 | This is the best Java course. 2 | Please like this video. 3 | Please share this with your friends. 4 | And comment which course do you want next. -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/src/in/kgcoding/exception/Calculator.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.exception; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Calculator { 6 | public static void main(String[] args) { 7 | a(); 8 | } 9 | 10 | private static void a() { 11 | b(); 12 | } 13 | 14 | private static void b() { 15 | c(); 16 | } 17 | 18 | private static void c() { 19 | d(); 20 | } 21 | 22 | private static void d() { 23 | Scanner input = new Scanner(System.in); 24 | System.out.println("Welcome to Division Calculator\n"); 25 | System.out.print("Please enter your two numbers: "); 26 | int first = input.nextInt(); 27 | int second = input.nextInt(); 28 | 29 | try { 30 | int[] a = new int[5]; 31 | System.out.printf("Result is %d", a[6]); 32 | a[6] = first / second; 33 | System.out.printf("Result is %d", a[6]); 34 | } catch (ArithmeticException exception) { 35 | System.out.printf("%s, enter valid values", 36 | exception.getMessage()); 37 | } catch (Throwable th) { 38 | System.out.println("General Exception."); 39 | throw th; 40 | } finally { 41 | System.out.println("I am in finally"); 42 | } 43 | } 44 | } 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/src/in/kgcoding/file/KgCodingReader.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.file; 2 | 3 | import java.io.FileReader; 4 | import java.io.IOException; 5 | 6 | public class KgCodingReader { 7 | public static void main(String[] args) { 8 | String fileName = "java-course.txt"; 9 | 10 | try (FileReader reader = new FileReader(fileName)) { 11 | int read = 0; 12 | do { 13 | read = reader.read(); 14 | System.out.print((char)read); 15 | } while (read != -1); 16 | 17 | } catch (IOException e) { 18 | System.out.printf("Exception occured: %s", e.getMessage()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Leacture Code/10 Exception and File Handling/Leacture/src/in/kgcoding/file/KgCodingWriter.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.file; 2 | 3 | import java.io.FileWriter; 4 | import java.io.IOException; 5 | 6 | public class KgCodingWriter { 7 | public static void main(String[] args) { 8 | String fileName = "java-course.txt"; 9 | 10 | try (FileWriter writer = new FileWriter(fileName)) { 11 | writer.write("This is the best Java course.\n"); 12 | for (int i = 0; i < 10000; i++) { 13 | writer.write('*'); 14 | } 15 | 16 | writer.flush(); 17 | System.out.println("File Written Successfully"); 18 | } catch (IOException exception) { 19 | System.out.printf("Exception occurred %s\n", 20 | exception.getMessage()); 21 | } 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/collection/TestingCollections.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.collection; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class TestingCollections { 8 | public static void main(String[] args) { 9 | List numList = new ArrayList<>(); 10 | numList.add(5); 11 | numList.add(2); 12 | numList.add(8); 13 | numList.add(-76); 14 | Utility.print(numList); 15 | 16 | Collections.sort(numList); 17 | Utility.print(numList); 18 | 19 | Collections.reverse(numList); 20 | Utility.print(numList); 21 | 22 | List unmodifiable = Collections.unmodifiableList(numList); 23 | unmodifiable.add(87); 24 | } 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/collection/TestingList.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.collection; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class TestingList { 7 | public static void main(String[] args) { 8 | List strList = new ArrayList<>(); 9 | 10 | strList.add("Prashant"); 11 | strList.add("Jain"); 12 | //strList.add(54); 13 | 14 | strList.add(1, "Pradeep"); 15 | strList.remove(0); 16 | 17 | if (strList.contains("Jain")) { 18 | System.out.println(strList.indexOf("Jain")); 19 | } 20 | 21 | for(int i = 0; i < strList.size(); i++) { 22 | System.out.print(strList.get(i)); 23 | } 24 | 25 | for (String str : strList) { 26 | System.out.print(str); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/collection/TestingQueue.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.collection; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Queue; 5 | 6 | public class TestingQueue { 7 | public static void main(String[] args) { 8 | Queue queue = new LinkedList<>(); 9 | queue.add(1); 10 | queue.offer(2); 11 | Utility.print(queue); 12 | 13 | System.out.println(queue.peek()); 14 | System.out.println(queue.element()); 15 | 16 | System.out.println(queue.remove()); 17 | Utility.print(queue); 18 | System.out.println(queue.poll()); 19 | Utility.print(queue); 20 | 21 | System.out.println(queue.poll()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/collection/TestingSet.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.collection; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class TestingSet { 7 | public static void main(String[] args) { 8 | Set names = new HashSet<>(); 9 | System.out.println(names.add("Prashant")); 10 | System.out.println(names.add("Sanchit")); 11 | System.out.println(names.add("KG Coding")); 12 | Utility.print(names); 13 | 14 | System.out.println(names.add("Prashant")); 15 | System.out.println(names.size()); 16 | Utility.print(names); 17 | 18 | System.out.println(names.contains("Prashant")); 19 | System.out.println(names.remove("Prashant")); 20 | Utility.print(names); 21 | System.out.println(names.remove("Prashant")); 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/collection/Utility.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.collection; 2 | 3 | import java.util.Collection; 4 | 5 | public class Utility { 6 | public static void print(Collection collection) { 7 | System.out.print("Collection is: "); 8 | for (E coll : collection) { 9 | System.out.printf("%s ", coll); 10 | } 11 | System.out.println(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/enums/Grade.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.enums; 2 | 3 | public enum Grade { 4 | A, B, C, D, E, F 5 | } 6 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/enums/TestingEnums.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.enums; 2 | 3 | public class TestingEnums { 4 | 5 | public static void main(String[] args) { 6 | TrafficLight color = TrafficLight.RED; 7 | color = TrafficLight.GREEN; 8 | 9 | Grade grade = Grade.valueOf("D"); 10 | for (Grade value : Grade.values()) { 11 | System.out.println(value); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/enums/TrafficLight.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.enums; 2 | 3 | public enum TrafficLight { 4 | RED("Stop"), GREEN("Go"), YELLOW("Caution"); 5 | 6 | private final String action; 7 | 8 | TrafficLight(String action) { 9 | this.action = action; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/map/TestingMaps.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.map; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class TestingMaps { 7 | public static void main(String[] args) { 8 | Map map = new HashMap<>(); 9 | map.put("Prashant", 34); 10 | map.put("Sanchit", 100); 11 | map.put("Ram", 100); 12 | map.put("sohan", 0); 13 | System.out.println(map.size()); 14 | System.out.println(map.get("Prashant")); 15 | System.out.println(map.containsKey("Ram")); 16 | System.out.println(map.containsKey("Geeta")); 17 | System.out.println(map.remove("sohan")); 18 | System.out.println(map.size()); 19 | 20 | for (String key : map.keySet()) { 21 | System.out.printf("%s : %s\n", key, map.get(key)); 22 | } 23 | } 24 | } 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/varargs/VarArgs.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.varargs; 2 | 3 | public class VarArgs { 4 | public static void main(String... args) { 5 | System.out.println(sum(4,5)); 6 | System.out.println(sum(4,5,6)); 7 | System.out.println(sum(4,5,6,5,3,2)); 8 | System.out.println(sum(1,2,5,7,8)); 9 | } 10 | 11 | public static int sum(int first, int second, int... a) { 12 | int sum = first + second; 13 | for (int i : a) { 14 | sum += i; 15 | } 16 | return sum; 17 | } 18 | 19 | // public static int sum(int[] a) { 20 | // int sum = 0; 21 | // for (int i : a) { 22 | // sum += i; 23 | // } 24 | // return sum; 25 | // } 26 | 27 | public static int sum(int a, int b) { 28 | return a + b; 29 | } 30 | } -------------------------------------------------------------------------------- /Leacture Code/11 Collection and Generics/Leacture/src/in/kgcoding/wrapper/TestingWrapper.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.wrapper; 2 | 3 | public class TestingWrapper { 4 | public static void main(String[] args) { 5 | Integer first = 55; 6 | System.out.println(first); 7 | int second = first; 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/executor/PrintTask.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.executor; 2 | 3 | public class PrintTask implements Runnable { 4 | @Override 5 | public void run() { 6 | // Print task 7 | for (int i = 1; i <= 100; i++) { 8 | try { 9 | Thread.sleep(30); 10 | } catch (InterruptedException e) { 11 | throw new RuntimeException(e); 12 | } 13 | System.out.printf("%d%c ", i, targetChar); 14 | } 15 | System.out.printf("\n %s %c task complete", 16 | Thread.currentThread().getName(), 17 | targetChar); 18 | } 19 | 20 | private final char targetChar; 21 | 22 | public PrintTask(char targetChar) { 23 | this.targetChar = targetChar; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/executor/TestingMultipleThreadExecutor.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.executor; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class TestingMultipleThreadExecutor { 8 | public static void main(String[] args) throws InterruptedException { 9 | ExecutorService service = Executors.newFixedThreadPool(3); 10 | 11 | for (int i = 0; i < 10; i++) { 12 | PrintTask task = new PrintTask((char)i); 13 | service.submit(task); 14 | } 15 | 16 | service.shutdown(); 17 | System.out.println("\n**************1"); 18 | if (!service.awaitTermination(10, TimeUnit.SECONDS)) { 19 | System.out.println("\n**************2"); 20 | service.shutdownNow(); 21 | } 22 | 23 | } 24 | } 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/executor/TestingSingleThreadExecutor.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.executor; 2 | 3 | import in.kgcoding.multithreading.runnable.PrintTask; 4 | 5 | import java.util.concurrent.Executor; 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | 9 | public class TestingSingleThreadExecutor { 10 | public static void main(String[] args) { 11 | ExecutorService service = Executors.newSingleThreadExecutor(); 12 | PrintTask task1 = new PrintTask('*'); 13 | PrintTask task2 = new PrintTask('$'); 14 | PrintTask task3 = new PrintTask('#'); 15 | 16 | service.submit(task1); 17 | service.submit(task2); 18 | service.submit(task3); 19 | 20 | service.shutdown(); 21 | } 22 | } 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/executor/future/FetchName.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.executor.future; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | public class FetchName implements Callable { 6 | 7 | private final String name; 8 | 9 | public FetchName(String name) { 10 | this.name = name; 11 | } 12 | 13 | @Override 14 | public String call() throws Exception { 15 | System.out.printf("\n Getting full name of %s from server", name); 16 | Thread.sleep(4000); 17 | return name + " Bhartiya"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/executor/future/TestingFutures.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.executor.future; 2 | 3 | import java.util.concurrent.*; 4 | 5 | public class TestingFutures { 6 | public static void main(String[] args) throws ExecutionException, InterruptedException { 7 | ExecutorService service = Executors.newFixedThreadPool(1); 8 | FetchName task1 = new FetchName("Prashant"); 9 | FetchName task2 = new FetchName("Sanchit"); 10 | FetchName task3 = new FetchName("KG Coding"); 11 | FetchName task4 = new FetchName("Subscribe"); 12 | 13 | Future name1 = service.submit(task1); 14 | Future name2 = service.submit(task2); 15 | Future name3 = service.submit(task3); 16 | Future name4 = service.submit(task4); 17 | 18 | System.out.printf("\nFull Name is: %s", name1.get()); 19 | System.out.printf("\nFull Name is: %s", name2.get()); 20 | System.out.printf("\nFull Name is: %s", name3.get()); 21 | System.out.printf("\nFull Name is: %s", name4.get()); 22 | 23 | service.shutdown(); 24 | } 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/NeedOfMultiThreading.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading; 2 | 3 | 4 | public class NeedOfMultiThreading { 5 | public static void main(String[] args) { 6 | long startTime = System.currentTimeMillis(); 7 | // First task 8 | for (int i = 1; i <= 1000; i++) { 9 | System.out.printf("%d* ", i); 10 | } 11 | System.out.println("\n * task complete"); 12 | 13 | // Second task 14 | for (int i = 1; i <= 1000; i++) { 15 | System.out.printf("%d$ ", i); 16 | } 17 | System.out.println("\n $ task complete"); 18 | 19 | // Third task 20 | for (int i = 1; i <= 1000; i++) { 21 | System.out.printf("%d# ", i); 22 | } 23 | System.out.println("\n # task complete"); 24 | long endTime = System.currentTimeMillis(); 25 | System.out.printf("Total time taken: %d", (endTime - startTime)); 26 | } 27 | } 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/TestingPriority.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading; 2 | 3 | import in.kgcoding.multithreading.runnable.PrintTask; 4 | 5 | public class TestingPriority { 6 | public static void main(String[] args) { 7 | long startTime = System.currentTimeMillis(); 8 | PrintTask p1 = new PrintTask('*'); 9 | PrintTask p2 = new PrintTask('$'); 10 | PrintTask p3 = new PrintTask('#'); 11 | 12 | Thread t1 = new Thread(p1); 13 | t1.setPriority(Thread.MIN_PRIORITY); 14 | t1.start(); 15 | Thread t2 = new Thread(p2); 16 | t2.setPriority(Thread.NORM_PRIORITY); 17 | t2.start(); 18 | Thread t3 = new Thread(p3); 19 | t3.setPriority(Thread.MAX_PRIORITY); 20 | t3.start(); 21 | 22 | long endTime = System.currentTimeMillis(); 23 | System.out.printf("%s Total time taken: %d", 24 | Thread.currentThread().getName(), 25 | (endTime - startTime)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/join/TestingJoin.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.join; 2 | 3 | import in.kgcoding.multithreading.runnable.PrintTask; 4 | 5 | public class TestingJoin { 6 | public static void main(String[] args) throws InterruptedException { 7 | long startTime = System.currentTimeMillis(); 8 | PrintTask p1 = new PrintTask('*'); 9 | PrintTask p2 = new PrintTask('$'); 10 | PrintTask p3 = new PrintTask('#'); 11 | 12 | Thread t1 = new Thread(p1); 13 | t1.start(); 14 | System.out.println("\nThread 1 started"); 15 | Thread t2 = new Thread(p2); 16 | t2.start(); 17 | System.out.println("\nThread 2 started"); 18 | t1.join(); 19 | Thread t3 = new Thread(p3); 20 | t3.start(); 21 | System.out.println("\nThread 3 started"); 22 | 23 | long endTime = System.currentTimeMillis(); 24 | System.out.printf("%s Total time taken: %d", 25 | Thread.currentThread().getName(), 26 | (endTime - startTime)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/runnable/PrintTask.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.runnable; 2 | 3 | public class PrintTask implements Runnable { 4 | @Override 5 | public void run() { 6 | // Print task 7 | for (int i = 1; i <= 1000; i++) { 8 | System.out.printf("%d%c ", i, targetChar); 9 | } 10 | System.out.printf("\n %s %c task complete", 11 | Thread.currentThread().getName(), 12 | targetChar); 13 | } 14 | 15 | private final char targetChar; 16 | 17 | public PrintTask(char targetChar) { 18 | this.targetChar = targetChar; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/runnable/TestingRunnables.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.runnable; 2 | 3 | public class TestingRunnables { 4 | public static void main(String[] args) { 5 | long startTime = System.currentTimeMillis(); 6 | PrintTask p1 = new PrintTask('*'); 7 | PrintTask p2 = new PrintTask('$'); 8 | PrintTask p3 = new PrintTask('#'); 9 | 10 | Thread t1 = new Thread(p1); 11 | t1.start(); 12 | Thread t2 = new Thread(p2); 13 | t2.start(); 14 | Thread t3 = new Thread(p3); 15 | t3.start(); 16 | 17 | long endTime = System.currentTimeMillis(); 18 | System.out.printf("%s Total time taken: %d", 19 | Thread.currentThread().getName(), 20 | (endTime - startTime)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/sleep/TestingSleep.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.sleep; 2 | 3 | public class TestingSleep { 4 | public static void main(String[] args) throws InterruptedException { 5 | System.out.println("Before Sleeping"); 6 | Thread.sleep(5000); 7 | System.out.println("Woke up"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/synchronize/Counter.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.synchronize; 2 | 3 | public class Counter { 4 | 5 | private int count = 0; 6 | 7 | public synchronized void increment() { 8 | count++; 9 | } 10 | 11 | public int getCount() { 12 | return count; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/synchronize/TestingSynchronize.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.synchronize; 2 | 3 | public class TestingSynchronize { 4 | public static void main(String[] args) { 5 | long startTime = System.currentTimeMillis(); 6 | Counter counter = new Counter(); 7 | UpdaterThread t1 = new UpdaterThread(counter); 8 | UpdaterThread t2 = new UpdaterThread(counter); 9 | 10 | try { 11 | t1.start(); 12 | t2.start(); 13 | 14 | t1.join(); 15 | t2.join(); 16 | } catch (InterruptedException e) { 17 | System.out.println("Thread interrupted: " + e.getMessage()); 18 | } 19 | 20 | long endTime = System.currentTimeMillis(); 21 | System.out.printf("Final counter value: %d and" + 22 | " time taken: %d", 23 | counter.getCount(), 24 | (endTime - startTime)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/synchronize/UpdaterThread.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.synchronize; 2 | 3 | public class UpdaterThread extends Thread { 4 | 5 | private final Counter counter; 6 | 7 | public UpdaterThread(Counter counter) { 8 | this.counter = counter; 9 | } 10 | 11 | @Override 12 | public void run() { 13 | for (int i = 0; i < 10000; i++) { 14 | counter.increment(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/threadclass/ExtendingThreadClass.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.threadclass; 2 | 3 | 4 | public class ExtendingThreadClass { 5 | public static void main(String[] args) { 6 | long startTime = System.currentTimeMillis(); 7 | FirstTask t1 = new FirstTask(); 8 | SecondTask t2 = new SecondTask(); 9 | ThirdTask t3 = new ThirdTask(); 10 | 11 | System.out.println("\nStarting First Thread"); 12 | t1.start(); 13 | System.out.println("\nStarting Second Thread"); 14 | t2.start(); 15 | System.out.println("\nStarting Third Thread"); 16 | t3.start(); 17 | 18 | long endTime = System.currentTimeMillis(); 19 | System.out.printf("%s Total time taken: %d", 20 | Thread.currentThread().getName(), 21 | (endTime - startTime)); 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/threadclass/FirstTask.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.threadclass; 2 | 3 | public class FirstTask extends Thread { 4 | @Override 5 | public void run() { 6 | // First task 7 | for (int i = 1; i <= 1000; i++) { 8 | System.out.printf("%d* ", i); 9 | } 10 | System.out.printf("\n %s * task complete", 11 | Thread.currentThread().getName()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/threadclass/SecondTask.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.threadclass; 2 | 3 | public class SecondTask extends Thread { 4 | @Override 5 | public void run() { 6 | // Second task 7 | for (int i = 1; i <= 1000; i++) { 8 | System.out.printf("%d$ ", i); 9 | } 10 | System.out.printf("\n %s $ task complete", 11 | Thread.currentThread().getName()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Leacture Code/12 Multithreading and Executor Service/Leacture/src/in/kgcoding/multithreading/threadclass/ThirdTask.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.multithreading.threadclass; 2 | 3 | public class ThirdTask extends Thread { 4 | @Override 5 | public void run() { 6 | // Third task 7 | for (int i = 1; i <= 1000; i++) { 8 | System.out.printf("%d# ", i); 9 | } 10 | System.out.printf("\n %s # task complete", 11 | Thread.currentThread().getName()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/src/in/kgcoding/filterandreduce/TestingFilter.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.filterandreduce; 2 | 3 | import java.util.List; 4 | import java.util.function.Consumer; 5 | 6 | public class TestingFilter { 7 | public static void main(String[] args) { 8 | List fruits = List.of("apple", "banana", "mango", "cherry", "date"); 9 | System.out.println(fruits.size()); 10 | 11 | System.out.println("Printing Fruits normally"); 12 | for (String fruit : fruits) { 13 | System.out.println(fruit); 14 | } 15 | 16 | System.out.println("Printing Fruits using streams"); 17 | fruits.stream().forEach(new Consumer() { 18 | @Override 19 | public void accept(String fruit) { 20 | System.out.println(fruit); 21 | } 22 | }); 23 | System.out.println("Printing Fruits using filter"); 24 | fruits.stream() 25 | .filter(fruit -> fruit.endsWith("e")) 26 | .forEach(fruit -> System.out.println(fruit)); 27 | } 28 | } 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/src/in/kgcoding/filterandreduce/TestingReduce.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.filterandreduce; 2 | 3 | import java.util.List; 4 | import java.util.function.BinaryOperator; 5 | 6 | public class TestingReduce { 7 | public static void main(String[] args) { 8 | List numbers = List.of(1,3,4,2,5,6,3); 9 | int sum = 0; 10 | for (Integer number : numbers) { 11 | sum += number; 12 | } 13 | System.out.println(sum); 14 | 15 | int newSum = numbers.stream() 16 | .reduce(0, new BinaryOperator() { 17 | @Override 18 | public Integer apply(Integer integer, Integer integer2) { 19 | return integer + integer2; 20 | } 21 | }); 22 | System.out.printf("\nSum using reduce is %d", newSum); 23 | 24 | int newSum2 = numbers.stream() 25 | .reduce(0, (a, b) -> a + b); 26 | System.out.printf("\nSum using reduce is %d", newSum2); 27 | 28 | 29 | int max = numbers.stream() 30 | .reduce(Integer.MIN_VALUE, (a, b) -> a > b ? a : b); 31 | System.out.printf("\nmax using reduce is %d", max); 32 | } 33 | } 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/src/in/kgcoding/lambda/TestingLambda.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.lambda; 2 | 3 | public class TestingLambda { 4 | public static void main(String[] args) { 5 | TestingLambda test = new TestingLambda(); 6 | int sum = test.sum(6, 7); 7 | test.printString("This is the best course"); 8 | 9 | // toPrint -> System.out.println(toPrint); 10 | // (a, b) -> a + b; 11 | // (a, b) -> { 12 | // int sum = a + b; 13 | // System.out.println(sum); 14 | // } 15 | } 16 | 17 | private void printString(String toPrint) { 18 | System.out.println(toPrint); 19 | } 20 | 21 | private int sum(int a, int b) { 22 | int sum = a + b; 23 | return sum; 24 | } 25 | } -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/src/in/kgcoding/methodreferences/TestingMethodInterface.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.methodreferences; 2 | 3 | import java.util.List; 4 | import java.util.function.BinaryOperator; 5 | 6 | public class TestingMethodInterface { 7 | public static void main(String[] args) { 8 | List numbers = List.of(1,3,4,2,5,6,3); 9 | 10 | numbers.stream() 11 | .filter(num -> num % 2 == 1) 12 | .forEach(System.out::println); 13 | 14 | numbers.stream() 15 | .filter(num -> num % 2 == 1) 16 | .forEach(num -> System.out.println(num)); 17 | 18 | int newSum2 = numbers.stream() 19 | .reduce(0, (a, b) -> a + b); 20 | 21 | newSum2 = numbers.stream() 22 | .reduce(0, Integer::sum); 23 | 24 | System.out.printf("\nSum using reduce is %d", newSum2); 25 | } 26 | } 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Leacture Code/13 Functional Programming/Leacture/src/in/kgcoding/optional/TestingOptional.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.optional; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | public class TestingOptional { 7 | public static void main(String[] args) { 8 | 9 | List numbers = List.of(1,3,4,2,5,6,3); 10 | Optional newSum2 = numbers.stream() 11 | .reduce((a, b) -> a + b); 12 | if (newSum2.isPresent()) { 13 | System.out.println(newSum2.get()); 14 | } else { 15 | System.out.println("List is empty"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/FirstProgram.java: -------------------------------------------------------------------------------- 1 | import java.lang.*; 2 | 3 | public class FirstProgram { 4 | public static void main(String[] args) { 5 | System.out.println("Welcome"); 6 | System.out.println("KG"); 7 | System.out.println("Coding"); 8 | } 9 | } -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/FirstProject/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/FirstProject/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/FirstProject/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/FirstProject/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/FirstProject/FirstProject.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/FirstProject/src/Main.java: -------------------------------------------------------------------------------- 1 | package FirstProject.src; 2 | public class Main { 3 | public static void main(String[] args) { 4 | System.out.println("Welcome KG Coding"); 5 | System.out.println("asdfasdf"); 6 | } 7 | } -------------------------------------------------------------------------------- /Leacture Code/2 Java Basics/Variables.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Complete-Coding/Java_Complete_Youtube/0351665e51429236f64363acb1800ef499ecbe76/Leacture Code/2 Java Basics/Variables.java -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/Three.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/src/Escape.java: -------------------------------------------------------------------------------- 1 | public class Escape { 2 | public static void main(String[] args) { 3 | System.out.println("Hello\bKGCoding..."); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/src/TypeConversion.java: -------------------------------------------------------------------------------- 1 | public class TypeConversion { 2 | public static void main(String[] args) { 3 | float myFloat = 5; 4 | System.out.println(myFloat); 5 | 6 | int myInt = (int) 5.45f; 7 | System.out.println(myInt); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/src/UserInput.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class UserInput { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.print("Please enter your name: "); 7 | String name = input.nextLine(); 8 | System.out.println("Good Morning " + name); 9 | System.out.print(name + ", Also tell me your age:"); 10 | int age = input.nextInt(); 11 | System.out.println("Your age is: " + age); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Leacture Code/3 Data Types Variables and Input/Three/src/Variables.java: -------------------------------------------------------------------------------- 1 | public class Variables { 2 | public static void main(String[] args) { 3 | int myNumber = 865; 4 | int myNUMBER = 865; 5 | int yourNumber = 0; 6 | 7 | int asdf987 = 8; 8 | 9 | int uh87d87yyd87 = 90; 10 | 11 | System.out.println(yourNumber); 12 | yourNumber = 865; 13 | System.out.println(yourNumber); 14 | yourNumber = 45; 15 | System.out.println(yourNumber); 16 | 17 | float myFloat = 5.0f; 18 | double myDouble = 6.98766; 19 | System.out.println(myFloat); 20 | 21 | boolean isVegetarian = true; 22 | System.out.println(isVegetarian); 23 | 24 | String wishes = "Good Morning"; 25 | System.out.println(wishes); 26 | 27 | char myCharacter = 'K'; 28 | 29 | 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/Arithmetic.java: -------------------------------------------------------------------------------- 1 | public class Arithmetic { 2 | public static void main(String[] args) { 3 | int a = 8; 4 | int b = 5; 5 | 6 | System.out.println(a+b); 7 | System.out.println(a-b); 8 | System.out.println(a*b); 9 | System.out.println(a/b); 10 | System.out.println(a%b); 11 | 12 | double x = 5; 13 | double y = 3; 14 | System.out.println(x+y); 15 | System.out.println(x-y); 16 | System.out.println(x*y); 17 | System.out.println(x/y); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/Assignment.java: -------------------------------------------------------------------------------- 1 | public class Assignment { 2 | public static void main(String[] args) { 3 | int myInt = 9; 4 | System.out.println(myInt); 5 | int newInt = myInt; 6 | System.out.println(newInt); 7 | 8 | //9 = myInt; 9 | } 10 | } -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/LearningIf.java: -------------------------------------------------------------------------------- 1 | public class LearningIf { 2 | public static void main(String[] args) { 3 | boolean isMale = true; 4 | String name = "Bob"; 5 | 6 | System.out.println("before if"); 7 | if (isMale) { 8 | System.out.println("Mr." + name); 9 | } else { 10 | System.out.println("Ms." + name); 11 | } 12 | System.out.println("after if"); 13 | 14 | boolean isSeniorCitizen = false; 15 | boolean isAnAdult = true; 16 | 17 | if (isSeniorCitizen) { 18 | System.out.println("Hello Senior Citizen"); 19 | } else if (isAnAdult) { 20 | System.out.println("Hello Adult"); 21 | } else { 22 | System.out.println("Hello Child"); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/Logical.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Logical { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Ticket Discount Calculator"); 7 | System.out.print("Please enter your age: "); 8 | int age = input.nextInt(); 9 | System.out.print("Are you a female? (true/false) "); 10 | boolean isFemale = input.nextBoolean(); 11 | 12 | if (age < 5) { 13 | System.out.println("You got 75% discount"); 14 | } else if (isFemale) { 15 | System.out.println("You got 50% discount"); 16 | } else if (age > 60 && !isFemale) { 17 | System.out.println("You got 25% discount"); 18 | } else { 19 | System.out.println("You got no discount"); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/OrderOfOperation.java: -------------------------------------------------------------------------------- 1 | public class OrderOfOperation { 2 | public static void main(String[] args) { 3 | System.out.println(8-3*3); 4 | 5 | System.out.println(9/(3/3 + 2)); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/Relational.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Relational { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Driving License Portal"); 7 | System.out.print("Please enter your age: "); 8 | int age = input.nextInt(); 9 | 10 | if (age >= 18) { 11 | System.out.println("You are eligible to drive"); 12 | } else { 13 | System.out.println("Beta cycle chalao"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/Shorthand.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Shorthand { 4 | public static void main(String[] args) { 5 | int a = 5; 6 | Scanner input = new Scanner(System.in); 7 | int x1 = input.nextInt(); 8 | a = a + x1; 9 | a += x1; 10 | 11 | 12 | System.out.println(a); 13 | int x2 = input.nextInt(); 14 | a = a + x2; 15 | System.out.println(a); 16 | int x3 = input.nextInt(); 17 | a = a + x3; 18 | System.out.println(a); 19 | int x4 = input.nextInt(); 20 | a = a + x4; 21 | System.out.println(a); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Leacture Code/4 Operators If-else and Number System/Leacture/src/Unary.java: -------------------------------------------------------------------------------- 1 | public class Unary { 2 | public static void main(String[] args) { 3 | int x = 5; 4 | int y = -x; 5 | int z = -y; 6 | System.out.println(z); 7 | 8 | 9 | int a = 5; 10 | a = a + 1; 11 | System.out.println(a); 12 | a += 1; 13 | System.out.println(a); 14 | 15 | System.out.println("Watching increment"); 16 | int p = 5; 17 | System.out.println(p++); 18 | System.out.println(p); 19 | 20 | System.out.println(++p); 21 | System.out.println(p); 22 | 23 | int q = 10; 24 | System.out.println(--q); 25 | System.out.println(q); 26 | 27 | System.out.println(q--); 28 | System.out.println(q); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/Array.java: -------------------------------------------------------------------------------- 1 | public class Array { 2 | public static void main(String[] args) { 3 | // int[] myArr = new int[5]; 4 | // myArr[0] = 98; 5 | // myArr[3] = 65; 6 | // myArr[1] = 2; 7 | // myArr[2] = 8; 8 | // myArr[4] = 37; 9 | int[] myArr = {98, 2, 8, 65, 37}; 10 | // int index = 2; 11 | 12 | // System.out.println(myArr[0]); 13 | // System.out.println(myArr[1]); 14 | // System.out.println(myArr[index]); 15 | // System.out.println(myArr[3]); 16 | // System.out.println(myArr[4]); 17 | // Array Traversal 18 | int index = 0; 19 | while (index < myArr.length) { 20 | System.out.println(myArr[index]); 21 | index++; 22 | } 23 | 24 | 25 | String[] strArr = new String[4]; 26 | strArr[0] = "My String"; 27 | 28 | String[] newStrArr = {"first", "second", "third"}; 29 | System.out.println(newStrArr.length); 30 | } 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/ArraySearching.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ArraySearching { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | int[] arr = {3, 6, 8, 87, 65, 4, 68, 23, 9, 98, 34}; 7 | System.out.println("Welcome to Array Searching\n"); 8 | System.out.print("Enter the number you want to search: "); 9 | int num = input.nextInt(); 10 | boolean isFound = isFound(arr, num); 11 | if (isFound) { 12 | System.out.println("Your number was found in the array"); 13 | } else { 14 | System.out.println("Your number was not found in the array"); 15 | } 16 | } 17 | 18 | public static boolean isFound(int[] arr, int num) { 19 | int index = 0; 20 | while (index < arr.length) { 21 | if (arr[index] == num) { 22 | return true; 23 | } 24 | index++; 25 | } 26 | return false; 27 | } 28 | } 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/Car.java: -------------------------------------------------------------------------------- 1 | public class Car { 2 | String color; 3 | float price; 4 | 5 | static { 6 | System.out.println("This is a Static Block"); 7 | } 8 | 9 | { 10 | System.out.println("This is a Initialization Block"); 11 | color = "Black"; 12 | price = 50000; 13 | } 14 | 15 | Car(String carColor, float currPrice) { 16 | color = carColor; 17 | price = currPrice; 18 | } 19 | 20 | Car() { // Default constructor 21 | color = "Black"; 22 | price = 50000; 23 | } 24 | 25 | public static void main(String[] args) { 26 | Car swift = new Car(); 27 | 28 | if (true) { // code block 29 | System.out.println("Code Block"); 30 | } 31 | } 32 | } 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/Comments.java: -------------------------------------------------------------------------------- 1 | public class Comments { 2 | /** 3 | * This is my main method 4 | * @param args 5 | */ 6 | public static void main(String[] args) { 7 | // this is important, don't delete this 8 | System.out.println("Hello world!"); 9 | 10 | /* 11 | this is the first line of the comment 12 | the comment is still continuing 13 | */ 14 | int a = 5; 15 | } 16 | } -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/Function.java: -------------------------------------------------------------------------------- 1 | public class Function { 2 | public static void main(String[] args) { 3 | // System.out.println("In main method"); 4 | // greetUser(); 5 | // System.out.println("Method calling complete"); 6 | // greetUser(); 7 | 8 | printFirstPattern(); 9 | // printSecondPattern(); 10 | // printThirdPattern(); 11 | } 12 | 13 | public static void printThirdPattern() { 14 | System.out.println(" *"); 15 | System.out.println(" * *"); 16 | System.out.println(" * * *"); 17 | System.out.println(" * * * *"); 18 | System.out.println("* * * * *"); 19 | } 20 | 21 | public static void printSecondPattern() { 22 | System.out.println("* * * * *"); 23 | System.out.println("* * * *"); 24 | System.out.println("* * *"); 25 | System.out.println("* *"); 26 | System.out.println("*"); 27 | } 28 | 29 | public static void printFirstPattern() { 30 | int rows = 0; 31 | while (rows < 5) { 32 | System.out.print("*"); 33 | int i = 0; 34 | while (i < rows) { 35 | System.out.print(" *"); 36 | i++; 37 | } 38 | System.out.println(); 39 | rows++; 40 | } 41 | } 42 | 43 | public static void greetUser() { 44 | System.out.println("Good Morning from KGCoding"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/Loop.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Loop { 4 | public static void main(String[] args) { 5 | int num = 1; // initialization 6 | while (num <= 10) { // condition 7 | System.out.println(num); // actual work 8 | num = num + 1; // updating the condition 9 | } 10 | 11 | int count = 500; 12 | while (count >= 200) { 13 | System.out.println(count); 14 | count -= 1; 15 | } 16 | 17 | Scanner input = new Scanner(System.in); 18 | int i = 0; 19 | while (i < 5) { 20 | int inp = input.nextInt(); 21 | System.out.println("Number is: " + inp); 22 | i++; 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/Parameter.java: -------------------------------------------------------------------------------- 1 | public class Parameter { 2 | public static void main(String[] args) { 3 | System.out.println(sumTwoNumbers(4, 7)); 4 | System.out.println(sumTwoNumbers(5, 9)); 5 | System.out.println(sumTwoNumbers(-67, 67)); 6 | } 7 | 8 | public static int sumTwoNumbers(int firstNum, int secondNum) { 9 | System.out.println("First Number received: " + firstNum); 10 | System.out.println("Second Number received: " + secondNum); 11 | return firstNum + secondNum; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/Return.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Return { 4 | public static void main(String[] args) { 5 | greet(); 6 | int first = readNumber(); 7 | int second = readNumber(); 8 | 9 | int sum = first + second; 10 | System.out.println("Sum of the numbers is: " + sum); 11 | } 12 | 13 | public static int readNumber() { 14 | Scanner input = new Scanner(System.in); 15 | System.out.print("Please enter the number: "); 16 | int number = input.nextInt(); 17 | return number; 18 | } 19 | 20 | public static void greet() { 21 | System.out.println("Welcome to Calculator\n"); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Leacture Code/5 While loop, Methods and Arrays/Leacture/src/TwoDimensionalArray.java: -------------------------------------------------------------------------------- 1 | public class TwoDimensionalArray { 2 | public static void main(String[] args) { 3 | int[][] myArr = new int[2][3]; 4 | myArr[0][0] = 9; 5 | 6 | int[][] arr = {{1,2,3}, {4,5,6}, {7,8,9}}; 7 | System.out.println(arr[0].length); 8 | 9 | // Traversal 10 | int i = 0; 11 | while (i < arr.length) { 12 | int j = 0; 13 | while (j < arr[i].length) { 14 | System.out.print(arr[i][j] + " "); 15 | j++; 16 | } 17 | System.out.println(); 18 | i++; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Leacture Code/6 Class and Object/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/6 Class and Object/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/6 Class and Object/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/6 Class and Object/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/6 Class and Object/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/6 Class and Object/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/6 Class and Object/Leacture/src/Driver.java: -------------------------------------------------------------------------------- 1 | public class Driver { 2 | 3 | static int minAgeForDriving = 18; 4 | 5 | String name; 6 | int age; 7 | String dateOfLicense; 8 | 9 | public boolean isAllowedToDrive() { 10 | return this.age >= minAgeForDriving; 11 | } 12 | 13 | 14 | public static void main(String[] args) { 15 | // Car myCar = new Car(); 16 | // myCar.addFuel(6); 17 | // myCar.drive(); 18 | // myCar.drive(); 19 | // myCar.drive(); 20 | // myCar.addFuel(3); 21 | // myCar.drive(); 22 | // System.out.println(myCar.getCurrentFuelLevel()); 23 | 24 | Car swift = new Car("Red"); 25 | Car thar = new Car(); 26 | thar = null; 27 | //swift.addFuel(6); 28 | swift.start().drive(); 29 | System.out.println(swift.color); 30 | 31 | // Driver myDriver = new Driver(); 32 | // myDriver.dateOfLicense = "1/Jan/2024"; 33 | // System.out.println(minAgeForDriving); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/BreakAndContinue.java: -------------------------------------------------------------------------------- 1 | public class BreakAndContinue { 2 | public static void main(String[] args) { 3 | // System.out.println("before loop"); 4 | // for (int i = 1; i < 1000; i++) { 5 | // if (i == 101) { 6 | // break; 7 | // } 8 | // System.out.println(i); 9 | // } 10 | // System.out.println("Out of loop"); 11 | 12 | System.out.println("before loop"); 13 | for (int i = 1; i < 10; i++) { 14 | if (i == 5) { 15 | continue; 16 | } 17 | System.out.println(i); 18 | } 19 | System.out.println("Out of loop"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/Car.java: -------------------------------------------------------------------------------- 1 | public class Car { 2 | int noOfWheels; 3 | int noOfDoors; 4 | int maxSpeed; 5 | String name; 6 | String modelNumber; 7 | String company; 8 | 9 | public Car(int noOfWheels, int noOfDoors, int maxSpeed, String name, String modelNumber, String company) { 10 | this.noOfWheels = noOfWheels; 11 | this.noOfDoors = noOfDoors; 12 | this.maxSpeed = maxSpeed; 13 | this.name = name; 14 | this.modelNumber = modelNumber; 15 | this.company = company; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | final StringBuilder sb = new StringBuilder("Car{"); 21 | sb.append("noOfWheels=").append(noOfWheels); 22 | sb.append(", noOfDoors=").append(noOfDoors); 23 | sb.append(", maxSpeed=").append(maxSpeed); 24 | sb.append(", name='").append(name).append('\''); 25 | sb.append(", modelNumber='").append(modelNumber).append('\''); 26 | sb.append(", company='").append(company).append('\''); 27 | sb.append('}'); 28 | return sb.toString(); 29 | } 30 | 31 | public static void main(String[] args) { 32 | Car swift = new Car(4, 4, 120, 33 | "Swift", "SW876", "Maruti"); 34 | System.out.println(swift); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/DoWhile.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class DoWhile { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | // System.out.print("Please enter your age: "); 7 | // int age = input.nextInt(); 8 | // while (age < 0 || age > 100) { 9 | // System.out.print("Please enter your age: "); 10 | // age = input.nextInt(); 11 | // } 12 | int age; 13 | do { 14 | System.out.print("Please enter your age: "); 15 | age = input.nextInt(); 16 | } while (age < 0 || age > 100); 17 | System.out.println("Your age is: " + age); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/ForEachLoop.java: -------------------------------------------------------------------------------- 1 | public class ForEachLoop { 2 | public static void main(String[] args) { 3 | String[] array = new String[] { 4 | "Ram", "Shyam", "Mohan", "Sohan", "Sita", "Geeta" 5 | }; 6 | // printArray(array); 7 | printArrayForEach(array); 8 | } 9 | public static void printArrayForEach(String[] array) { 10 | for (String name : array) { 11 | System.out.println(name); 12 | } 13 | } 14 | public static void printArray(String[] array) { 15 | for (int i = 0; i < array.length; i++) { 16 | System.out.println(array[i]); 17 | } 18 | } 19 | } 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/ForLoop.java: -------------------------------------------------------------------------------- 1 | public class ForLoop { 2 | public static void main(String[] args) { 3 | int i = 1; 4 | while (i <= 100) { 5 | System.out.print(i + " "); 6 | i++; 7 | } 8 | System.out.println(); 9 | 10 | for (int j = 1; j <= 100; j += 2) { 11 | System.out.print(j + " "); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/KGMath.java: -------------------------------------------------------------------------------- 1 | public class KGMath { 2 | public static void main(String[] args) { 3 | System.out.println(Math.abs(-99)); 4 | System.out.println(Math.ceil(5.07)); 5 | System.out.println(Math.floor(5.07)); 6 | System.out.println(Math.round(5.57)); 7 | System.out.println(Math.PI); 8 | 9 | 10 | for (int i = 0; i < 10; i++) { 11 | int random = (int) Math.round(Math.random() * 100); 12 | System.out.println(random); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/Recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Recursion { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Factorial generator\n"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | long fact = factorial(num); 10 | System.out.println("Factorial of your number is: " + fact); 11 | } 12 | 13 | public static long factorial(int num) { 14 | System.out.println("Function called for: " + num); 15 | if (num == 1) { 16 | return 1; 17 | } 18 | return num * factorial(num - 1); 19 | } 20 | 21 | public static long factorialIterative(int num) { 22 | long result = 1; 23 | for (int i = 1; i <= num; i++) { 24 | result *= i; 25 | } 26 | return result; 27 | } 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/StringFormat.java: -------------------------------------------------------------------------------- 1 | public class StringFormat { 2 | public static void main(String[] args) { 3 | String name = "Sandeep"; 4 | int marks = 45765; 5 | System.out.println("Hello " + name + ", your marks are: " + marks); 6 | 7 | System.out.printf("Hello %-10S, your marks are: %0,5d", name, marks); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/StringTest.java: -------------------------------------------------------------------------------- 1 | public class StringTest { 2 | public static void main(String[] args) { 3 | StringBuilder sb = new StringBuilder("First"); 4 | sb.append(45); 5 | sb.append(", now this is the"); 6 | sb.append(76.45); 7 | System.out.println(sb); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/TernaryOperator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TernaryOperator { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to number checker\n"); 7 | System.out.print("Please enter your first number: "); 8 | int num1 = input.nextInt(); 9 | System.out.print("Now, enter the second number: "); 10 | int num2 = input.nextInt(); 11 | 12 | // int greaterNumber; 13 | // if (num1 > num2) { 14 | // greaterNumber = num1; 15 | // } else { 16 | // greaterNumber = num2; 17 | // } 18 | int greaterNumber = num1 > num2 ? num1 : num2; 19 | System.out.println(greaterNumber + " is the greatest number"); 20 | } 21 | } 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Leacture Code/7 Control Statements Math and String/Leacture/src/TestingFinal.java: -------------------------------------------------------------------------------- 1 | public class TestingFinal { 2 | 3 | final double PI = 3.1412; 4 | 5 | void testing() { 6 | } 7 | 8 | public static void main(String[] args) { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/Leacture.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/gettersetter/Car.java: -------------------------------------------------------------------------------- 1 | package in.gettersetter; 2 | 3 | public class Car { 4 | private String color; // public 5 | private String model; // public 6 | private double fuelLevel; 7 | private long costOfPurchase; // default 8 | 9 | 10 | 11 | public Car(String color, String model, double fuelLevel, long costOfPurchase) { 12 | this.color = color; 13 | this.model = model; 14 | this.fuelLevel = fuelLevel; 15 | this.costOfPurchase = costOfPurchase; 16 | } 17 | 18 | public double getFuelLevel() { 19 | return fuelLevel; 20 | } 21 | 22 | public void setFuelLevel(double fuelLevel) { 23 | this.fuelLevel = fuelLevel; 24 | } 25 | 26 | public String getColor() { 27 | return color; 28 | } 29 | 30 | public void setColor(String color) { 31 | if (color.equals("Yellow")) { 32 | System.out.println("Pagal hai kya"); 33 | } else { 34 | this.color = color; 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/AccessTest.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding; 2 | 3 | public class AccessTest { 4 | public static void main(String[] args) { 5 | Car car = new Car(); 6 | car.color = "Red"; 7 | car.model = "Swift"; 8 | car.costOfPurchase = 7654; 9 | System.out.println(car); 10 | Car newCar = new Car("Black", "BMW", 11 | 1, 5000); 12 | System.out.println(newCar); 13 | 14 | Default def = new Default(); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/Car.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding; 2 | 3 | public class Car { 4 | public String color; 5 | public String model; 6 | private double fuelLevel; 7 | long costOfPurchase; 8 | 9 | public Car() { 10 | 11 | } 12 | 13 | public Car(String color, String model, double fuelLevel, long costOfPurchase) { 14 | this.color = color; 15 | this.model = model; 16 | this.fuelLevel = fuelLevel; 17 | this.costOfPurchase = costOfPurchase; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | final StringBuilder sb = new StringBuilder("Car{"); 23 | sb.append("color='").append(color).append('\''); 24 | sb.append(", model='").append(model).append('\''); 25 | sb.append(", fuelLevel=").append(fuelLevel); 26 | sb.append(", costOfPurchase=").append(costOfPurchase); 27 | sb.append('}'); 28 | return sb.toString(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/Default.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding; 2 | 3 | class Default { 4 | } 5 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/Packages.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Packages { 6 | public static void main(String[] args) { 7 | Scanner input = new Scanner(System.in); 8 | in.knowledgegate.Packages packages = new in.knowledgegate.Packages(); 9 | } 10 | } -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/TwoWheeler.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding; 2 | 3 | import in.kgcoding.inheritance.Vehicle; 4 | 5 | public class TwoWheeler extends Vehicle { 6 | public TwoWheeler() { 7 | setNumberOfTires(2); 8 | numberOfTires = 4; 9 | } 10 | 11 | public void balance() { 12 | System.out.println("I am balancing on two tires"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/equals/EqualsAndHashCodeTest.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.equals; 2 | 3 | public class EqualsAndHashCodeTest { 4 | public static void main(String[] args) { 5 | Person person1 = new Person("Prashant", 31, "001"); 6 | Person person2 = new Person("Prashant", 30, "001"); 7 | 8 | if (person1.equals(person2)) { 9 | System.out.println("Equals"); 10 | } else { 11 | System.out.println("Not equal"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/inheritance/InheritanceTest.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.inheritance; 2 | 3 | import in.kgcoding.TwoWheeler; 4 | 5 | public class InheritanceTest { 6 | public static void main(String[] args) { 7 | Vehicle vehicle = new Vehicle(); 8 | vehicle.commute(); 9 | System.out.println(vehicle.toString()); 10 | System.out.println(vehicle.hashCode()); 11 | System.out.println(vehicle.getClass()); 12 | 13 | TwoWheeler two = new TwoWheeler(); 14 | two.commute(); 15 | two.balance(); 16 | 17 | MotorCycle motor = new MotorCycle(); 18 | motor.commute(); 19 | motor.balance(); 20 | motor.start(); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/inheritance/MotorCycle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.inheritance; 2 | 3 | import in.kgcoding.TwoWheeler; 4 | 5 | public class MotorCycle extends TwoWheeler { 6 | public double petrolCapacity; 7 | 8 | public void start() { 9 | System.out.println("Starting"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/inheritance/Vehicle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.inheritance; 2 | 3 | public class Vehicle { 4 | protected int numberOfTires; 5 | 6 | public void setNumberOfTires(int numberOfTires) { 7 | this.numberOfTires = numberOfTires; 8 | } 9 | 10 | @Override 11 | public String toString() { 12 | return "Vehicle no of tires: " + numberOfTires; 13 | } 14 | 15 | public void commute() { 16 | System.out.printf("I am going from place A to place B using %d tires\n", numberOfTires); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/nested/Car.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.nested; 2 | 3 | public class Car { 4 | 5 | private int noOfDoors; 6 | 7 | public void repair() { 8 | Tire t = new Tire(); 9 | } 10 | protected class Tire { 11 | private double width; 12 | private double pressure; 13 | private String material; 14 | 15 | public void inflate() { 16 | noOfDoors = 4; 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/passby/TestPassByReference.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.passby; 2 | 3 | public class TestPassByReference { 4 | 5 | public static void main(String[] args) { 6 | Point first = new Point(4, 8); 7 | System.out.println("first: " + first); 8 | move(first); 9 | System.out.println("first: " + first); 10 | } 11 | 12 | public static void move(Point p) { 13 | p.x++; 14 | p.y++; 15 | System.out.println(p); 16 | } 17 | 18 | 19 | public static class Point { 20 | int x; 21 | int y; 22 | 23 | public Point(int x, int y) { 24 | this.x = x; 25 | this.y = y; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | final StringBuilder sb = new StringBuilder("Point{"); 31 | sb.append("x=").append(x); 32 | sb.append(", y=").append(y); 33 | sb.append('}'); 34 | return sb.toString(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/passby/TestPassByValue.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.passby; 2 | 3 | public class TestPassByValue { 4 | public static void main(String[] args) { 5 | int x = 5; 6 | int y = 10; 7 | int sum = add(x, y); 8 | System.out.printf("x=%d, y=%d, sum=%d", x, y, sum); 9 | } 10 | 11 | public static int add(int a, int b) { 12 | a = 99; 13 | return a; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/polymorphism/Car.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.polymorphism; 2 | 3 | class Car extends Vehicle { 4 | 5 | Car() { 6 | super(); 7 | } 8 | Car(int noOfTires) { 9 | super(noOfTires); 10 | } 11 | 12 | public int noOfDoors() { 13 | return 5; 14 | } 15 | 16 | @Override 17 | public void start() { 18 | System.out.println(super.getNoOfTires()); 19 | System.out.println("Car is starting"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/polymorphism/Overloading.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.polymorphism; 2 | 3 | public class Overloading { 4 | 5 | Overloading() { 6 | System.out.println("Default constructor called."); 7 | } 8 | 9 | Overloading(String pop) { 10 | System.out.println(pop); 11 | } 12 | 13 | 14 | public int add(int a, int b) { 15 | return a + b; 16 | } 17 | 18 | public String add(String a, String b) { 19 | return a + b; 20 | } 21 | 22 | public int add(int a, int b, int c, int d) { 23 | return a + b + c + d; 24 | } 25 | 26 | public static void main(String[] args) { 27 | Overloading overload = new Overloading(); 28 | int sum = overload.add(3, 4); 29 | overload.add("a", "b"); 30 | System.out.println(overload.add(5, sum)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/polymorphism/Plane.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.polymorphism; 2 | 3 | class Plane extends Vehicle { 4 | @Override 5 | public void start() { 6 | System.out.println("Plane is taking off"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/polymorphism/TestTransportation.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.polymorphism; 2 | 3 | public class TestTransportation { 4 | public static void main(String[] args) { 5 | Car c = new Car(); 6 | //Vehicle v = new Vehicle(); 7 | Plane p = new Plane(); 8 | 9 | // c.start(); 10 | // p.start(); 11 | 12 | //castTest(v); 13 | castTest(c); 14 | castTest(p); 15 | 16 | //Vehicle vCar = new Car(); 17 | 18 | //Car cVehicle = (Car) new Vehicle(); 19 | } 20 | 21 | private static void castTest(Vehicle veh) { 22 | //Car cVehicle = (Car) veh; 23 | //veh.noOfDoors(); 24 | veh.start(); 25 | //cVehicle.noOfDoors(); 26 | 27 | // if (veh instanceof Car) { 28 | // 29 | // } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/kgcoding/polymorphism/Vehicle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.polymorphism; 2 | 3 | public abstract class Vehicle { 4 | 5 | private int noOfTires; 6 | 7 | Vehicle() { 8 | this.noOfTires = 0; 9 | } 10 | 11 | Vehicle(int noOfTires) { 12 | this.noOfTires = noOfTires; 13 | } 14 | 15 | public int getNoOfTires() { 16 | return this.noOfTires; 17 | } 18 | 19 | public void start() { 20 | System.out.println("Vehicle is starting..."); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/knowledgegate/DefaultTest.java: -------------------------------------------------------------------------------- 1 | package in.knowledgegate; 2 | 3 | import in.kgcoding.Car; 4 | 5 | public class DefaultTest { 6 | public static void main(String[] args) { 7 | Car car = new Car("Yellow", "Dezire", 8 | 5, 3000); 9 | //car.costOfPurchase = 8; 10 | // in.kgcoding.Default def; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/knowledgegate/GetterTest.java: -------------------------------------------------------------------------------- 1 | package in.knowledgegate; 2 | 3 | import in.gettersetter.Car; 4 | 5 | public class GetterTest { 6 | public static void main(String[] args) { 7 | Car car = new Car("Red", "Maurti", 8 | 3, 8000); 9 | car.setColor("Blue"); 10 | //System.out.printf("%s %s", car.getColor(), car.getModel()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Leacture Code/8 Encapsulation and Inheritance/Leacture/src/in/knowledgegate/Packages.java: -------------------------------------------------------------------------------- 1 | package in.knowledgegate; 2 | 3 | public class Packages { 4 | } 5 | -------------------------------------------------------------------------------- /Leacture Code/9 Abstraction and Polymorphism/Leacture/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Leacture Code/9 Abstraction and Polymorphism/Leacture/src/in/kgcoding/abstraction/Car.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.abstraction; 2 | 3 | public class Car extends Vehicle { 4 | private int noOfDoors; 5 | 6 | public Car() { 7 | super(4); 8 | } 9 | 10 | @Override 11 | public void getSetGo() { 12 | System.out.println("going to place.."); 13 | } 14 | 15 | @Override 16 | public void makeStartSound() { 17 | System.out.println("Vroommm....."); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Leacture Code/9 Abstraction and Polymorphism/Leacture/src/in/kgcoding/abstraction/TestAbstraction.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.abstraction; 2 | 3 | public class TestAbstraction { 4 | public static void main(String[] args) { 5 | //Vehicle veh = new Vehicle(2); 6 | Car car = new Car(); 7 | car.commute(); 8 | car.makeStartSound(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Leacture Code/9 Abstraction and Polymorphism/Leacture/src/in/kgcoding/abstraction/Transport.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.abstraction; 2 | 3 | public interface Transport { 4 | void getSetGo(); 5 | } 6 | -------------------------------------------------------------------------------- /Leacture Code/9 Abstraction and Polymorphism/Leacture/src/in/kgcoding/abstraction/Vehicle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.abstraction; 2 | 3 | public abstract class Vehicle implements Transport { 4 | private int noOfTires; 5 | 6 | public abstract void makeStartSound(); 7 | 8 | 9 | public Vehicle(int noOfTires) { 10 | this.noOfTires = noOfTires; 11 | } 12 | 13 | public int getNoOfTires() { 14 | return noOfTires; 15 | } 16 | 17 | public void setNoOfTires(int noOfTires) { 18 | this.noOfTires = noOfTires; 19 | } 20 | 21 | public void commute() { 22 | System.out.println("going....."); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Programming Challenge/.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Programming Challenge/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Programming Challenge/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Programming Challenge/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Programming Challenge/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Programming Challenge/Programming Challenge.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Programming Challenge/java-course.txt: -------------------------------------------------------------------------------- 1 | This is the best Java course. 2 | Please like this video. 3 | Please share this with your friends. 4 | And comment which course do you want next. -------------------------------------------------------------------------------- /Programming Challenge/src/1 Morning.java: -------------------------------------------------------------------------------- 1 | import java.lang.*; 2 | 3 | class Morning { 4 | public static void main(String[] args) { 5 | System.out.print("Good Morning"); 6 | } 7 | } -------------------------------------------------------------------------------- /Programming Challenge/src/10 Perimeter.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Perimeter { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Perimeter Calculator"); 7 | System.out.print("Please enter all 4 sides in cms: "); 8 | double a = input.nextDouble(); 9 | double b = input.nextDouble(); 10 | double c = input.nextDouble(); 11 | double d = input.nextDouble(); 12 | 13 | double perimeter = a + b + c + d; 14 | System.out.println("Perimeter of your rectangle is: " + perimeter + "cm"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Programming Challenge/src/11 TriangleArea.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class TriangleArea { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Area calculator\n"); 7 | System.out.print("Please enter your base in cms: "); 8 | double base = input.nextDouble(); 9 | System.out.print("Now, enter your perpendicular height in cms: "); 10 | double height = input.nextDouble(); 11 | 12 | double area = (base * height) / 2; 13 | 14 | System.out.println("The area of your triangle is: " + area + "cms2"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Programming Challenge/src/12 SimpleInterest.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class SimpleInterest { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Simple Interest Calculator\n"); 7 | System.out.print("Please enter your principle amount Rs"); 8 | int principle = input.nextInt(); 9 | System.out.print("Now, Tell me your rate of interest: "); 10 | float rate = input.nextFloat(); 11 | System.out.print("Now, tell me for how many years are you borrowing this money: "); 12 | float years = input.nextFloat(); 13 | 14 | float interest = (principle * rate * years) / 100; 15 | System.out.println("\n\n Your Simple interest is Rs:" + interest); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Programming Challenge/src/13 CompoundInterest.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class CompoundInterest { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Compound interest calculator\n"); 7 | System.out.print("Please enter your principle amount Rs"); 8 | int principle = input.nextInt(); 9 | System.out.print("Now, Tell me your rate of interest: "); 10 | float rate = input.nextFloat(); 11 | System.out.print("Now, tell me for how many years are you borrowing this money: "); 12 | float years = input.nextFloat(); 13 | 14 | double compInt = principle * Math.pow((1 + rate / 100), years); 15 | System.out.println("Your compound interest is Rs:" + compInt); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Programming Challenge/src/14 FahrenheitToCelsius.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class FahrenheitToCelsius { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Temperature converter"); 7 | System.out.print("Enter your temp in F: "); 8 | float fah = input.nextFloat(); 9 | float cel = (fah - 32) * 5.0f / 9.0f; 10 | System.out.println("Your temperature is: " + cel + "C"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Programming Challenge/src/15 PositiveNegativeZero.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class PositiveNegativeZero { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Number checker\n"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | 10 | if (num > 0) { 11 | System.out.println("Your number is positive"); 12 | } else if (num == 0) { 13 | System.out.println("Your number is zero"); 14 | } else { 15 | System.out.println("Your number is negative"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Programming Challenge/src/16 OddEven.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class OddEven { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Odd even calculator\n"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | 10 | if (num % 2 == 0) { 11 | System.out.println("Your number is an even number"); 12 | } else { 13 | System.out.println("Your number is a odd number."); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Programming Challenge/src/17 GreatestOfThree.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class GreatestOfThree { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to the World of Three\n"); 7 | System.out.print("Please enter your first number: "); 8 | int first = input.nextInt(); 9 | System.out.print("Now, enter your second number: "); 10 | int second = input.nextInt(); 11 | System.out.print("Finally, enter your third number: "); 12 | int third = input.nextInt(); 13 | 14 | if (first >= second && first >= third) { 15 | System.out.println(first + " is the greatest number"); 16 | } else if (second >= third) { 17 | System.out.println(second + " is the greatest number"); 18 | } else { 19 | System.out.println(third + " is the greatest number"); 20 | } 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/18 LeapYear.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class LeapYear { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to New Year Calculator\n"); 7 | System.out.print("Please enter the year that you want to check: "); 8 | int year = input.nextInt(); 9 | 10 | if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { 11 | System.out.println("Your year is a leap year"); 12 | } else { 13 | System.out.println("Your year is not a leap year"); 14 | } 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /Programming Challenge/src/19 Grading.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Grading { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Grade calculator\n"); 7 | System.out.print("Please enter your percentage: "); 8 | float percentage = input.nextFloat(); 9 | 10 | if (percentage >= 90) { 11 | System.out.println("Great, You have got A"); 12 | } else if (percentage >= 75) { 13 | System.out.println("Good, You have got B"); 14 | } else if (percentage >= 60) { 15 | System.out.println("You have got C, Work harder next time"); 16 | } else if (percentage >= 30) { 17 | System.out.println("You have got D, You seriously need to work harder"); 18 | } else { 19 | System.out.println("Sorry, You have failed the test and got a F"); 20 | } 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/2 Subscribe.java: -------------------------------------------------------------------------------- 1 | class Subscribe { 2 | public static void main(String[] args) { 3 | System.out.println("Subscribe"); 4 | } 5 | } -------------------------------------------------------------------------------- /Programming Challenge/src/20 AgeCalculator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class AgeCalculator { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to age calculator"); 7 | System.out.print("Please enter your age: "); 8 | int age = input.nextInt(); 9 | 10 | if (age >= 65) { 11 | System.out.println("You are a senior citizen"); 12 | } else if (age >= 20) { 13 | System.out.println("You are an adult"); 14 | } else if (age >= 13) { 15 | System.out.println("You are a teenager"); 16 | } else { 17 | System.out.println("You are a child"); 18 | } 19 | } 20 | } 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Programming Challenge/src/21 BitwiseAnd.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class BitwiseAnd { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Showcasing Bitwise And operator\n"); 7 | System.out.print("Please enter the first number: "); 8 | int first = input.nextInt(); 9 | System.out.print("Now, enter the other number: "); 10 | int second = input.nextInt(); 11 | 12 | int result = first & second; 13 | System.out.println("Result is: " + result); 14 | } 15 | } 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Programming Challenge/src/22 BitwiseOr.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class BitwiseOr { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Showcasing Bitwise Or operator\n"); 7 | System.out.print("Please enter the first number: "); 8 | int first = input.nextInt(); 9 | System.out.print("Now, enter the other number: "); 10 | int second = input.nextInt(); 11 | 12 | int result = first | second; 13 | System.out.println("Result is: " + result); 14 | } 15 | } 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Programming Challenge/src/23 BitwiseXor.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class BitwiseXor { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Showcasing Bitwise XOR operator\n"); 7 | System.out.print("Please enter the first number: "); 8 | int first = input.nextInt(); 9 | System.out.print("Now, enter the other number: "); 10 | int second = input.nextInt(); 11 | 12 | int result = first ^ second; 13 | System.out.println("Result is: " + result); 14 | } 15 | } 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Programming Challenge/src/24 BitwiseCompliment.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class BitwiseCompliment { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to showcase of Not/Compliment Operator\n"); 7 | System.out.print("Please enter your number"); 8 | int num = input.nextInt(); 9 | 10 | int result = ~num; 11 | System.out.println("Your result is: " + result); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Programming Challenge/src/25 LeftShift.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class LeftShift { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to showcase LeftShift Operator\n"); 7 | System.out.print("Please enter your number "); 8 | int num = input.nextInt(); 9 | 10 | int result = num << 4; 11 | System.out.println("Your result is: " + result); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Programming Challenge/src/26 RightShift.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class RightShift { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to showcase RightShift Operator\n"); 7 | System.out.print("Please enter your number "); 8 | int num = input.nextInt(); 9 | 10 | int result = num >> 1; 11 | System.out.println("Your result is: " + result); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Programming Challenge/src/27 OddEvenBitWise.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class OddEvenBitWise { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Odd/Even Calculator"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | 10 | if ((num & 1) == 1) { 11 | System.out.println("Your number is odd"); 12 | } else { 13 | System.out.println("Your number is even"); 14 | } 15 | } 16 | } 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Programming Challenge/src/28 MultiplicationTable.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class MultiplicationTable { 3 | public static void main(String[] args) { 4 | Scanner scanner = new Scanner(System.in); 5 | System.out.println("Welcome to Multiplication World\n"); 6 | System.out.print("Please enter your number: "); 7 | int num = scanner.nextInt(); 8 | printMultiplicationTable(num); 9 | } 10 | 11 | public static void printMultiplicationTable(int num) { 12 | int i = 1; 13 | while (i <= 10) { 14 | System.out.println(num + " X " + i + " = " + (num * i)); 15 | i++; 16 | } 17 | } 18 | } 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Programming Challenge/src/29 OddSum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class OddSum { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Odd Sum"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | int sum = oddSum(num); 10 | System.out.println("OddSum till " + num + " is: " + sum); 11 | } 12 | 13 | public static int oddSum(int num) { 14 | int sum = 0; 15 | int i = 1; 16 | while (i <= num) { 17 | sum += i; 18 | i += 2; 19 | } 20 | return sum; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Programming Challenge/src/3 Pattern.java: -------------------------------------------------------------------------------- 1 | class Pattern { 2 | public static void main(String[] args) { 3 | System.out.println("*"); 4 | System.out.println("* *"); 5 | System.out.println("* * *"); 6 | System.out.println("* * * *"); 7 | System.out.println("* * * * *"); 8 | 9 | System.out.println("* * * * *"); 10 | System.out.println("* * * *"); 11 | System.out.println("* * *"); 12 | System.out.println("* *"); 13 | System.out.println("*"); 14 | 15 | System.out.println(" *"); 16 | System.out.println(" * *"); 17 | System.out.println(" * * *"); 18 | System.out.println(" * * * *"); 19 | System.out.println("* * * * *"); 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /Programming Challenge/src/30 Factorial.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Factorial { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Factorial"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | long fact = factorial(num); 10 | System.out.println("Factorial is: " + fact); 11 | } 12 | 13 | public static long factorial(int num) { 14 | if (num < 2) { 15 | return 1; 16 | } 17 | long fact = 1; 18 | int i = 2; 19 | while (i <= num) { 20 | fact *= i; 21 | i++; 22 | } 23 | return fact; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Programming Challenge/src/31 SumOfDigits.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class SumOfDigits { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Sum Of Digits"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | int sum = sumOfDigits(num); 10 | System.out.println("Sum of Digits is: " + sum); 11 | } 12 | 13 | public static int sumOfDigits(int num) { 14 | int sum = 0; 15 | while (num > 0) { 16 | sum += num % 10; 17 | num /= 10; 18 | } 19 | return sum; 20 | } 21 | } 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Programming Challenge/src/32 LCM.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class LCM { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to LCM"); 7 | System.out.print("Please enter your number: "); 8 | int first = input.nextInt(); 9 | System.out.print("Please enter your number: "); 10 | int second = input.nextInt(); 11 | int lcm = lcm(first, second); 12 | System.out.println("LCM of the two numbers is: " + lcm); 13 | } 14 | 15 | public static int lcm(int first, int second) { 16 | int i = 1; 17 | while (true) { 18 | int factor = first * i; 19 | if (factor % second == 0) { 20 | return factor; 21 | } 22 | i++; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Programming Challenge/src/33 GCD.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class GCD { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to GCD"); 7 | System.out.print("Please enter your number: "); 8 | int first = input.nextInt(); 9 | System.out.print("Please enter your number: "); 10 | int second = input.nextInt(); 11 | int gcd = gcd(first, second); 12 | System.out.println("GCD of the numbers is: " + gcd); 13 | } 14 | 15 | public static int gcd(int num1, int num2) { 16 | int gcd = 1; 17 | int i = 2; 18 | int least = least(num1, num2); 19 | while (i <= least) { 20 | if (num1 % i == 0 && num2 % i == 0) { 21 | gcd = i; 22 | } 23 | i++; 24 | } 25 | return gcd; 26 | } 27 | 28 | public static int least(int num1, int num2) { 29 | if (num1 < num2) { 30 | return num1; 31 | } else { 32 | return num2; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Programming Challenge/src/34 Prime.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Prime { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Prime Number checker"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | boolean isPrime = isPrime(num); 10 | if (isPrime) { 11 | System.out.println("Your number is Prime"); 12 | } else { 13 | System.out.println("Your number is not prime"); 14 | } 15 | } 16 | 17 | public static boolean isPrime(int num) { 18 | int i = 2; 19 | while (i < num) { 20 | if (num % i == 0) { 21 | return false; 22 | } 23 | i++; 24 | } 25 | return true; 26 | } 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /Programming Challenge/src/35 ReverseTheDigits.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class ReverseTheDigits { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Reverse the digits"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | int reverse = reverse(num); 10 | System.out.println("Reverse of your number is " + reverse); 11 | } 12 | 13 | public static int reverse(int num) { 14 | int newNum = 0; 15 | while (num > 0) { 16 | int digit = num % 10; 17 | newNum = newNum * 10 + digit; 18 | num /= 10; 19 | } 20 | return newNum; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Programming Challenge/src/36 Fibonacci.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Fibonacci { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Fibonacci Series"); 7 | System.out.print("Please enter the number up to which series has to be printed: "); 8 | int num = input.nextInt(); 9 | System.out.println("Here is the Fibonacci Series"); 10 | printFibonacci(num); 11 | } 12 | 13 | public static void printFibonacci(int num) { 14 | if (num < 0) return; 15 | System.out.print("0 "); 16 | if (num == 0) return; 17 | System.out.print("1 "); 18 | 19 | int first = 0, second = 1; 20 | while (first + second <= num) { 21 | int third = first + second; 22 | System.out.print(third + " "); 23 | first = second; 24 | second = third; 25 | } 26 | } 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Programming Challenge/src/37 ArmstrongNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class ArmstrongNumber { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Armstrong Number"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | boolean isArmstrong = isArmstrong(num); 10 | if (isArmstrong) { 11 | System.out.println("Your number is Armstrong"); 12 | } else { 13 | System.out.println("Your number is not Armstrong"); 14 | } 15 | } 16 | 17 | public static boolean isArmstrong(int num) { 18 | int noOfDigits = noOfDigits(num); 19 | int numCopy = num; 20 | int finalNumber = 0; 21 | while (num > 0) { 22 | int lastDigit = num % 10; 23 | num /= 10; 24 | finalNumber += pow(lastDigit, noOfDigits); 25 | } 26 | return finalNumber == numCopy; 27 | } 28 | 29 | public static int pow(int num1, int num2) { 30 | int result = 1; 31 | int i = 0; 32 | while (i < num2) { 33 | result *= num1; 34 | i++; 35 | } 36 | return result; 37 | } 38 | 39 | public static int noOfDigits(int num) { 40 | int digits = 0; 41 | while (num > 0) { 42 | digits++; 43 | num /= 10; 44 | } 45 | return digits; 46 | } 47 | } 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Programming Challenge/src/38 PalindromeNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class PalindromeNumber { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Palindrome Number"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | boolean isPalindrome = isPalindrome(num); 10 | if (isPalindrome) { 11 | System.out.println("Your number is a palindrome number"); 12 | } else { 13 | System.out.println("Your number is not a palindrome number"); 14 | } 15 | } 16 | 17 | public static boolean isPalindrome(int num) { 18 | return num == reverse(num); 19 | } 20 | 21 | public static int reverse(int num) { 22 | int newNum = 0; 23 | while (num > 0) { 24 | int digit = num % 10; 25 | newNum = newNum * 10 + digit; 26 | num /= 10; 27 | } 28 | return newNum; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Programming Challenge/src/4 SingleLine.java: -------------------------------------------------------------------------------- 1 | class SingleLine { 2 | public static void main(String[] args) { 3 | System.out.println("*\n* *\n* * *\n* * * *\n* * * * *"); 4 | System.out.println("\n\n* * * * *\n* * * *\n* * *\n* *\n*"); 5 | System.out.println("\n\n *\n * *\n * * *\n * * * *\n* * * * *"); 6 | } 7 | } -------------------------------------------------------------------------------- /Programming Challenge/src/40 ArraySumAverage.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class ArraySumAverage { 4 | public static void main(String[] args) { 5 | System.out.println("Welcome to Array sum and Average"); 6 | int[] numArray = ArrayUtility.inputArray(); 7 | long sum = sum(numArray); 8 | double avg = average(numArray); 9 | System.out.println("Sum of the numbers is: " + sum); 10 | System.out.println("Average of the numbers is: " + avg); 11 | } 12 | 13 | public static long sum(int[] numArray) { 14 | long sum = 0; 15 | int i = 0; 16 | while (i < numArray.length) { 17 | sum += numArray[i]; 18 | i++; 19 | } 20 | return sum; 21 | } 22 | 23 | public static double average(int[] numArray) { 24 | double sum = sum(numArray); 25 | return (sum / numArray.length); 26 | } 27 | } 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Programming Challenge/src/41 OccurrencesArray.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class OccurrencesArray { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Array Occurrences\n"); 7 | int[] numArr = ArrayUtility.inputArray(); 8 | System.out.print("Now enter the number you want to find: "); 9 | int num = input.nextInt(); 10 | int occurrences = noOfOccurrences(numArr, num); 11 | System.out.println("Your element was found " + occurrences + " times in the array"); 12 | } 13 | 14 | public static int noOfOccurrences(int[] numArr, int num) { 15 | int occ = 0; 16 | int i = 0; 17 | while (i < numArr.length) { 18 | if (numArr[i] == num) { 19 | occ++; 20 | } 21 | i++; 22 | } 23 | return occ; 24 | } 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Programming Challenge/src/42 MaxMinArray.java: -------------------------------------------------------------------------------- 1 | class MaxMinArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to Max and Min\n"); 4 | int[] numArr = ArrayUtility.inputArray(); 5 | int max = max(numArr); 6 | int min = min(numArr); 7 | System.out.println("Max of the Array is: " + max); 8 | System.out.println("Min of the Array is: " + min); 9 | } 10 | 11 | public static int min(int[] numArr) { 12 | int min = Integer.MAX_VALUE; 13 | int i = 0; 14 | while (i < numArr.length) { 15 | if (min > numArr[i]) { 16 | min = numArr[i]; 17 | } 18 | i++; 19 | } 20 | return min; 21 | } 22 | public static int max(int[] numArr) { 23 | if (numArr.length == 0) { 24 | return Integer.MIN_VALUE; 25 | } 26 | int max = numArr[0]; 27 | int i = 1; 28 | while (i < numArr.length) { 29 | if (max < numArr[i]) { 30 | max = numArr[i]; 31 | } 32 | i++; 33 | } 34 | return max; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Programming Challenge/src/43 IsSortedArray.java: -------------------------------------------------------------------------------- 1 | class IsSortedArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to Array Sorting Check post\n"); 4 | int[] numArr = ArrayUtility.inputArray(); 5 | boolean isInc = isIncreasing(numArr); 6 | boolean isDec = isDecreasing(numArr); 7 | if (isInc || isDec) { 8 | System.out.println("Your array is sorted"); 9 | } else { 10 | System.out.println("Your array is not sorted"); 11 | } 12 | } 13 | 14 | public static boolean isDecreasing(int[] numArr) { 15 | int i = 1; 16 | while (i < numArr.length) { 17 | if (numArr[i] > numArr[i-1]) { 18 | return false; 19 | } 20 | i++; 21 | } 22 | return true; 23 | } 24 | public static boolean isIncreasing(int[] numArr) { 25 | int i = 1; 26 | while (i < numArr.length) { 27 | if (numArr[i] < numArr[i-1]) { 28 | return false; 29 | } 30 | i++; 31 | } 32 | return true; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Programming Challenge/src/44 DeleteFromArray.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class DeleteFromArray { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Array Deletion\n"); 7 | int[] numArr = ArrayUtility.inputArray(); 8 | System.out.print("Now, enter then number you want to delete: "); 9 | int numToDelete = input.nextInt(); 10 | int[] newArr = deleteNumber(numArr, numToDelete); 11 | System.out.println("Here is your new array"); 12 | ArrayUtility.displayArray(newArr); 13 | } 14 | 15 | public static int[] deleteNumber(int[] numArr, int numToDelete) { 16 | int occ = OccurrencesArray.noOfOccurrences(numArr, numToDelete); 17 | if (occ == 0) { 18 | return numArr; 19 | } 20 | int newSize = numArr.length - occ; 21 | int[] newArr = new int[newSize]; 22 | 23 | int i = 0, j = 0; 24 | while (i < numArr.length) { 25 | if (numArr[i] != numToDelete) { 26 | newArr[j] = numArr[i]; 27 | j++; 28 | } 29 | i++; 30 | } 31 | 32 | return newArr; 33 | } 34 | } 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Programming Challenge/src/45 ReverseArray.java: -------------------------------------------------------------------------------- 1 | class ReverseArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to Array Reversal\n"); 4 | int[] numArr = ArrayUtility.inputArray(); 5 | reverse(numArr); 6 | System.out.println("Your reversed array is"); 7 | ArrayUtility.displayArray(numArr); 8 | } 9 | 10 | public static void reverse(int[] arr) { 11 | int i = 0; 12 | while (i < arr.length / 2) { 13 | int swap = arr[i]; 14 | arr[i] = arr[(arr.length - 1) - i]; 15 | arr[(arr.length - 1) - i] = swap; 16 | i++; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Programming Challenge/src/46 PalindromeArray.java: -------------------------------------------------------------------------------- 1 | class PalindromeArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to Palindrome Checker\n"); 4 | int[] numArr = ArrayUtility.inputArray(); 5 | boolean isPalin = isPalindrome(numArr); 6 | if (isPalin) { 7 | System.out.println("Your array is Palindrome"); 8 | } else { 9 | System.out.println("Your array is not Palindrome"); 10 | } 11 | } 12 | 13 | public static boolean isPalindrome(int[] numArr) { 14 | int i = 0; 15 | while (i < numArr.length / 2) { 16 | if (numArr[i] != numArr[numArr.length - 1 - i]) { 17 | return false; 18 | } 19 | i++; 20 | } 21 | return true; 22 | } 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /Programming Challenge/src/47 MergeTwoSortedArray.java: -------------------------------------------------------------------------------- 1 | class MergeTwoSortedArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to Merging Sorted Arrays\n"); 4 | int[] arr1 = ArrayUtility.inputArray(); 5 | int[] arr2 = ArrayUtility.inputArray(); 6 | int[] mergedArr = merge(arr1, arr2); 7 | System.out.println("Your merged array is:"); 8 | ArrayUtility.displayArray(mergedArr); 9 | } 10 | 11 | public static int[] merge(int[] arr1, int[] arr2) { 12 | int newSize = arr1.length + arr2.length; 13 | int[] newArr = new int[newSize]; 14 | int i = 0, j = 0, k = 0; 15 | while (i < arr1.length || j < arr2.length) { 16 | if (j == arr2.length || 17 | (i < arr1.length && arr1[i] < arr2[j])) { 18 | newArr[k] = arr1[i]; 19 | i++; 20 | k++; 21 | } else { 22 | newArr[k] = arr2[j]; 23 | k++; 24 | j++; 25 | } 26 | } 27 | return newArr; 28 | } 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Programming Challenge/src/48 Search2DArray.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Search2DArray { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to 2D Search\n"); 7 | int[][] numArr = ArrayUtility.input2DArray(); 8 | System.out.print("Now enter the number you want to search: "); 9 | int num = input.nextInt(); 10 | boolean isFound = search(numArr, num); 11 | if (isFound) { 12 | System.out.println("Your number was found."); 13 | } else { 14 | System.out.println("Your number was not found."); 15 | } 16 | } 17 | 18 | public static boolean search(int[][] numArr, int num) { 19 | int i = 0; 20 | while (i < numArr.length) { 21 | int j = 0; 22 | while (j < numArr[i].length) { 23 | if (numArr[i][j] == num) { 24 | return true; 25 | } 26 | j++; 27 | } 28 | i++; 29 | } 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Programming Challenge/src/49 SumAverage2dArray.java: -------------------------------------------------------------------------------- 1 | class SumAverage2dArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to Sum and Average of 2D Array\n"); 4 | int[][] numArr = ArrayUtility.input2DArray(); 5 | long sum =sum(numArr); 6 | double avg = average(numArr); 7 | System.out.println("Your sum of array is: " + sum); 8 | System.out.println("Your average of array is: " + avg); 9 | } 10 | 11 | public static double average(int[][] numArr) { 12 | if (numArr.length == 0) { 13 | return 0; 14 | } 15 | int rows = numArr.length; 16 | int cols = numArr[0].length; 17 | double size = rows * cols; 18 | return sum(numArr) / size; 19 | } 20 | 21 | public static long sum(int[][] numArr) { 22 | long sum = 0; 23 | int i = 0; 24 | while (i < numArr.length) { 25 | int j = 0; 26 | while (j < numArr[i].length) { 27 | sum += numArr[i][j]; 28 | j++; 29 | } 30 | i++; 31 | } 32 | return sum; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Programming Challenge/src/5 Welcome.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Welcome { 4 | public static void main(String[] args) { 5 | System.out.print("Please enter your name: "); 6 | Scanner input = new Scanner(System.in); 7 | String name = input.nextLine(); 8 | System.out.println("Welcome " + name + " to KG Coding"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Programming Challenge/src/50 DiagonalSum2DArray.java: -------------------------------------------------------------------------------- 1 | class DiagonalSum2DArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to Diagonal Sum"); 4 | int[][] numArr = ArrayUtility.input2DArray(); 5 | long sum = sumOfDiagonals(numArr); 6 | System.out.println("Sum of diagonals is: " + sum); 7 | } 8 | 9 | public static long sumOfDiagonals(int[][] numArr) { 10 | long leftSum = sumOfLeftDiagonal(numArr); 11 | long rightSum = sumOfRightDiagonal(numArr); 12 | long sum = leftSum + rightSum; 13 | if (numArr.length % 2 != 0) { 14 | int ind = numArr.length / 2; 15 | sum -= numArr[ind][ind]; 16 | } 17 | return sum; 18 | } 19 | 20 | public static long sumOfLeftDiagonal(int[][] numArr) { 21 | long sum = 0; 22 | int i = 0; 23 | while (i < numArr.length) { 24 | sum += numArr[i][i]; 25 | i++; 26 | } 27 | return sum; 28 | } 29 | 30 | public static long sumOfRightDiagonal(int[][] numArr) { 31 | long sum = 0; 32 | int i = 0; 33 | while (i < numArr.length) { 34 | int col = numArr.length - 1 - i; 35 | sum += numArr[i][col]; 36 | i++; 37 | } 38 | return sum; 39 | } 40 | } 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Programming Challenge/src/52 Course.java: -------------------------------------------------------------------------------- 1 | class Course { 2 | static int maxCapacity = 100; 3 | String courseName; 4 | int enrollments; 5 | 6 | String[] enrolledStudents; 7 | 8 | Course(String courseName) { 9 | this.courseName = courseName; 10 | this.enrollments = 0; 11 | this.enrolledStudents = new String[maxCapacity]; 12 | } 13 | 14 | static void setMaxCapacity(int maxCapacity) { 15 | Course.maxCapacity = maxCapacity; 16 | } 17 | 18 | void enrollStudent(String studentName) { 19 | enrolledStudents[enrollments] = studentName; 20 | enrollments++; 21 | } 22 | 23 | void unenrollStudent(String studentName) { 24 | System.out.println("Student removed"); 25 | enrollments--; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Programming Challenge/src/53 MinimumTernary.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class MinimumTernary { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to finding minimum\n"); 7 | System.out.print("Please enter your first number: "); 8 | int num1 = input.nextInt(); 9 | System.out.print("Now, Please enter your second number: "); 10 | int num2 = input.nextInt(); 11 | MinimumTernary ternary = new MinimumTernary(); 12 | int min = ternary.min(num1, num2); 13 | System.out.println("Minimum number is: " + min); 14 | } 15 | 16 | public int min(int num1, int num2) { 17 | return num1 < num2 ? num1 : num2; 18 | // if (num1 < num2) { 19 | // return num1; 20 | // } else { 21 | // return num2; 22 | // } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/54 OddEvenTernary.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class OddEvenTernary { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Odd or even\n"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | String result = num % 2 == 0 ? "Even" : "Odd"; 10 | System.out.println("Your number is: " + result); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Programming Challenge/src/55 AbsoluteTernary.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class AbsoluteTernary { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Absolute Value\n"); 7 | System.out.print("Please enter your number: "); 8 | int num = input.nextInt(); 9 | int result = num >= 0 ? num : -num; 10 | System.out.println("Absolute value is: " + result); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Programming Challenge/src/56 StudentScoreTernary.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class StudentScoreTernary { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Student Score\n"); 7 | System.out.print("Please enter your marks: "); 8 | int marks = input.nextInt(); 9 | 10 | String category = marks > 80 ? "High" : (marks > 50 ? "Moderate" : "Low"); 11 | System.out.println("Your category is: " + category); 12 | } 13 | } 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Programming Challenge/src/57 MonthSwitch.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class MonthSwitch { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Month mapping\n"); 7 | System.out.print("Please enter your month number: "); 8 | int monthNum = input.nextInt(); 9 | String monthName = getMonthName(monthNum); 10 | System.out.println("Your month name is: " + monthName); 11 | } 12 | 13 | public static String getMonthName(int monthNum) { 14 | return switch (monthNum) { 15 | case 1 -> "January"; 16 | case 2 -> "February"; 17 | case 3 -> "March"; 18 | case 4 -> "April"; 19 | case 5 -> "May"; 20 | case 6 -> "June"; 21 | case 7 -> "July"; 22 | case 8 -> "August"; 23 | case 9 -> "September"; 24 | case 10 -> "October"; 25 | case 11 -> "November"; 26 | case 12 -> "December"; 27 | default -> "Mars Month"; 28 | }; 29 | } 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Programming Challenge/src/58 CalculatorSwitch.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class CalculatorSwitch { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to calculator\n"); 7 | System.out.print("Please enter your first number: "); 8 | int num1 = input.nextInt(); 9 | System.out.print("Now, enter the second number: "); 10 | int num2 = input.nextInt(); 11 | System.out.print("Now, enter the operation: "); 12 | String operation = input.next(); 13 | 14 | int result = switch (operation) { 15 | case "+" -> num1 + num2; 16 | case "-" -> num1 - num2; 17 | case "*" -> num1 * num2; 18 | case "/" -> num1 / num2; 19 | default -> -1; 20 | }; 21 | 22 | System.out.println("Your answer is: " + result); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/59 PasswordChecker.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class PasswordChecker { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Set your password\n"); 7 | String password; 8 | do { 9 | System.out.print("Please enter your password: "); 10 | password = input.next(); 11 | } while (!isValidPassword(password)); 12 | System.out.println("Thanks for entering a valid password"); 13 | } 14 | 15 | public static boolean isValidPassword(String password) { 16 | return password.length() > 6; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Programming Challenge/src/6 Sum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Sum { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to our Calculator"); 7 | System.out.print("Please enter first number: "); 8 | int firstNum = input.nextInt(); 9 | System.out.print("Now, please enter the second number: "); 10 | int secondNum = input.nextInt(); 11 | int sum = firstNum + secondNum; 12 | System.out.println("Sum of your numbers is: " + sum); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Programming Challenge/src/60 NumberGuessingGame.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class NumberGuessingGame { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | int num = 5, guess; 7 | System.out.println("Welcome to the number guessing game"); 8 | do { 9 | System.out.print("Please guess the number between 0 and 10: "); 10 | guess = input.nextInt(); 11 | } while (num != guess); 12 | System.out.println("You have successfully guessed the number"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Programming Challenge/src/61 MultiplicationTableFor.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class MultiplicationTableFor { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to printing tables\n"); 7 | System.out.print("Please enter the number you want to print table of: "); 8 | int num = input.nextInt(); 9 | 10 | for (int i = 1; i <= 10; i++) { 11 | System.out.println(num + " X " + i + " = " + (num * i)); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Programming Challenge/src/62 PrimeFor.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class PrimeFor { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to prime number checker"); 7 | System.out.print("Please enter the number: "); 8 | int num = input.nextInt(); 9 | System.out.println("Your number is " + 10 | (isPrime(num) ? "Prime" : "Not Prime")); 11 | } 12 | 13 | public static boolean isPrime(int num) { 14 | for (int i = 2; i < num; i++) { 15 | if (num % i == 0) { 16 | return false; 17 | } 18 | } 19 | return true; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Programming Challenge/src/63 MaxArray.java: -------------------------------------------------------------------------------- 1 | class MaxArray { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to finding the maximum\n"); 4 | int[] arr = ArrayUtility.inputArray(); 5 | 6 | int max = Integer.MIN_VALUE; 7 | for (int num: arr) { 8 | if (max < num) { 9 | max = num; 10 | } 11 | } 12 | 13 | System.out.println("Maximum number is: " + max); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Programming Challenge/src/64 OccurrencesForEach.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class OccurrencesForEach { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to finding occurrences"); 7 | int[] nums = ArrayUtility.inputArray(); 8 | System.out.print("Now, enter the number you want to search: "); 9 | int element = input.nextInt(); 10 | int occ = countOccurrences(nums, element); 11 | System.out.println("Your element was found: " + occ + " times."); 12 | } 13 | 14 | public static int countOccurrences(int[] nums, int element) { 15 | int occ = 0; 16 | for (int num : nums) { 17 | if (num == element) { 18 | occ++; 19 | } 20 | } 21 | return occ; 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Programming Challenge/src/65 ExitOnExit.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class ExitOnExit { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | while (true) { 7 | System.out.print("Enter your command: "); 8 | String command = input.next(); 9 | if (command.equalsIgnoreCase("exit")) { 10 | break; 11 | } 12 | } 13 | System.out.println("You have successfully exited."); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Programming Challenge/src/66 SumPositive.java: -------------------------------------------------------------------------------- 1 | class SumPositive { 2 | public static void main(String[] args) { 3 | System.out.println("Welcome to adding positive numbers."); 4 | int[] numArr = ArrayUtility.inputArray(); 5 | 6 | int sum = 0; 7 | for (int num : numArr) { 8 | if (num < 0) { 9 | continue; 10 | } 11 | sum += num; 12 | } 13 | System.out.println("The sum of positive numbers is: " + sum); 14 | } 15 | } 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Programming Challenge/src/67 PrintEven.java: -------------------------------------------------------------------------------- 1 | class PrintEven { 2 | public static void main(String[] args) { 3 | for (int i = 1; i <= 100; i++) { 4 | if (i % 2 == 1) { 5 | continue; 6 | } 7 | System.out.println(i); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Programming Challenge/src/68 FibonacciRecursion.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class FibonacciRecursion { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to printing Fibonacci Series"); 7 | System.out.print("Enter the number of elements to be printed: "); 8 | int count = input.nextInt(); 9 | for (int i = 1; i <= count; i++) { 10 | System.out.println(fibonacci(i) + " "); 11 | } 12 | } 13 | 14 | public static int fibonacci(int position) { 15 | System.out.print("."); 16 | if (position == 1) { 17 | return 0; 18 | } 19 | if (position == 2) { 20 | return 1; 21 | } 22 | return fibonacci(position - 1) 23 | + fibonacci(position - 2); 24 | } 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Programming Challenge/src/69 PalindromeRecursion.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class PalindromeRecursion { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Palindrome Checker"); 7 | System.out.print("Enter the string to be checked: "); 8 | String str = input.next(); 9 | System.out.println("Your string is " 10 | + ((isPalindrome(str) ? "Palindrome" 11 | : "Not Palindrome"))); 12 | } 13 | 14 | public static boolean isPalindrome(String str) { 15 | if (str.length() <= 1) { 16 | return true; 17 | } 18 | int lastPos = str.length() - 1; 19 | if (str.charAt(0) != str.charAt(lastPos)) { 20 | return false; 21 | } 22 | String newStr = str.substring(1, lastPos); 23 | return isPalindrome(newStr); 24 | } 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Programming Challenge/src/7 Swap.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Swap { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Swapping station\n\n"); 7 | System.out.print("Enter value of A: "); 8 | int a = input.nextInt(); 9 | System.out.print("Enter value of B: "); 10 | int b = input.nextInt(); 11 | 12 | int c = a; 13 | a = b; 14 | b = c; 15 | 16 | System.out.println("Swapping done..."); 17 | System.out.println("Value of A is:" + a); 18 | System.out.println("Value of B is:" + b); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Programming Challenge/src/70 StudentToString.java: -------------------------------------------------------------------------------- 1 | class StudentToString { 2 | String name; 3 | int age; 4 | String rollNumber; 5 | String house; 6 | 7 | public StudentToString(String name, int age, String rollNumber, String house) { 8 | this.name = name; 9 | this.age = age; 10 | this.rollNumber = rollNumber; 11 | this.house = house; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return "Student Details:{name:" + name 17 | + ", age:" + age 18 | + ", roll number:" + rollNumber 19 | + ", house:" + house + " }"; 20 | } 21 | 22 | public static void main(String[] args) { 23 | StudentToString stu = new StudentToString("Prashant", 24 | 30, "001", "Shivaji"); 25 | System.out.println(stu); 26 | } 27 | } 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Programming Challenge/src/71 StringManipulation.java: -------------------------------------------------------------------------------- 1 | class StringManipulation { 2 | public static void main(String[] args) { 3 | String firstName = "Prashant"; 4 | String lasName = "Jain"; 5 | String fullName = firstName.concat( " ").concat(lasName); 6 | System.out.println(fullName.toUpperCase()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Programming Challenge/src/72 Circle.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Circle { 4 | double radiusInMm; 5 | 6 | Circle(double radiusInMm) { 7 | this.radiusInMm = radiusInMm; 8 | } 9 | 10 | double getCircumference() { 11 | return 2 * radiusInMm * Math.PI; 12 | } 13 | 14 | double getArea() { 15 | return Math.PI * Math.pow(radiusInMm, 2); 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "Circle Props: Radius in mm: " + radiusInMm 21 | + " , Circumference in mm: " + getCircumference() 22 | + ", Area in mm2: " + getArea(); 23 | } 24 | 25 | public static void main(String[] args) { 26 | Scanner input = new Scanner(System.in); 27 | System.out.println("Welcome to the world of Circle\n"); 28 | System.out.print("Please enter your radius: "); 29 | double radius = input.nextDouble(); 30 | Circle circle = new Circle(radius); 31 | System.out.println(circle); 32 | } 33 | } 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Programming Challenge/src/73 DiceRoll.java: -------------------------------------------------------------------------------- 1 | class Dice { 2 | 3 | int roll() { 4 | double random = Math.random() * 6; 5 | return (int) Math.ceil(random); 6 | } 7 | 8 | public static void main(String[] args) { 9 | Dice dice = new Dice(); 10 | for (int i = 0; i < 100; i++) { 11 | System.out.println(dice.roll()); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Programming Challenge/src/74 GuessingGame.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class GuessingGame { 4 | 5 | int random; 6 | GuessingGame() { 7 | random = (int) Math.ceil(Math.random() * 100); 8 | } 9 | 10 | /** 11 | * @param guessNumber the number that player guessed 12 | * @return 13 | * - Negative if the guessed number is smaller 14 | * - 0 if the guessed number is correct. 15 | * - Positive if the guessed number is higher. 16 | */ 17 | int guess(int guessNumber) { 18 | return guessNumber - random; 19 | } 20 | 21 | public static void main(String[] args) { 22 | Scanner input = new Scanner(System.in); 23 | GuessingGame game = new GuessingGame(); 24 | System.out.println("Welcome to the guessing game. Guess the number between 1-100"); 25 | int guess; 26 | int result; 27 | do { 28 | System.out.print("Guess the number: "); 29 | guess = input.nextInt(); 30 | result = game.guess(guess); 31 | if (result == 0) { 32 | System.out.println("Congrats, your guess is correct"); 33 | } else if (result < 0) { 34 | System.out.println("Please Guess Higher"); 35 | } else { 36 | System.out.println("Please Guess Lower"); 37 | } 38 | } while (result != 0); 39 | } 40 | } 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Programming Challenge/src/75 ArrayToString.java: -------------------------------------------------------------------------------- 1 | class ArrayToString { 2 | public static void main(String[] args) { 3 | String[] arr = new String[] {"This", 4 | "is", "the", "best", "and", "most", 5 | "detailed", "course", "on", "java", "on", 6 | "the", "internet"}; 7 | StringBuilder sb = new StringBuilder(); 8 | for (String str : arr) { 9 | sb.append(str).append(" "); 10 | } 11 | System.out.println(sb); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Programming Challenge/src/76 CarFinal.java: -------------------------------------------------------------------------------- 1 | class CarFinal { 2 | final int noOfWheels; 3 | final String model; 4 | final String engineInLiters; 5 | 6 | public CarFinal(int noOfWheels, String model, String engineInLiters) { 7 | this.noOfWheels = noOfWheels; 8 | this.model = model; 9 | this.engineInLiters = engineInLiters; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Programming Challenge/src/8 Arithmetic.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Arithmetic { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("Welcome to Arithmetic calculator\n"); 7 | System.out.print("Please enter first number: "); 8 | int first = input.nextInt(); 9 | System.out.print("Now, please enter second number: "); 10 | int second = input.nextInt(); 11 | 12 | int add = first + second; 13 | int sub = first - second; 14 | int mul = first * second; 15 | int div = first / second; 16 | int mod = first % second; 17 | 18 | System.out.println("Addition is: " + add); 19 | System.out.println("Subtraction is: " + sub); 20 | System.out.println("Multiplication is: " + mul); 21 | System.out.println("Division is: " + div); 22 | System.out.println("Modulus is: " + mod); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/89 VarArgs.java: -------------------------------------------------------------------------------- 1 | class VarArgs { 2 | 3 | public static void main(String[] args) { 4 | System.out.println(concatenate("Prashant")); 5 | 6 | System.out.println(concatenate("Prashant", "Jain")); 7 | 8 | System.out.println(concatenate("Subscribe", "to", "KgCoding")); 9 | } 10 | public static String concatenate(String... strs) { 11 | StringBuilder sb = new StringBuilder(); 12 | for (String str : strs) { 13 | sb.append(str).append(" "); 14 | } 15 | return sb.toString(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Programming Challenge/src/9 FloatMultiplication.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class FloatMultiplication { 4 | public static void main(String[] args) { 5 | Scanner input = new Scanner(System.in); 6 | System.out.println("We are doing Float Multiplication\n"); 7 | System.out.print("Please enter first decimal number: "); 8 | double first = input.nextDouble(); 9 | System.out.print("Now, please enter second number: "); 10 | double second = input.nextDouble(); 11 | 12 | System.out.println("\n Result is: " + (first * second)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Programming Challenge/src/90 Comparator.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Collections; 3 | import java.util.List; 4 | 5 | class Comparator { 6 | public static void main(String[] args) { 7 | List list = Arrays.asList("Bear", "Zebra", "Lion", "Ant"); 8 | System.out.println(list); 9 | sortInDescending(list); 10 | System.out.println(list); 11 | } 12 | 13 | public static void sortInDescending(List stringList) { 14 | Collections.sort(stringList, new java.util.Comparator() { 15 | @Override 16 | public int compare(String s, String t1) { 17 | if (s.equals(t1)) { 18 | return 0; 19 | } else if (s.charAt(0) < t1.charAt(0)) { 20 | return 1; 21 | } else { 22 | return -1; 23 | } 24 | } 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Programming Challenge/src/91 Frequency.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Collections; 3 | import java.util.List; 4 | 5 | class Frequency { 6 | public static void main(String[] args) { 7 | List list = Arrays.asList(1,4,8,6,4,1,7,8,1); 8 | System.out.println(Collections.frequency(list, 1)); 9 | System.out.println(Collections.frequency(list, 7)); 10 | System.out.println(Collections.frequency(list, 8)); 11 | } 12 | } 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Programming Challenge/src/92 ListSwapping.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | 4 | class ListSwapping { 5 | public static void main(String[] args) { 6 | List list = Arrays.asList(1,2,3,4,5,6,7,8); 7 | System.out.println(list); 8 | swap(list, 2, 7); 9 | System.out.println(list); 10 | } 11 | 12 | public static void swap(List list, int x, int y) { 13 | int swap = list.get(x); 14 | list.set(x, list.get(y)); 15 | list.set(y, swap); 16 | } 17 | } 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Programming Challenge/src/93 ListReverse.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Collections; 3 | import java.util.List; 4 | 5 | class ListReverse { 6 | public static void main(String[] args) { 7 | List list = Arrays.asList(1,2,3,4,5,6,76); 8 | System.out.println(list); 9 | reverse(list); 10 | System.out.println(list); 11 | } 12 | 13 | public static void reverse(List list) { 14 | //Collections.reverse(list); 15 | 16 | for (int i = 0; i < list.size() / 2; i++) { 17 | ListSwapping.swap(list, i, list.size() - 1 - i); 18 | } 19 | } 20 | } 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Programming Challenge/src/95 UniqueCharacters.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | import java.util.Scanner; 3 | import java.util.Set; 4 | 5 | class UniqueCharacters { 6 | public static void main(String[] args) { 7 | Set unique = new HashSet<>(); 8 | Scanner input = new Scanner(System.in); 9 | System.out.print("Please enter your string: "); 10 | String userStr = input.next(); 11 | 12 | for (char ch : userStr.toCharArray()) { 13 | unique.add(ch); 14 | } 15 | 16 | System.out.printf("Your string has %d unique characters", 17 | unique.size()); 18 | } 19 | } 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/98 CountryMap.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | import java.util.Scanner; 4 | 5 | class CountryMap { 6 | public static void main(String[] args) { 7 | Map countryMap = new HashMap<>(); 8 | countryMap.put("Bharat", "New Delhi"); 9 | countryMap.put("China", "Beijing"); 10 | countryMap.put("Pakistan", "Islamabad"); 11 | countryMap.put("SriLanka", "Columbo"); 12 | countryMap.put("Bangladesh", "Dhaka"); 13 | 14 | Scanner input = new Scanner(System.in); 15 | System.out.print("Please enter the country name: "); 16 | String country = input.next(); 17 | if (countryMap.containsKey(country)) { 18 | System.out.printf("Capital of %s is %s", country, 19 | countryMap.get(country)); 20 | } else { 21 | System.out.println("Sorry We don't know the capital"); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge100/Main.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge100; 2 | 3 | public class Main { 4 | public static void main(String[] args) throws InterruptedException { 5 | ThreadState t1 = new ThreadState(); 6 | System.out.printf("\nCreate the thread %s", 7 | t1.getState()); 8 | t1.start(); 9 | t1.join(); 10 | System.out.printf("\nthread finished %s", 11 | t1.getState()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge100/ThreadState.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge100; 2 | 3 | public class ThreadState extends Thread { 4 | 5 | @Override 6 | public void run() { 7 | try { 8 | Thread.sleep(4000); 9 | System.out.printf("\nFrom inside run %s", getState()); 10 | } catch (InterruptedException e) { 11 | throw new RuntimeException(e); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge101/PrintThread.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge101; 2 | 3 | public class PrintThread extends Thread { 4 | private final int threadNumber; 5 | 6 | public PrintThread(int threadNumber) { 7 | this.threadNumber = threadNumber; 8 | } 9 | 10 | @Override 11 | public void run() { 12 | System.out.printf("%s Thread Starting-%d\n", 13 | Thread.currentThread().getName(), 14 | threadNumber); 15 | 16 | try { 17 | Thread.sleep(5000); 18 | } catch (InterruptedException e) { 19 | throw new RuntimeException(e); 20 | } 21 | 22 | System.out.printf("%s Thread Ended-%d\n", 23 | Thread.currentThread().getName(), 24 | threadNumber); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge101/TestingJoin.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge101; 2 | 3 | public class TestingJoin { 4 | public static void main(String[] args) throws InterruptedException { 5 | PrintThread t1 = new PrintThread(1); 6 | PrintThread t2 = new PrintThread(2); 7 | PrintThread t3 = new PrintThread(3); 8 | 9 | t1.start(); 10 | t1.join(); 11 | t2.start(); 12 | t2.join(); 13 | t3.start(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge102/Road.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge102; 2 | 3 | public class Road { 4 | public static void main(String[] args) throws InterruptedException { 5 | TrafficLightThread red = new TrafficLightThread(TrafficColor.RED); 6 | TrafficLightThread yellow = new TrafficLightThread(TrafficColor.YELLOW); 7 | TrafficLightThread green = new TrafficLightThread(TrafficColor.GREEN); 8 | 9 | green.start(); 10 | green.join(); 11 | yellow.start(); 12 | yellow.join(); 13 | red.start(); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge102/TrafficColor.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge102; 2 | 3 | public enum TrafficColor { 4 | RED(9000), 5 | YELLOW(1000), 6 | GREEN(3000); 7 | 8 | private final int onTimeInMills; 9 | 10 | public int getOnTimeInMills() { 11 | return onTimeInMills; 12 | } 13 | 14 | TrafficColor(int onTimeInMills) { 15 | this.onTimeInMills = onTimeInMills; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge102/TrafficLightThread.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge102; 2 | 3 | import javax.swing.plaf.TableHeaderUI; 4 | 5 | public class TrafficLightThread extends Thread { 6 | 7 | private final TrafficColor color; 8 | 9 | public TrafficLightThread(TrafficColor color) { 10 | this.color = color; 11 | } 12 | 13 | @Override 14 | public void run() { 15 | System.out.printf("%s active\n", color); 16 | try { 17 | Thread.sleep(color.getOnTimeInMills()); 18 | } catch (InterruptedException e) { 19 | throw new RuntimeException(e); 20 | } 21 | System.out.printf("%s Inactive\n", color); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge103/PrintNumbers.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge103; 2 | 3 | public class PrintNumbers implements Runnable { 4 | @Override 5 | public void run() { 6 | for (int i = 0; i < 10; i++) { 7 | System.out.printf("Number is %d\n", i+1); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge103/SingleThreadService.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge103; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | public class SingleThreadService { 7 | public static void main(String[] args) { 8 | try (ExecutorService service = Executors.newSingleThreadExecutor()) { 9 | PrintNumbers task = new PrintNumbers(); 10 | service.submit(task); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge104/MultiThreadExecutorService.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge104; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class MultiThreadExecutorService { 8 | public static void main(String[] args) { 9 | try (ExecutorService service = Executors.newFixedThreadPool(5)) { 10 | for (int i = 0; i < 10; i++) { 11 | SleepTask task = new SleepTask(); 12 | service.submit(task); 13 | } 14 | service.shutdown(); 15 | 16 | if (!service.awaitTermination(10, TimeUnit.SECONDS)) { 17 | System.out.println("EMERGENCY SHUTDOWN"); 18 | service.shutdownNow(); 19 | } 20 | } catch (InterruptedException e) { 21 | throw new RuntimeException(e); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge104/SleepTask.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge104; 2 | 3 | public class SleepTask implements Runnable { 4 | @Override 5 | public void run() { 6 | Thread current = Thread.currentThread(); 7 | System.out.printf("Started with Thread: %s\n", current.getName()); 8 | try { 9 | Thread.sleep(getRandom() * 1000); 10 | } catch (InterruptedException e) { 11 | throw new RuntimeException(e); 12 | } 13 | System.out.printf("Ended with Thread: %s\n", current.getName()); 14 | } 15 | 16 | private int getRandom() { 17 | double random = Math.random() * 5 + 1; 18 | return (int) random; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge105/FactorialCalculator.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge105; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | public class FactorialCalculator implements Callable { 6 | 7 | private final int number; 8 | 9 | public FactorialCalculator(int number) { 10 | this.number = number; 11 | } 12 | 13 | @Override 14 | public Integer call() throws Exception { 15 | Thread.sleep(2000); 16 | if (number <= 1) { 17 | return 1; 18 | } 19 | int result = 1; 20 | for (int i = 2; i <= number; i++) { 21 | result *= i; 22 | } 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge105/TestingFactorial.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge105; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.concurrent.*; 6 | 7 | public class TestingFactorial { 8 | public static void main(String[] args) { 9 | try (ExecutorService service = Executors.newFixedThreadPool(3)) { 10 | List> list = new ArrayList<>(); 11 | for (int i = 0; i < 10; i++) { 12 | FactorialCalculator task = new FactorialCalculator(i); 13 | list.add(service.submit(task)); 14 | } 15 | 16 | for (Future future : list) { 17 | System.out.printf("\n Result is: %d", future.get()); 18 | } 19 | 20 | service.shutdown(); 21 | 22 | if (!service.awaitTermination(10, TimeUnit.SECONDS)) { 23 | System.out.println("BOHOT HUA BUS....."); 24 | service.shutdown(); 25 | } 26 | 27 | } catch (InterruptedException | ExecutionException e) { 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge106/LambdaMultiplication.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge106; 2 | 3 | import java.util.function.BinaryOperator; 4 | 5 | public class LambdaMultiplication { 6 | public static void main(String[] args) { 7 | BinaryOperator multi = (a, b) -> a * b; 8 | int result = multi.apply(4, 5); 9 | System.out.println(result); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge107/StreamTest.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge107; 2 | 3 | import java.util.List; 4 | 5 | public class StreamTest { 6 | public static void main(String[] args) { 7 | List names = List.of("Prashant", "Sanchit", "Kg Coding"); 8 | names.stream() 9 | .forEach(name -> System.out.println(name)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge108/StringFilterAndConcatenate.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge108; 2 | 3 | import java.util.List; 4 | 5 | public class StringFilterAndConcatenate { 6 | public static void main(String[] args) { 7 | List strs = List.of("Prashant Jain", "bad", 8 | "is teaching java", "ghatiya", "ganda", 9 | "on KG Coding", "Best Youtube programming channel"); 10 | 11 | String result = strs.stream() 12 | .filter(str -> str.length() > 10) 13 | .reduce("", (a, b) -> a + " " + b); 14 | 15 | System.out.println(result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge109/OddNumbers.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge109; 2 | 3 | import java.util.List; 4 | 5 | public class OddNumbers { 6 | public static void main(String[] args) { 7 | List numbers = List.of(1,2,3,4,5,6,7,8,9,10); 8 | numbers.stream() 9 | .filter(num -> num % 2 == 1) 10 | .forEach(num -> System.out.println(num)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge110/Candidate.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge110; 2 | 3 | @FunctionalInterface 4 | public interface Candidate { 5 | boolean isCandidate(int num); 6 | } 7 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge110/TestingFunctionalInterface.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge110; 2 | 3 | public class TestingFunctionalInterface { 4 | public static void main(String[] args) { 5 | Candidate candidate = num -> { 6 | for (int i = 2; i < num; i++) { 7 | if (num % i == 0) { 8 | return false; 9 | } 10 | } 11 | return true; 12 | }; 13 | 14 | System.out.println(candidate.isCandidate(12)); 15 | } 16 | } 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge111/TestingFactorial.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge111; 2 | 3 | import java.util.stream.IntStream; 4 | 5 | public class TestingFactorial { 6 | public static void main(String[] args) { 7 | System.out.println("Factorial using two ways"); 8 | int number = 9; 9 | System.out.println(factorial(number)); 10 | 11 | IntStream.rangeClosed(2, number) 12 | .reduce((a,b) -> a * b) 13 | .ifPresent(System.out::println); 14 | } 15 | 16 | public static int factorial(int num) { 17 | if (num == 0 || num == 1) { 18 | return 1; 19 | } 20 | 21 | int fact = 1; 22 | for (int i = 2; i <= num; i++) { 23 | fact *= i; 24 | } 25 | return fact; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge112/OptionalString.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge112; 2 | 3 | import java.util.Optional; 4 | 5 | public class OptionalString { 6 | public static void main(String[] args) { 7 | System.out.println(toOptional(null)); 8 | System.out.println(toOptional("")); 9 | System.out.println(toOptional("pop")); 10 | } 11 | 12 | public static Optional toOptional(String str) { 13 | if (str == null || str.isEmpty()) { 14 | return Optional.empty(); 15 | } 16 | return Optional.of(str.toUpperCase()); 17 | } 18 | } 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge113/TestingDistinct.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge113; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | public class TestingDistinct { 7 | public static void main(String[] args) { 8 | List numbers = List.of(1,2,3,2,5,3,4,6,2); 9 | List distinctNumbers = numbers.stream() 10 | .distinct() 11 | .collect(Collectors.toList()); 12 | System.out.println(numbers); 13 | System.out.println(distinctNumbers); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge114/Employee.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge114; 2 | 3 | public class Employee { 4 | private final String name; 5 | private final int salary; 6 | 7 | public Employee(String name, int salary) { 8 | this.name = name; 9 | this.salary = salary; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getSalary() { 17 | return salary; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | final StringBuilder sb = new StringBuilder("Employee{"); 23 | sb.append("name='").append(name).append('\''); 24 | sb.append(", salary=").append(salary); 25 | sb.append('}'); 26 | return sb.toString(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge114/TestingSorting.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge114; 2 | 3 | import java.util.Comparator; 4 | import java.util.List; 5 | 6 | public class TestingSorting { 7 | public static void main(String[] args) { 8 | List employees = List.of( 9 | new Employee("Prashant", 100), 10 | new Employee("Sanchit", 1000), 11 | new Employee("Ram", 10000), 12 | new Employee("Shyam", 1), 13 | new Employee("Mohan", 5) 14 | ); 15 | 16 | employees.stream() 17 | .sorted((emp1, emp2) -> emp1.getSalary() - emp2.getSalary()) 18 | .forEach(System.out::println); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge115/FinalTest.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge115; 2 | 3 | import java.util.List; 4 | 5 | public class FinalTest { 6 | public static void main(String[] args) { 7 | List numbers = List.of("1", "2", "3", "4", "5"); 8 | 9 | numbers.stream() 10 | .map(Integer::parseInt) 11 | .map(num -> Math.pow(num, 2)) 12 | .reduce(Double::sum) 13 | .ifPresent(System.out::println); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge77/geometry/Circle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge77.geometry; 2 | 3 | public class Circle { 4 | public double radius; 5 | 6 | public Circle(double radius) { 7 | this.radius = radius; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge77/geometry/Rectangle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge77.geometry; 2 | 3 | public class Rectangle { 4 | 5 | public int length; 6 | public int breadth; 7 | 8 | public Rectangle(int length, int breadth) { 9 | this.length = length; 10 | this.breadth = breadth; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge77/utils/Calculator.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge77.utils; 2 | 3 | import in.kgcoding.challenge77.geometry.Circle; 4 | import in.kgcoding.challenge77.geometry.Rectangle; 5 | 6 | public class Calculator { 7 | public static void main(String[] args) { 8 | Circle cir = new Circle(5.5); 9 | Rectangle rect = new Rectangle(10, 5); 10 | 11 | double cirArea = Math.PI * Math.pow(cir.radius, 2); 12 | double rectArea = rect.breadth * rect.length; 13 | 14 | System.out.printf("Area of the circle is: %f, Area of the rectangle is: %f", 15 | cirArea, rectArea); 16 | } 17 | } 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge78/BankAccount.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge78; 2 | 3 | class BankAccount { 4 | private String accountNumber; 5 | private String accountHolderName; 6 | private double balance; 7 | 8 | public BankAccount(String accountNumber, String accountHolderName) { 9 | this.accountNumber = accountNumber; 10 | this.accountHolderName = accountHolderName; 11 | } 12 | 13 | public void depositMoney(double money) { 14 | if (money <= 0) { 15 | System.out.println("Invalid Deposit"); 16 | } else { 17 | balance += money; 18 | } 19 | } 20 | 21 | public double withdrawMoney(double money) { 22 | if (money <= 0) { 23 | System.out.println("Invalid Withdraw"); 24 | } else if (balance >= money) { 25 | balance -= money; 26 | } else { 27 | money = balance; 28 | balance = 0; 29 | } 30 | return money; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge78/Customer.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge78; 2 | 3 | public class Customer { 4 | public static void main(String[] args) { 5 | BankAccount account = new BankAccount("001", "Prashant Jain"); 6 | account.depositMoney(100); 7 | System.out.println(account.withdrawMoney(200)); 8 | account.depositMoney(-40); 9 | account.withdrawMoney(0); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge79/Employee.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge79; 2 | 3 | class Employee { 4 | 5 | private String name; 6 | private int age; 7 | private double salary; 8 | 9 | Employee(String name, int age, double salary) { 10 | this.name = name; 11 | this.age = age; 12 | this.salary = salary; 13 | } 14 | 15 | String getEmployeeDetails() { 16 | return "EmployeeDetails: Name:" + name 17 | + ", Age:" + age 18 | + ", Salary:" + salary; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public int getAge() { 30 | return age; 31 | } 32 | 33 | public void setAge(int age) { 34 | this.age = age; 35 | } 36 | 37 | public double getSalary() { 38 | return salary; 39 | } 40 | 41 | public void setSalary(double salary) { 42 | this.salary = salary; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge79/TestEmployee.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge79; 2 | 3 | public class TestEmployee { 4 | public static void main(String[] args) { 5 | Employee emp = new Employee("Prashant", 30, 25000); 6 | System.out.println(emp.getEmployeeDetails()); 7 | emp.setName("Golu"); 8 | System.out.println(emp.getEmployeeDetails()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge80/Book.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge80; 2 | 3 | public class Book extends LibraryItem { 4 | 5 | private String iSBN; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge80/DVD.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge80; 2 | 3 | public class DVD extends LibraryItem { 4 | 5 | private int durationInSeconds; 6 | } 7 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge80/LibraryItem.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge80; 2 | 3 | public class LibraryItem { 4 | private String itemId; 5 | private String title; 6 | private String author; 7 | 8 | public void checkout() { 9 | System.out.println("checkout"); 10 | } 11 | 12 | public void returnItem() { 13 | System.out.println("Returning the item"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge80/Magazine.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge80; 2 | 3 | public class Magazine extends LibraryItem { 4 | 5 | private String issueNumber; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge82/ArrayOperations.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge82; 2 | 3 | public class ArrayOperations { 4 | private int[] numbers; 5 | 6 | public ArrayOperations(int[] numbers) { 7 | this.numbers = numbers; 8 | } 9 | 10 | public class Statistics { 11 | double mean() { 12 | double sum = 0; 13 | for (int number : numbers) { 14 | sum += number; 15 | } 16 | return sum / numbers.length; 17 | } 18 | 19 | double median() { 20 | return 0; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge82/TestArray.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge82; 2 | 3 | public class TestArray { 4 | public static void main(String[] args) { 5 | ArrayOperations opr = new ArrayOperations(new int[]{1,3,5,9}); 6 | ArrayOperations.Statistics statistics = opr.new Statistics(); 7 | System.out.println(statistics.mean()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge83/Circle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge83; 2 | 3 | public class Circle extends Shape { 4 | private final double radiusInCms; 5 | 6 | public Circle(double radiusInCms) { 7 | this.radiusInCms = radiusInCms; 8 | } 9 | 10 | public double getRadiusInCms() { 11 | return radiusInCms; 12 | } 13 | 14 | @Override 15 | public double calculateArea() { 16 | return Math.PI * Math.pow(radiusInCms, 2); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge83/Shape.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge83; 2 | 3 | public abstract class Shape { 4 | public abstract double calculateArea(); 5 | } 6 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge83/Square.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge83; 2 | 3 | public class Square extends Shape { 4 | 5 | private final double sideInCms; 6 | 7 | public Square(double sideInCms) { 8 | this.sideInCms = sideInCms; 9 | } 10 | 11 | public double getSideInCms() { 12 | return sideInCms; 13 | } 14 | 15 | @Override 16 | public double calculateArea() { 17 | return Math.pow(sideInCms, 2); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge83/TestShapes.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge83; 2 | 3 | public class TestShapes { 4 | public static void main(String[] args) { 5 | //Shape shape = new Shape(); 6 | Circle circle = new Circle(5); 7 | Square square = new Square(10.3); 8 | 9 | System.out.printf("Area of Circle is %5.2f\n", circle.calculateArea()); 10 | System.out.printf("Area of Square is %5.2f\n", square.calculateArea()); 11 | } 12 | } 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge84/Bird.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge84; 2 | 3 | public abstract class Bird implements Flyable { 4 | 5 | private final String breed; 6 | 7 | public Bird(String breed) { 8 | this.breed = breed; 9 | } 10 | 11 | public String getBreed() { 12 | return breed; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge84/Eagle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge84; 2 | 3 | public class Eagle extends Bird { 4 | public Eagle() { 5 | super("Eagle"); 6 | } 7 | 8 | @Override 9 | public void fly() { 10 | System.out.println("Eagle is flying."); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge84/Flyable.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge84; 2 | 3 | public interface Flyable { 4 | void fly(); 5 | } 6 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge84/TestFly.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge84; 2 | 3 | public class TestFly { 4 | public static void main(String[] args) { 5 | Eagle eagle = new Eagle(); 6 | eagle.fly(); 7 | } 8 | } -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge85/Calculator.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge85; 2 | 3 | public class Calculator { 4 | public int add(int first, int second) { 5 | return first + second; 6 | } 7 | 8 | public int add(int first, int second, int third) { 9 | return first + second + third; 10 | } 11 | 12 | public double add(double first, double second) { 13 | return first + second; 14 | } 15 | 16 | public static void main(String[] args) { 17 | Calculator calc = new Calculator(); 18 | System.out.println(calc.add(5, 6)); 19 | System.out.println(calc.add(5, 6, 7)); 20 | System.out.println(calc.add(5.9, 6.2)); 21 | } 22 | } 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge86/Car.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge86; 2 | 3 | public class Car extends Vehicle { 4 | @Override 5 | public void service() { 6 | super.service(); 7 | System.out.println("Car is getting serviced....."); 8 | } 9 | } 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge86/Test.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge86; 2 | 3 | public class Test { 4 | public static void main(String[] args) { 5 | Car car = new Car(); 6 | Vehicle veh = new Vehicle(); 7 | veh.service(); 8 | car.service(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge86/Vehicle.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge86; 2 | 3 | public class Vehicle { 4 | 5 | public void service() { 6 | System.out.println("Vehicle is getting serviced...."); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge87/Calculator.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge87; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Calculator { 6 | public static void main(String[] args) { 7 | Scanner input = new Scanner(System.in); 8 | System.out.println("Welcome to calculator\n"); 9 | System.out.print("Enter first number: "); 10 | int first = input.nextInt(); 11 | System.out.print("Now, the second: "); 12 | int second = input.nextInt(); 13 | 14 | try { 15 | int result = first / second; 16 | System.out.printf("Result is %d", result); 17 | } catch (ArithmeticException exception) { 18 | if (exception.getMessage() 19 | .equals("/ by zero")) { 20 | System.out.println("Divide by zero occurred."); 21 | } else { 22 | throw exception; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge88/RobustFileReader.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge88; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.Scanner; 7 | 8 | public class RobustFileReader { 9 | public static void main(String[] args) { 10 | Scanner input = new Scanner(System.in); 11 | System.out.print("Please enter the name of the file you wish to read: "); 12 | String fileName = input.next(); 13 | 14 | try (FileReader reader = new FileReader(fileName)) { 15 | int read; 16 | while ((read = reader.read()) != -1) { 17 | System.out.print((char)read); 18 | } 19 | } catch (FileNotFoundException exception) { 20 | System.out.printf("%s not found", fileName); 21 | } catch (IOException exception) { 22 | System.out.printf("Exception occurred: %s", 23 | exception.getMessage()); 24 | } 25 | } 26 | } 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge96/Day.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge96; 2 | 3 | public enum Day { 4 | MONDAY, 5 | TUESDAY, 6 | WEDNESDAY, 7 | THRUSDAY, 8 | FRIDAY, 9 | SATURDAY, 10 | SUNDAY 11 | } 12 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge96/EnumTest.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge96; 2 | 3 | public class EnumTest { 4 | public static void main(String[] args) { 5 | System.out.println("Printing all the days of the week"); 6 | System.out.println(Day.MONDAY); 7 | System.out.println(Day.TUESDAY); 8 | System.out.println(Day.WEDNESDAY); 9 | System.out.println(Day.THRUSDAY); 10 | System.out.println(Day.FRIDAY); 11 | System.out.println(Day.SATURDAY); 12 | System.out.println(Day.SUNDAY); 13 | 14 | for (Day day : Day.values()) { 15 | System.out.println(day); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge97/Day.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge97; 2 | 3 | public enum Day { 4 | MONDAY(true), 5 | TUESDAY(true), 6 | WEDNESDAY(true), 7 | THRUSDAY(true), 8 | FRIDAY(true), 9 | SATURDAY(false), 10 | SUNDAY(false); 11 | 12 | private final boolean isWeekday; 13 | 14 | Day(boolean isWeekday) { 15 | this.isWeekday = isWeekday; 16 | } 17 | 18 | public String getType() { 19 | return isWeekday ? "Weekday" : "Weekend"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge97/EnumTest.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge97; 2 | 3 | public class EnumTest { 4 | public static void main(String[] args) { 5 | System.out.println("Printing all the days of the week"); 6 | for (Day day : Day.values()) { 7 | System.out.printf("%s : %s\n", day, day.getType()); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge99/HelloThread.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge99; 2 | 3 | public class HelloThread extends Thread { 4 | 5 | private final int threadNumber; 6 | 7 | public HelloThread(int threadNumber) { 8 | this.threadNumber = threadNumber; 9 | } 10 | 11 | @Override 12 | public void run() { 13 | for (int i = 0; i < 10; i++) { 14 | System.out.printf("(%d) %s Hello from Thread-%d\n", 15 | (i+1), Thread.currentThread().getName(), 16 | threadNumber); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Programming Challenge/src/in/kgcoding/challenge99/Main.java: -------------------------------------------------------------------------------- 1 | package in.kgcoding.challenge99; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | HelloThread t1 = new HelloThread(1); 6 | HelloThread t2 = new HelloThread(2); 7 | 8 | t1.start(); 9 | t2.start(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![1](https://github.com/KG-Coding-with-Prashant-Sir/Java_Complete_Youtube/assets/102736197/ec40ebbc-cb0d-446c-8078-1380e2ce940c) 2 | ![2](https://github.com/KG-Coding-with-Prashant-Sir/Java_Complete_Youtube/assets/102736197/83214d75-b2f3-4246-addd-c0da1874aa31) 3 | ![3](https://github.com/KG-Coding-with-Prashant-Sir/Java_Complete_Youtube/assets/102736197/f63ccf04-a85e-407e-a7f8-e434c8565ab7) 4 | --------------------------------------------------------------------------------