├── .gitignore ├── README.md ├── doc ├── JavaNotes.md └── media │ ├── AnalyticalCircle.png │ ├── DemoRaceAppClasses.PNG │ ├── DemoTaxiAutomationApp.PNG │ ├── InheritanceMemory.PNG │ ├── StringInternal.png │ ├── Vehicles.PNG │ ├── aggregation.png │ ├── association.png │ ├── big-endian.png │ ├── composition.png │ ├── hardware.png │ ├── inheritance1.png │ ├── inheritance2.png │ ├── inheritance3.png │ ├── little-endian.png │ ├── non-static-fields1.png │ ├── object-reference1.png │ ├── object-reference2.png │ ├── ram.png │ ├── ram2.png │ ├── ram3.png │ ├── reference-assignment.png │ ├── reference-assignment1.png │ ├── reference-assignment2.png │ ├── reference-assignment3.png │ ├── reference-assignment4.png │ └── reference-assignment5.png ├── homework ├── Homework-001.md ├── Homework-002.pdf ├── Homework-003.pdf ├── Homework-004.pdf ├── Homework-005.pdf ├── Homework-006.pdf ├── Homework-007.pdf ├── Homework-008.pdf ├── Homework-009.pdf ├── Homework-010.pdf ├── Homework-011.pdf ├── Homework-012.pdf ├── Homework-013.pdf ├── Homework-014.pdf ├── Solutions.md └── sudoku.txt └── src ├── Sample ├── .gitignore ├── .idea │ ├── .gitignore │ ├── codeStyles │ │ └── codeStyleConfig.xml │ ├── misc.xml │ ├── modules.xml │ └── vcs.xml ├── Sample.iml ├── question └── src │ └── org │ └── csystem │ ├── app │ ├── App.java │ ├── datetime │ │ ├── DateAppEN.java │ │ ├── DateAppTR.java │ │ └── DateUtil.java │ ├── game │ │ ├── banner │ │ │ └── ballfall │ │ │ │ └── BallFallApp.java │ │ └── lottery │ │ │ └── NumericLotteryApp.java │ ├── generator │ │ └── DemoObjectArrayGeneratorApp.java │ ├── school │ │ └── grade │ │ │ ├── GradeCalculator.java │ │ │ ├── GradeCalculatorApp.java │ │ │ └── GradeInfo.java │ ├── simulation │ │ └── exam │ │ │ ├── ExamInfo.java │ │ │ ├── ExamSimulation.java │ │ │ └── ExamSimulationApp.java │ └── string │ │ └── store │ │ ├── ConcatWithHyphenApp.java │ │ └── StoreStringsApp.java │ ├── datetime │ ├── DayOfWeek.java │ └── Month.java │ ├── game │ ├── banner │ │ └── ballfall │ │ │ └── BallFall.java │ ├── card │ │ ├── Card.java │ │ ├── CardType.java │ │ ├── CardValue.java │ │ └── RandomCardGenerator.java │ └── lottery │ │ └── NumericLottery.java │ ├── math │ ├── Complex.java │ ├── geometry │ │ ├── AnalyticalCircle.java │ │ ├── Circle.java │ │ ├── MutablePoint.java │ │ ├── Point.java │ │ ├── PointCommon.java │ │ └── test │ │ │ ├── AnalyticalCircleCenterDistanceTest.java │ │ │ ├── AnalyticalCircleCenterTest.java │ │ │ ├── AnalyticalCircleIsTangentTest.java │ │ │ └── CircleRadiusPositiveTest.java │ └── util │ │ └── MathUtil.java │ ├── random │ └── generator │ │ ├── ObjectArrayGenerator.java │ │ └── RandomStringArrayGenerator.java │ ├── string │ └── CSDStringBuilder.java │ ├── util │ ├── array │ │ ├── ArrayUtil.java │ │ └── test │ │ │ ├── ArrayUtilAddTest.java │ │ │ ├── ArrayUtilArrayOfIntArrayEqualsTest.java │ │ │ ├── ArrayUtilAverageTest.java │ │ │ ├── ArrayUtilBubbleSortAscendingTest.java │ │ │ ├── ArrayUtilBubbleSortDescendingTest.java │ │ │ ├── ArrayUtilEqualsTest.java │ │ │ ├── ArrayUtilHistogramDataTest.java │ │ │ ├── ArrayUtilMinMaxTest.java │ │ │ ├── ArrayUtilMultiplyTest.java │ │ │ ├── ArrayUtilPartitionTest.java │ │ │ ├── ArrayUtilReverseTest.java │ │ │ ├── ArrayUtilReversedTest.java │ │ │ ├── ArrayUtilSelectionSortAscendingTest.java │ │ │ ├── ArrayUtilSelectionSortDescendingTest.java │ │ │ ├── ArrayUtilSubtractTest.java │ │ │ └── ArrayUtilSumTest.java │ ├── console │ │ ├── Console.java │ │ └── commanline │ │ │ └── CommandLineArgsUtil.java │ ├── datetime │ │ └── DateTimeUtil.java │ ├── matrix │ │ ├── MatrixUtil.java │ │ └── test │ │ │ ├── MatrixUtilAddByTest.java │ │ │ ├── MatrixUtilAddTest.java │ │ │ ├── MatrixUtilArrayOfIntArrayEqualsTest.java │ │ │ ├── MatrixUtilIsMatrixTest.java │ │ │ ├── MatrixUtilIsSquareMatrixTest.java │ │ │ ├── MatrixUtilMultiplyByTest.java │ │ │ ├── MatrixUtilMultiplyTest.java │ │ │ ├── MatrixUtilSubtractByTest.java │ │ │ ├── MatrixUtilSubtractTest.java │ │ │ ├── MatrixUtilSumDiagonalTest.java │ │ │ └── MatrixUtilTransposeTest.java │ ├── numeric │ │ ├── NumberUtil.java │ │ └── test │ │ │ ├── NumberUtilDigitsInThreesTest.java │ │ │ ├── NumberUtilDigitsInTwosTest.java │ │ │ ├── NumberUtilDigitsTest.java │ │ │ └── NumberUtilNumToStrTRTest.java │ ├── string │ │ ├── StringSplitOptions.java │ │ ├── StringUtil.java │ │ └── test │ │ │ ├── StringUtilChangeCaseTest.java │ │ │ ├── StringUtilDigitsTest.java │ │ │ ├── StringUtilJoinDirectTest.java │ │ │ ├── StringUtilJoinWithCharDelimiterTest.java │ │ │ ├── StringUtilJoinWithDelimiterIgnoreEmptiesTest.java │ │ │ ├── StringUtilJoinWithDelimiterIgnoreStatusTest.java │ │ │ ├── StringUtilJoinWithDelimiterTest.java │ │ │ ├── StringUtilRandomTextTRENTest.java │ │ │ ├── StringUtilRandomTextsTRENFixedTest.java │ │ │ ├── StringUtilRandomTextsTRENTest.java │ │ │ └── StringUtilSplitTest.java │ └── thread │ │ └── ThreadUtil.java │ └── wrapper │ ├── IntValue.java │ └── test │ └── IntValueCacheTest.java ├── csd ├── App.class ├── App.java ├── Mample.class └── Sample.class └── msd ├── Sample.class └── Sample.java /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-Sep-2024 2 | KAYNAK GÖSTERMEK KOŞULUYLA HER TÜRLÜ ALINTI YAPILABİLİR 3 | 4 | #java 5 | #programming 6 | #eclipse 7 | #intellij 8 | #spring 9 | #springboot 10 | -------------------------------------------------------------------------------- /doc/media/AnalyticalCircle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/AnalyticalCircle.png -------------------------------------------------------------------------------- /doc/media/DemoRaceAppClasses.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/DemoRaceAppClasses.PNG -------------------------------------------------------------------------------- /doc/media/DemoTaxiAutomationApp.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/DemoTaxiAutomationApp.PNG -------------------------------------------------------------------------------- /doc/media/InheritanceMemory.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/InheritanceMemory.PNG -------------------------------------------------------------------------------- /doc/media/StringInternal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/StringInternal.png -------------------------------------------------------------------------------- /doc/media/Vehicles.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/Vehicles.PNG -------------------------------------------------------------------------------- /doc/media/aggregation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/aggregation.png -------------------------------------------------------------------------------- /doc/media/association.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/association.png -------------------------------------------------------------------------------- /doc/media/big-endian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/big-endian.png -------------------------------------------------------------------------------- /doc/media/composition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/composition.png -------------------------------------------------------------------------------- /doc/media/hardware.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/hardware.png -------------------------------------------------------------------------------- /doc/media/inheritance1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/inheritance1.png -------------------------------------------------------------------------------- /doc/media/inheritance2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/inheritance2.png -------------------------------------------------------------------------------- /doc/media/inheritance3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/inheritance3.png -------------------------------------------------------------------------------- /doc/media/little-endian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/little-endian.png -------------------------------------------------------------------------------- /doc/media/non-static-fields1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/non-static-fields1.png -------------------------------------------------------------------------------- /doc/media/object-reference1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/object-reference1.png -------------------------------------------------------------------------------- /doc/media/object-reference2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/object-reference2.png -------------------------------------------------------------------------------- /doc/media/ram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/ram.png -------------------------------------------------------------------------------- /doc/media/ram2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/ram2.png -------------------------------------------------------------------------------- /doc/media/ram3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/ram3.png -------------------------------------------------------------------------------- /doc/media/reference-assignment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/reference-assignment.png -------------------------------------------------------------------------------- /doc/media/reference-assignment1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/reference-assignment1.png -------------------------------------------------------------------------------- /doc/media/reference-assignment2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/reference-assignment2.png -------------------------------------------------------------------------------- /doc/media/reference-assignment3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/reference-assignment3.png -------------------------------------------------------------------------------- /doc/media/reference-assignment4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/reference-assignment4.png -------------------------------------------------------------------------------- /doc/media/reference-assignment5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/doc/media/reference-assignment5.png -------------------------------------------------------------------------------- /homework/Homework-001.md: -------------------------------------------------------------------------------- 1 | ##### C ve Sistem Programcıları Derneği 2 | 3 | ##### Java ile Nesne Yönelimli Programlama 4 | 5 | ##### Çalışma Soruları 6 | 7 | **1.** Klavyeden alınan ***int*** türden üç sayı arasındaki büyüklük-küçüklük ilişkisini küçükten büyüğe doğru `<` ve `=` sembolleriyle gösteren programı yazınız: 8 | 9 | **Açıklama:** 10 | 11 | - Program içerisinde dizi kullanılmayacaktır. Zaten gerek de yoktur. 12 | 13 | - Bir sıralama algoritmasına ihtiyacınız yoktur. 14 | 15 | - Program üç tane int türden sayı isteyecektir ve aralarındaki ilişkiyi ekranda gösterecektir. İşte birkaç örnek 16 | 17 | > Giriş: `10 20 30` 18 | > 19 | > Yanıt: `10 < 20 < 30` 20 | > 21 | > Giriş: `30 10 20` 22 | > 23 | > Yanıt: `10 < 20 < 30` 24 | > 25 | > Giriş: `10 10 15` 26 | > 27 | > Yanıt: `10 = 10 < 15` 28 | > 29 | > Giriş: `40 50 50` 30 | > 31 | > Yanıt: `40 < 50 = 50` 32 | 33 | **2.** Parametresi ile aldığı ***int*** türden 3 sayıdan ortancasına geri dönen ***mid*** isimli metodu **NumberUtil** isimli sınıf içerisinde yazınız ve test ediniz. 34 | 35 | **Açıklamalar:** 36 | 37 | - Metot sayıların aynı olması durumunda da ortanca değere geri dönecektir. Örneğin sayılar 10, 10, 20 ise ortanca değer 10 olacaktır. 38 | 39 | - Üç tane sayının ortancası sayıların toplamından sayıların en küçüğünün ve en büyüğünün toplamını çıkartmakla bulunabilir. Metot bu şekilde **yazılmayacaktır.** Yani metot içerisinde sayıların en büyüğünün ve en küçüğünün bulunmasına gerek yoktur. 40 | 41 | **3.** Parametresi ile aldığı int türden bir sayının negatif mi, 0(sıfır) mı, pozitif mi olduğunu test eden **signum*** isimli metodu yazınız ve test ediniz. Metot pozitif için 1(bir), negatif için -1(eksi bir) ve sıfır için 0(sıfır) döndürecektir. 42 | 43 | **Açıklama:** Math sınıfının signum metodu **kullanılmayacaktır.** 44 | 45 | **Çözümlerinizi eğitmene kontrol ettiriniz.** 46 | 47 | **Tekrar yapıyor musunuz? ...** 48 | 49 | **İyi Çalışmalar\...** 50 | -------------------------------------------------------------------------------- /homework/Homework-002.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-002.pdf -------------------------------------------------------------------------------- /homework/Homework-003.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-003.pdf -------------------------------------------------------------------------------- /homework/Homework-004.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-004.pdf -------------------------------------------------------------------------------- /homework/Homework-005.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-005.pdf -------------------------------------------------------------------------------- /homework/Homework-006.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-006.pdf -------------------------------------------------------------------------------- /homework/Homework-007.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-007.pdf -------------------------------------------------------------------------------- /homework/Homework-008.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-008.pdf -------------------------------------------------------------------------------- /homework/Homework-009.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-009.pdf -------------------------------------------------------------------------------- /homework/Homework-010.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-010.pdf -------------------------------------------------------------------------------- /homework/Homework-011.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-011.pdf -------------------------------------------------------------------------------- /homework/Homework-012.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-012.pdf -------------------------------------------------------------------------------- /homework/Homework-013.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-013.pdf -------------------------------------------------------------------------------- /homework/Homework-014.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/homework/Homework-014.pdf -------------------------------------------------------------------------------- /homework/Solutions.md: -------------------------------------------------------------------------------- 1 | ### Java ile Nesne Yönelimli Programlama Kursu 2 | ### Çalışma Soruları Çözümleri 3 | ### Eğitmen: Oğuz KARAN 4 | ### C ve Sistem Programcıları Derneği 5 | 6 | #### Homework-001 7 | 8 | >1.sorunun bir çözümü 9 | > 10 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 11 | 12 | ```java 13 | package csd; 14 | 15 | class App { 16 | public static void main(String[] args) 17 | { 18 | PrintRelationsApp.run(); 19 | } 20 | } 21 | 22 | class PrintRelationsApp { 23 | public static void printRelations(int a, int b, int c) 24 | { 25 | int max = Math.max(Math.max(a, b), c); 26 | int min = Math.min(Math.min(a, b), c); 27 | int mid = a + b + c - max - min; 28 | 29 | if (min < mid) 30 | System.out.printf("%d < %d ", min, mid); 31 | else 32 | System.out.printf("%d = %d ", min, mid); 33 | 34 | if (mid < max) 35 | System.out.printf("< %d%n", max); 36 | else 37 | System.out.printf("= %d%n", max); 38 | } 39 | 40 | public static void run() 41 | { 42 | java.util.Scanner kb = new java.util.Scanner(System.in); 43 | 44 | System.out.print("Üç tane sayı giriniz:"); 45 | int a = kb.nextInt(); 46 | int b = kb.nextInt(); 47 | int c = kb.nextInt(); 48 | 49 | printRelations(a, b, c); 50 | } 51 | } 52 | 53 | ``` 54 | 55 | >2.sorunun bir çözümü 56 | > 57 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 58 | 59 | ```java 60 | package csd; 61 | 62 | class App { 63 | public static void main(String [] args) 64 | { 65 | NumberUtilMidTest.run(); 66 | } 67 | } 68 | 69 | class NumberUtilMidTest { 70 | public static void run() 71 | { 72 | java.util.Scanner kb = new java.util.Scanner(System.in); 73 | 74 | System.out.print("Üç tane sayı giriniz:"); 75 | int a = kb.nextInt(); 76 | int b = kb.nextInt(); 77 | int c = kb.nextInt(); 78 | 79 | System.out.printf("mid(%d, %d, %d) = %d%n", a, b, c, NumberUtil.mid(a, b, c)); 80 | } 81 | } 82 | 83 | class NumberUtil { 84 | public static int mid(int a, int b, int c) 85 | { 86 | if (a <= b && b <= c || c <= b && b <= a) 87 | return b; 88 | 89 | if (b <= a && a <= c || c <= a && a <= b) 90 | return a; 91 | 92 | return c; 93 | } 94 | } 95 | ``` 96 | >2.sorunun bir çözümü 97 | > 98 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 99 | 100 | ```java 101 | package csd; 102 | 103 | class App { 104 | public static void main(String [] args) 105 | { 106 | NumberUtilMidTest.run(); 107 | } 108 | } 109 | 110 | class NumberUtilMidTest { 111 | public static void run() 112 | { 113 | java.util.Scanner kb = new java.util.Scanner(System.in); 114 | 115 | System.out.print("Üç tane sayı giriniz:"); 116 | int a = kb.nextInt(); 117 | int b = kb.nextInt(); 118 | int c = kb.nextInt(); 119 | 120 | System.out.printf("mid(%d, %d, %d) = %d%n", a, b, c, NumberUtil.mid(a, b, c)); 121 | } 122 | } 123 | 124 | class NumberUtil { 125 | public static int mid(int a, int b, int c) 126 | { 127 | int result = c; 128 | 129 | if (a <= b && b <= c || c <= b && b <= a) 130 | result = b; 131 | else if (b <= a && a <= c || c <= a && a <= b) 132 | result = a; 133 | 134 | return result; 135 | } 136 | } 137 | ``` 138 | >3.sorunun bir çözümü 139 | > 140 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 141 | 142 | ```java 143 | package csd; 144 | 145 | class App { 146 | public static void main(String [] args) 147 | { 148 | NumberUtilSignumTest.run(); 149 | } 150 | } 151 | 152 | class NumberUtilSignumTest { 153 | public static void run() 154 | { 155 | java.util.Scanner kb = new java.util.Scanner(System.in); 156 | 157 | System.out.print("Bir sayı giriniz:"); 158 | int a = kb.nextInt(); 159 | 160 | System.out.printf("signum(%d) = %d%n", a, NumberUtil.signum(a)); 161 | } 162 | } 163 | 164 | class NumberUtil { 165 | public static int signum(int a) 166 | { 167 | if (a > 0) 168 | return 1; 169 | 170 | if (a == 0) 171 | return 0; 172 | 173 | return -1; 174 | } 175 | } 176 | 177 | ``` 178 | 179 | >3.sorunun bir çözümü 180 | > 181 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 182 | 183 | ```java 184 | package csd; 185 | 186 | class App { 187 | public static void main(String [] args) 188 | { 189 | NumberUtilSignumTest.run(); 190 | } 191 | } 192 | 193 | class NumberUtilSignumTest { 194 | public static void run() 195 | { 196 | java.util.Scanner kb = new java.util.Scanner(System.in); 197 | 198 | System.out.print("Bir sayı giriniz:"); 199 | int a = kb.nextInt(); 200 | 201 | System.out.printf("signum(%d) = %d%n", a, NumberUtil.signum(a)); 202 | } 203 | } 204 | 205 | class NumberUtil { 206 | public static int signum(int a) 207 | { 208 | int result = -1; 209 | 210 | if (a > 0) 211 | result = 1; 212 | else if (a == 0) 213 | result = 0; 214 | 215 | return result; 216 | } 217 | } 218 | 219 | ``` 220 | #### Homework-002 221 | 222 | >1.sorunun bir çözümü 223 | > 224 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 225 | 226 | ```java 227 | package csd; 228 | 229 | class App { 230 | public static void main(String[] args) 231 | { 232 | PrintDiamondApp.run(); 233 | } 234 | } 235 | 236 | class PrintDiamondApp { 237 | public static void printAbove(int n) 238 | { 239 | for (int i = 1; i < n; ++i) { 240 | for (int k = 0; k < n - i; ++k) 241 | System.out.print(' '); 242 | 243 | for (int k = 0; k < 2 * i - 1; ++k) 244 | System.out.print('*'); 245 | 246 | System.out.println(); 247 | } 248 | } 249 | 250 | public static void printBelow(int n) 251 | { 252 | for (int i = 0; i < n; ++i) { 253 | for (int k = 0; k < i; ++k) 254 | System.out.print(' '); 255 | 256 | for (int k = 0; k < 2 * (n - i) - 1; ++k) 257 | System.out.print('*'); 258 | 259 | System.out.println(); 260 | } 261 | } 262 | 263 | public static void printDiamond(int n) 264 | { 265 | printAbove(n); 266 | printBelow(n); 267 | } 268 | 269 | public static void run() 270 | { 271 | java.util.Scanner kb = new java.util.Scanner(System.in); 272 | 273 | System.out.print("Bir sayı giriniz:"); 274 | int n = kb.nextInt(); 275 | 276 | printDiamond(n); 277 | } 278 | } 279 | ``` 280 | >2.sorunun bir çözümü 281 | > 282 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 283 | 284 | ```java 285 | package csd; 286 | 287 | class App { 288 | public static void main(String[] args) 289 | { 290 | DurationUtilPrintDurationTest.run(); 291 | } 292 | } 293 | 294 | class DurationUtilPrintDurationTest { 295 | public static void run() 296 | { 297 | java.util.Scanner kb = new java.util.Scanner(System.in); 298 | 299 | while (true) { 300 | System.out.print("Saniye değerini giriniz:"); 301 | long totalSeconds = Long.parseLong(kb.nextLine()); 302 | 303 | DurationUtil.printDuration(totalSeconds); 304 | 305 | if (totalSeconds == 0) 306 | break; 307 | } 308 | 309 | 310 | } 311 | } 312 | 313 | class DurationUtil { 314 | public static void printDuration(long totalSeconds) 315 | { 316 | long hours = totalSeconds / 60 / 60; 317 | long minutes = totalSeconds / 60 % 60; 318 | long seconds = totalSeconds % 60; 319 | 320 | if (hours != 0) 321 | System.out.printf("%d saat ", hours); 322 | 323 | if (minutes != 0) 324 | System.out.printf("%d dakika ", minutes); 325 | 326 | if (seconds != 0) 327 | System.out.printf("%d saniye", seconds); 328 | 329 | System.out.println(); 330 | } 331 | } 332 | ``` 333 | >3.sorunun bir çözümü 334 | > 335 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 336 | 337 | ```java 338 | package csd; 339 | 340 | class App { 341 | public static void main(String[] args) 342 | { 343 | PrintPrimeFactorsApp.run(); 344 | } 345 | } 346 | 347 | class PrintPrimeFactorsApp { 348 | public static void run() 349 | { 350 | java.util.Scanner kb = new java.util.Scanner(System.in); 351 | 352 | while (true) { 353 | System.out.print("Bir sayı giriniz:"); 354 | int val = Integer.parseInt(kb.nextLine()); 355 | 356 | if (val <= 0) 357 | break; 358 | 359 | NumberUtil.printPrimeFactors(val); 360 | } 361 | } 362 | } 363 | 364 | class NumberUtil { 365 | public static void printPrimeFactors(int val) 366 | { 367 | int x = 2; 368 | 369 | while (val != 1) 370 | if (val % x == 0) { 371 | System.out.printf("%d ", x); 372 | val /= x; 373 | } 374 | else 375 | ++x; 376 | 377 | System.out.println(); 378 | } 379 | } 380 | ``` 381 | 382 | >4.sorunun bir çözümü 383 | > 384 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 385 | 386 | ```java 387 | package csd; 388 | 389 | class App { 390 | public static void main(String [] args) 391 | { 392 | BallFallApp.run(); 393 | } 394 | } 395 | 396 | class BallFallApp { 397 | public static void run() 398 | { 399 | java.util.Scanner kb = new java.util.Scanner(System.in); 400 | 401 | while (true) { 402 | System.out.print("Input width and height:"); 403 | int width = kb.nextInt(); 404 | int height = kb.nextInt(); 405 | 406 | if (width == 0 || height == 0) 407 | break; 408 | 409 | BallFall.play(width, height); 410 | } 411 | } 412 | } 413 | 414 | class BallFall { 415 | public static void writeSpaces(int begin, int end) 416 | { 417 | for (int i = begin; i < end; ++i) 418 | System.out.print(' '); 419 | } 420 | 421 | public static void writeBall(int ballIndex, int end) 422 | { 423 | writeSpaces(0, ballIndex); 424 | System.out.print('*'); 425 | writeSpaces(ballIndex + 1, end); 426 | } 427 | 428 | public static boolean updateRightFlag(boolean isRight, int ballIndex, int width) 429 | { 430 | if (ballIndex == 0) 431 | return true; 432 | 433 | if (ballIndex == width - 1) 434 | return false; 435 | 436 | return isRight; 437 | } 438 | 439 | public static int updateBallIndex(boolean isRight, int ballIndex) 440 | { 441 | if (isRight) 442 | return ballIndex + 1; 443 | 444 | return ballIndex - 1; 445 | } 446 | 447 | public static void play(int width, int height) 448 | { 449 | int ballIndex = 0; 450 | boolean isRight = false; 451 | 452 | for (int i = 1; i <= height; ++i) { 453 | System.out.print('|'); 454 | writeBall(ballIndex, width); 455 | if (width != 1) { 456 | isRight = updateRightFlag(isRight, ballIndex, width); 457 | ballIndex = updateBallIndex(isRight, ballIndex); 458 | } 459 | System.out.println('|'); 460 | } 461 | } 462 | } 463 | ``` 464 | >5.sorunun bir çözümü 465 | > 466 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 467 | ```java 468 | package csd; 469 | 470 | class App { 471 | public static void main(String [] args) 472 | { 473 | PrintGoldbachApp.run(); 474 | } 475 | } 476 | 477 | class PrintGoldbachApp { 478 | public static void run() 479 | { 480 | java.util.Scanner kb = new java.util.Scanner(System.in); 481 | 482 | while (true) { 483 | System.out.print("2'den büyük bir çift sayı giriniz:"); 484 | int val = Integer.parseInt(kb.nextLine()); 485 | 486 | if (val == 0) 487 | break; 488 | 489 | if (val <= 2 || val % 2 != 0) { 490 | System.out.println("Geçersiz giriş -> 2'den büyük çift bir sayı girmelisiniz!..."); 491 | continue; 492 | } 493 | 494 | NumberUtil.printGoldbach(val); 495 | } 496 | } 497 | } 498 | 499 | class NumberUtil { 500 | public static void printGoldbach(int val) 501 | { 502 | for (int x = val - 1; x >= 2; --x) { 503 | int y = val - x; 504 | 505 | if (isPrime(x) && isPrime(y) && x >= y) 506 | System.out.printf("%d + %d%n", x, y); 507 | } 508 | } 509 | 510 | public static boolean isPrime(long a) 511 | { 512 | if (a <= 1) 513 | return false; 514 | 515 | if (a % 2 == 0) 516 | return a == 2; 517 | 518 | if (a % 3 == 0) 519 | return a == 3; 520 | 521 | if (a % 5 == 0) 522 | return a == 5; 523 | 524 | if (a % 7 == 0) 525 | return a == 7; 526 | 527 | for (long i = 11; i * i <= a; i += 2) 528 | if (a % i == 0) 529 | return false; 530 | 531 | return true; 532 | } 533 | } 534 | ``` 535 | 536 | #### Homework-003 537 | 538 | >1.sorunun bir çözümü 539 | > 540 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 541 | 542 | ```java 543 | package csd; 544 | 545 | class App { 546 | public static void main(String[] args) 547 | { 548 | SatisfyConditionsApp.run(); 549 | } 550 | } 551 | 552 | class SatisfyConditionsApp { 553 | public static boolean isCondition1Satisfied(int a, int b, int c) 554 | { 555 | return 100 * c + 10 * b + a > 100 * a + 10 * b + c; 556 | } 557 | 558 | public static boolean isCondition2Satisfied(int a, int b, int c) 559 | { 560 | return NumberUtil.isPrime(100 * a + 10 * b + c); 561 | } 562 | 563 | public static boolean isCondition3Satisfied(int a, int b, int c) 564 | { 565 | return NumberUtil.isPrime(100 * c + 10 * b + a); 566 | } 567 | 568 | public static boolean isCondition4Satisfied(int a, int b) 569 | { 570 | return NumberUtil.isPrime(10 * a + b); 571 | } 572 | 573 | public static boolean isCondition5Satisfied(int b, int c) 574 | { 575 | return NumberUtil.isPrime(10 * b + c); 576 | } 577 | 578 | public static boolean isCondition6Satisfied(int c, int b) 579 | { 580 | return NumberUtil.isPrime(10 * c + b); 581 | } 582 | 583 | public static boolean isCondition7Satisfied(int b, int a) 584 | { 585 | return NumberUtil.isPrime(10 * b + a); 586 | } 587 | 588 | public static boolean isAllSatisfied(int val) 589 | { 590 | int a = val / 100; 591 | int b = val / 10 % 10; 592 | int c = val % 10; 593 | 594 | return isCondition1Satisfied(a, b, c) && isCondition2Satisfied(a, b, c) && isCondition3Satisfied(a, b, c) 595 | && isCondition4Satisfied(a, b) && isCondition5Satisfied(b, c) && isCondition6Satisfied(c, b) 596 | && isCondition7Satisfied(b, a); 597 | } 598 | 599 | public static void run() 600 | { 601 | for (int val = 100; val <= 999; ++val) 602 | if (isAllSatisfied(val)) 603 | System.out.printf("%d ", val); 604 | 605 | System.out.println(); 606 | } 607 | } 608 | 609 | class NumberUtil { 610 | 611 | public static boolean isPrime(long a) 612 | { 613 | if (a <= 1) 614 | return false; 615 | 616 | if (a % 2 == 0) 617 | return a == 2; 618 | 619 | if (a % 3 == 0) 620 | return a == 3; 621 | 622 | if (a % 5 == 0) 623 | return a == 5; 624 | 625 | if (a % 7 == 0) 626 | return a == 7; 627 | 628 | for (long i = 11; i * i <= a; i += 2) 629 | if (a % i == 0) 630 | return false; 631 | 632 | return true; 633 | } 634 | } 635 | 636 | ``` 637 | 638 | >2.sorunun bir çözümü 639 | > 640 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 641 | 642 | ```java 643 | package csd; 644 | 645 | class App { 646 | public static void main(String[] args) 647 | { 648 | NumberUtilIsPrimeXTest.run(); 649 | } 650 | } 651 | 652 | class NumberUtilIsPrimeXTest { 653 | 654 | public static void run() 655 | { 656 | java.util.Scanner kb = new java.util.Scanner(System.in); 657 | 658 | System.out.print("Bir sayı giriniz:"); 659 | long n = kb.nextLong(); 660 | 661 | for (long i = 0; i <= n; ++i) 662 | if (NumberUtil.isPrimeX(i)) 663 | System.out.println(i); 664 | } 665 | } 666 | 667 | class NumberUtil { 668 | public static boolean isPrimeX(long a) 669 | { 670 | long sum = a; 671 | boolean result; 672 | 673 | while ((result = isPrime(sum)) && sum > 9) 674 | sum = sumDigits(sum); 675 | 676 | return result; 677 | } 678 | 679 | public static boolean isPrime(long a) 680 | { 681 | if (a <= 1) 682 | return false; 683 | 684 | if (a % 2 == 0) 685 | return a == 2; 686 | 687 | if (a % 3 == 0) 688 | return a == 3; 689 | 690 | if (a % 5 == 0) 691 | return a == 5; 692 | 693 | if (a % 7 == 0) 694 | return a == 7; 695 | 696 | for (long i = 11; i * i <= a; i += 2) 697 | if (a % i == 0) 698 | return false; 699 | 700 | return true; 701 | } 702 | 703 | public static int sumDigits(long a) 704 | { 705 | int total = 0; 706 | 707 | while (a != 0) { 708 | total += a % 10; 709 | a /= 10; 710 | } 711 | 712 | return Math.abs(total); 713 | } 714 | } 715 | 716 | 717 | ``` 718 | 719 | >2.sorunun bir çözümü 720 | > 721 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 722 | 723 | ```java 724 | package csd; 725 | 726 | class App { 727 | public static void main(String[] args) 728 | { 729 | NumberUtilIsPrimeXTest.run(); 730 | } 731 | } 732 | 733 | class NumberUtilIsPrimeXTest { 734 | 735 | public static void run() 736 | { 737 | java.util.Scanner kb = new java.util.Scanner(System.in); 738 | 739 | System.out.print("Bir sayı giriniz:"); 740 | long n = kb.nextLong(); 741 | 742 | for (long i = 0; i <= n; ++i) 743 | if (NumberUtil.isPrimeX(i)) 744 | System.out.println(i); 745 | } 746 | } 747 | 748 | class NumberUtil { 749 | public static boolean isPrimeX(long a) 750 | { 751 | boolean result; 752 | 753 | for (long sum = a; (result = isPrime(sum)) && sum > 9; sum = sumDigits(sum)) 754 | ; 755 | 756 | return result; 757 | } 758 | 759 | public static boolean isPrime(long a) 760 | { 761 | if (a <= 1) 762 | return false; 763 | 764 | if (a % 2 == 0) 765 | return a == 2; 766 | 767 | if (a % 3 == 0) 768 | return a == 3; 769 | 770 | if (a % 5 == 0) 771 | return a == 5; 772 | 773 | if (a % 7 == 0) 774 | return a == 7; 775 | 776 | for (long i = 11; i * i <= a; i += 2) 777 | if (a % i == 0) 778 | return false; 779 | 780 | return true; 781 | } 782 | 783 | public static int sumDigits(long a) 784 | { 785 | int total = 0; 786 | 787 | while (a != 0) { 788 | total += a % 10; 789 | a /= 10; 790 | } 791 | 792 | return Math.abs(total); 793 | } 794 | } 795 | ``` 796 | 797 | >3.sorunun bir çözümü 798 | > 799 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 800 | 801 | ```java 802 | package csd; 803 | 804 | class App { 805 | public static void main(String[] args) 806 | { 807 | NumberUtilCalculateDigitalRootTest.run(); 808 | } 809 | } 810 | 811 | class NumberUtilCalculateDigitalRootTest { 812 | 813 | public static void run() 814 | { 815 | java.util.Scanner kb = new java.util.Scanner(System.in); 816 | 817 | System.out.print("Bir sayı giriniz:"); 818 | int n = kb.nextInt(); 819 | 820 | for (int i = 0; i <= n; ++i) 821 | System.out.printf("%d -> %d%n", i, NumberUtil.calculateDigitalRoot(i)); 822 | } 823 | } 824 | 825 | class NumberUtil { 826 | public static int calculateDigitalRoot(int a) 827 | { 828 | int root = Math.abs(a); 829 | 830 | while (root > 9) 831 | root = sumDigits(root); 832 | 833 | return root; 834 | } 835 | 836 | public static int sumDigits(long a) 837 | { 838 | int total = 0; 839 | 840 | while (a != 0) { 841 | total += a % 10; 842 | a /= 10; 843 | } 844 | 845 | return Math.abs(total); 846 | } 847 | } 848 | 849 | ``` 850 | 851 | >4.sorunun bir çözümü 852 | > 853 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 854 | 855 | ```java 856 | package csd; 857 | 858 | class App { 859 | public static void main(String[] args) 860 | { 861 | NumberUtilIsFactorianTest.run(); 862 | } 863 | } 864 | 865 | class NumberUtilIsFactorianTest { 866 | public static void run() 867 | { 868 | java.util.Scanner kb = new java.util.Scanner(System.in); 869 | 870 | System.out.print("Bir sayı giriniz:"); 871 | int n = kb.nextInt(); 872 | 873 | for (int i = 0; i <= n; ++i) 874 | if (NumberUtil.isFactorian(i)) 875 | System.out.printf("%d ", i); 876 | 877 | System.out.println(); 878 | } 879 | } 880 | 881 | class NumberUtil { 882 | public static boolean isFactorian(int n) 883 | { 884 | return n > 0 && sumFactorialOfDigits(n) == n; 885 | } 886 | 887 | public static int sumFactorialOfDigits(int n) 888 | { 889 | int total = 0; 890 | 891 | while (n != 0) { 892 | total += factorial(n % 10); 893 | n /= 10; 894 | } 895 | 896 | return total; 897 | } 898 | 899 | public static int factorial(int n) 900 | { 901 | int result = 1; 902 | 903 | for (int i = 2; i <= n; ++i) 904 | result *= i; 905 | 906 | return result; 907 | } 908 | } 909 | ``` 910 | 911 | >5.sorunun bir çözümü 912 | > 913 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 914 | 915 | ```java 916 | package csd; 917 | 918 | class App { 919 | public static void main(String[] args) 920 | { 921 | NumberUtilIsSuperPrimeTest.run(); 922 | } 923 | } 924 | 925 | class NumberUtilIsSuperPrimeTest { 926 | public static void run() 927 | { 928 | java.util.Scanner kb = new java.util.Scanner(System.in); 929 | 930 | System.out.print("Bir sayı giriniz:"); 931 | long n = kb.nextLong(); 932 | 933 | for (long i = 0; i <= n; ++i) 934 | if (NumberUtil.isSuperPrime(i)) 935 | System.out.printf("%d ", i); 936 | 937 | System.out.println(); 938 | } 939 | } 940 | 941 | class NumberUtil { 942 | public static boolean isSuperPrime(long a) 943 | { 944 | return isPrime(a) && isPrime(indexOfPrime(a)); 945 | } 946 | 947 | public static int indexOfPrime(long a) 948 | { 949 | int i = 1; 950 | long val = 2; 951 | 952 | while (true) { 953 | if (val == a) 954 | return i; 955 | 956 | if (isPrime(val)) 957 | ++i; 958 | 959 | ++val; 960 | } 961 | } 962 | 963 | public static boolean isPrime(long a) 964 | { 965 | if (a <= 1) 966 | return false; 967 | 968 | if (a % 2 == 0) 969 | return a == 2; 970 | 971 | if (a % 3 == 0) 972 | return a == 3; 973 | 974 | if (a % 5 == 0) 975 | return a == 5; 976 | 977 | if (a % 7 == 0) 978 | return a == 7; 979 | 980 | for (long i = 11; i * i <= a; i += 2) 981 | if (a % i == 0) 982 | return false; 983 | 984 | return true; 985 | } 986 | } 987 | 988 | ``` 989 | 990 | >6.sorunun bir çözümü 991 | > 992 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 993 | 994 | ```java 995 | package csd; 996 | 997 | class App { 998 | public static void main(String[] args) 999 | { 1000 | FindHardyRamanujanNumbersApp.run(); 1001 | } 1002 | } 1003 | 1004 | class FindHardyRamanujanNumbersApp { 1005 | public static void run() 1006 | { 1007 | for (int n = 1; n < 100_000; ++n) 1008 | if (NumberUtil.isHardyRamanujan(n)) 1009 | System.out.printf("%d ", n); 1010 | 1011 | System.out.println(); 1012 | } 1013 | } 1014 | 1015 | class NumberUtil { 1016 | public static boolean isHardyRamanujan(int n) 1017 | { 1018 | return n > 0 && countHardyRamanujan(n) == 2; 1019 | } 1020 | 1021 | public static int countHardyRamanujan(int n) 1022 | { 1023 | int count = 0; 1024 | 1025 | EXIT_LOOP: 1026 | for (int x = 1; x * x * x < n; ++x) 1027 | for (int y = x + 1; x * x * x + y * y * y <= n; ++y) { 1028 | if (x * x * x + y * y * y == n) { 1029 | if (++count == 2) 1030 | break EXIT_LOOP; 1031 | 1032 | ++x; 1033 | } 1034 | } 1035 | 1036 | return count; 1037 | } 1038 | } 1039 | ``` 1040 | 1041 | >7.sorunun bir çözümü 1042 | > 1043 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 1044 | 1045 | ```java 1046 | package csd; 1047 | 1048 | class App { 1049 | public static void main(String[] args) 1050 | { 1051 | NumberUtilIsDecimalHarshadTest.run(); 1052 | } 1053 | } 1054 | 1055 | class NumberUtilIsDecimalHarshadTest { 1056 | public static void run() 1057 | { 1058 | java.util.Scanner kb = new java.util.Scanner(System.in); 1059 | 1060 | System.out.print("Bir sayı giriniz:"); 1061 | int n = kb.nextInt(); 1062 | 1063 | for (int i = 0; i <= n; ++i) 1064 | if (NumberUtil.isDecimalHarshad(i)) 1065 | System.out.println(i); 1066 | 1067 | System.out.println(); 1068 | } 1069 | } 1070 | 1071 | class NumberUtil { 1072 | public static boolean isDecimalHarshad(int a) 1073 | { 1074 | return a > 0 && a % sumDigits(a) == 0; 1075 | } 1076 | 1077 | public static int sumDigits(long a) 1078 | { 1079 | int total = 0; 1080 | 1081 | while (a != 0) { 1082 | total += a % 10; 1083 | a /= 10; 1084 | } 1085 | 1086 | return Math.abs(total); 1087 | } 1088 | } 1089 | ``` 1090 | 1091 | >8.sorunun bir çözümü 1092 | > 1093 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 1094 | 1095 | ```java 1096 | package csd; 1097 | 1098 | class App { 1099 | public static void main(String[] args) 1100 | { 1101 | NumberUtilPrintCollatzTest.run(); 1102 | } 1103 | } 1104 | 1105 | class NumberUtilPrintCollatzTest { 1106 | public static void run() 1107 | { 1108 | java.util.Scanner kb = new java.util.Scanner(System.in); 1109 | 1110 | while (true) { 1111 | System.out.print("Bir sayı giriniz:"); 1112 | int n = kb.nextInt(); 1113 | 1114 | if (n == 0) 1115 | break; 1116 | 1117 | System.out.println("-------------------------------"); 1118 | NumberUtil.printCollatz(n); 1119 | System.out.println("-------------------------------"); 1120 | } 1121 | } 1122 | } 1123 | 1124 | class NumberUtil { 1125 | public static void printCollatz(int n) 1126 | { 1127 | if (n <= 0) { 1128 | System.out.println("Geçersiz sayı!..."); 1129 | return; 1130 | } 1131 | 1132 | System.out.println(n); 1133 | 1134 | while (n != 1) { 1135 | if (n % 2 == 0) 1136 | n /= 2; 1137 | else 1138 | n = 3 * n + 1; 1139 | 1140 | System.out.println(n); 1141 | } 1142 | } 1143 | } 1144 | ``` 1145 | 1146 | #### Homework-004 1147 | 1148 | >Sorunun bir çözümü 1149 | > 1150 | >**Not:** Çözüm, çalışma sorusunun verildiği tarihe kadar işlenmiş konular kullanılarak yazılmıştır 1151 | >**Açıklama:** Soruda birden fazla `Scanner` nesnesi yaratılmaması için ve sorunun verildiği tarihte `referans parametreli metotlar` ele alınmadığı için çözüm az metot kullanılarak yazılmıştır. 1152 | 1153 | ```java 1154 | package csd; 1155 | 1156 | class App { 1157 | public static void main(String[] args) 1158 | { 1159 | CalculateTotalMinMaxCountAverageApp.run(); 1160 | } 1161 | } 1162 | 1163 | class CalculateTotalMinMaxCountAverageApp { 1164 | public static void printReport(int total, int count, int min, int max) 1165 | { 1166 | System.out.printf("Toplam %d değer girildi%n", count); 1167 | System.out.printf("Max:%d%nMin:%d%nOrtalama:%.6f%n", max, min, (double)total / count); 1168 | } 1169 | 1170 | public static void run() 1171 | { 1172 | java.util.Scanner kb = new java.util.Scanner(System.in); 1173 | 1174 | int total, count, min, max; 1175 | 1176 | total = count = 0; 1177 | max = 0; 1178 | min = 100; 1179 | 1180 | while (true) { 1181 | int val; 1182 | 1183 | while (true) { 1184 | System.out.print("Bir tamsayı giriniz:"); 1185 | val = Integer.parseInt(kb.nextLine()); 1186 | 1187 | if (0 <= val && val <= 100) 1188 | break; 1189 | 1190 | System.out.println("Geçersiz değer girdiniz!...Yeni bir değer giriniz:"); 1191 | } 1192 | 1193 | ++count; 1194 | total += val; 1195 | min = Math.min(min, val); 1196 | max = Math.max(max, val); 1197 | 1198 | System.out.println("Yeni bir değer girmek istiyor musunuz? [Evet için 1(bir) Hayır için 0(sıfır) değerlerinden birini giriniz]"); 1199 | 1200 | int option; 1201 | 1202 | do 1203 | option = Integer.parseInt(kb.nextLine()); 1204 | while (option != 0 && option != 1); 1205 | 1206 | if (option == 0) 1207 | break; 1208 | } 1209 | 1210 | printReport(total, count, min, max); 1211 | } 1212 | } 1213 | ``` 1214 | -------------------------------------------------------------------------------- /homework/sudoku.txt: -------------------------------------------------------------------------------- 1 | 3 6 7 5 1 9 8 4 2 2 | 8 4 2 3 7 6 9 1 5 3 | 5 9 1 4 8 2 7 6 3 4 | 5 | 1 8 5 9 2 4 3 7 6 6 | 9 3 6 7 5 1 2 8 4 7 | 2 7 4 6 3 8 5 9 1 8 | 9 | 6 2 3 8 4 7 1 5 9 10 | 4 5 8 1 9 3 6 2 7 11 | 7 1 9 2 6 5 4 3 8 -------------------------------------------------------------------------------- /src/Sample/.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 -------------------------------------------------------------------------------- /src/Sample/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /src/Sample/.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /src/Sample/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Sample/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Sample/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Sample/Sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Sample/question: -------------------------------------------------------------------------------- 1 | package org.csystem.app; 2 | 3 | import org.csystem.util.console.Console; 4 | 5 | class App { 6 | public static void main(String[] args) 7 | { 8 | Object o = 12; //Integer.valueOf(12) 9 | long val; 10 | 11 | val = (long)o; //((Long)o).longValue(); 12 | 13 | Console.writeLine("val = %d", val); 14 | } 15 | } 16 | 17 | Bu kod için aşağıdakilerden hangisi doğrudur 18 | 19 | 1. Sentaks hatası vardır. Nedeni ... 20 | 2. Ekrana val = 12 yazılır 21 | 3. Exception oluşur. Nedeni ... 22 | 4. Hiçbiri. Ne olur?... -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/App.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app; 2 | 3 | class App { 4 | public static void main(String[] args) 5 | { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/datetime/DateAppEN.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.datetime; 2 | 3 | import java.util.Scanner; 4 | 5 | class DateAppEN { 6 | public static void run() 7 | { 8 | Scanner kb = new Scanner(System.in); 9 | 10 | System.out.print("Input day month and year values:"); 11 | int day = kb.nextInt(); 12 | int month = kb.nextInt(); 13 | int year = kb.nextInt(); 14 | 15 | DateUtil.printDateEN(day, month, year); 16 | } 17 | 18 | public static void main(String[] args) 19 | { 20 | run(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/datetime/DateAppTR.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.datetime; 2 | 3 | import java.util.Scanner; 4 | 5 | class DateAppTR { 6 | public static void run() 7 | { 8 | Scanner kb = new Scanner(System.in); 9 | 10 | System.out.print("Gün, ay ve yıl bilgilerini giriniz:"); 11 | int day = kb.nextInt(); 12 | int month = kb.nextInt(); 13 | int year = kb.nextInt(); 14 | 15 | DateUtil.printDateTR(day, month, year); 16 | } 17 | 18 | public static void main(String[] args) 19 | { 20 | run(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/datetime/DateUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.datetime; 2 | 3 | public class DateUtil { 4 | public static int [] daysOfMonths = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 5 | public static String [] daysOfWeekTR = {"Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi"}; 6 | public static String [] monthsTR = {"", "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", 7 | "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"}; 8 | public static String [] daysOfWeekEN = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 9 | public static String [] monthsEN = {"", "January", "February", "March", "April", "May", "June", "July", 10 | "August", "September", "October", "November", "December"}; 11 | 12 | public static void printDateTR(int day, int month, int year) 13 | { 14 | String dateStr = getLongDateTR(day, month, year); 15 | 16 | if (!dateStr.isEmpty()) 17 | System.out.println(dateStr); 18 | else 19 | System.out.println("Geçersiz tarih"); 20 | } 21 | 22 | public static void printDateEN(int day, int month, int year) 23 | { 24 | String dateStr = getLongDateEN(day, month, year); 25 | 26 | if (!dateStr.isEmpty()) 27 | System.out.println(dateStr); 28 | else 29 | System.out.println("Invalid date"); 30 | } 31 | 32 | public static String getLongDateEN(int day, int month, int year) 33 | { 34 | int dayOfWeek = getDayOfWeek(day, month, year); 35 | 36 | return dayOfWeek != -1 ? "%d%s %s %d %s".formatted(day, getDaySuffix(day), monthsEN[month], year, daysOfWeekEN[dayOfWeek]) : ""; 37 | } 38 | 39 | public static String getLongDateTR(int day, int month, int year) 40 | { 41 | int dayOfWeek = getDayOfWeek(day, month, year); 42 | 43 | return dayOfWeek != -1 ? "%d %s %d %s%n".formatted(day, monthsTR[month], year, daysOfWeekTR[dayOfWeek]) : ""; 44 | } 45 | 46 | public static int getDayOfWeek(int day, int month, int year) 47 | { 48 | int totalDays; 49 | 50 | if (year < 1900 || (totalDays = getDayOfYear(day, month, year)) == -1) 51 | return -1; 52 | 53 | for (int y = 1900; y < year; ++y) 54 | totalDays += isLeapYear(y) ? 366 : 365; 55 | 56 | return totalDays % 7; 57 | } 58 | 59 | public static int getDayOfYear(int day, int month, int year) 60 | { 61 | if (!isValidDate(day, month, year)) 62 | return -1; 63 | 64 | return getDayOfYearValue(day, month, year); 65 | } 66 | 67 | public static int getDayOfYearValue(int day, int month, int year) 68 | { 69 | int dayOfYear = day; 70 | 71 | for (int m = month - 1; m >= 1; --m) 72 | dayOfYear += getDays(m, year); 73 | 74 | return dayOfYear; 75 | } 76 | 77 | public static boolean isValidDate(int day, int month, int year) 78 | { 79 | return 1 <= day && day <= 31 && 1 <= month && month <= 12 && day <= getDays(month, year); 80 | } 81 | 82 | public static String getDaySuffix(int day) 83 | { 84 | return switch (day) { 85 | case 1, 21, 31 -> "st"; 86 | case 2, 22 -> "nd"; 87 | case 3, 23 -> "rd"; 88 | default -> "th"; 89 | }; 90 | } 91 | 92 | public static int getDays(int month, int year) 93 | { 94 | return month == 2 && isLeapYear(year) ? 29 : daysOfMonths[month]; 95 | } 96 | 97 | public static boolean isLeapYear(int year) 98 | { 99 | return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; 100 | } 101 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/game/banner/ballfall/BallFallApp.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.game.banner.ballfall; 2 | 3 | import org.csystem.game.banner.ballfall.BallFall; 4 | 5 | class BallFallApp { 6 | public static void run() 7 | { 8 | java.util.Scanner kb = new java.util.Scanner(System.in); 9 | 10 | BallFall ballFall = new BallFall(); 11 | 12 | while (true) { 13 | System.out.print("Input width and height:"); 14 | int width = kb.nextInt(); 15 | int height = kb.nextInt(); 16 | 17 | if (width == 0 || height == 0) 18 | break; 19 | 20 | ballFall.play(width, height); 21 | 22 | System.out.println(ballFall.getShape()); 23 | } 24 | } 25 | 26 | public static void main(String[] args) 27 | { 28 | run(); 29 | } 30 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/game/lottery/NumericLotteryApp.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.game.lottery; 2 | 3 | import org.csystem.game.lottery.NumericLottery; 4 | import org.csystem.util.array.ArrayUtil; 5 | 6 | import java.util.Random; 7 | import java.util.Scanner; 8 | 9 | public class NumericLotteryApp { 10 | public static void run() 11 | { 12 | Random random = new Random(); 13 | Scanner kb = new Scanner(System.in); 14 | NumericLottery numericLottery = new NumericLottery(random); 15 | 16 | while (true) { 17 | System.out.print("Input count:"); 18 | int count = Integer.parseInt(kb.nextLine()); 19 | 20 | if (count <= 0) 21 | break; 22 | 23 | ArrayUtil.print(numericLottery.getNumbers(count), 2); 24 | } 25 | } 26 | 27 | public static void main(String[] args) 28 | { 29 | run(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/generator/DemoObjectArrayGeneratorApp.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.generator; 2 | 3 | import org.csystem.math.Complex; 4 | import org.csystem.math.geometry.Circle; 5 | import org.csystem.math.geometry.Point; 6 | import org.csystem.random.generator.ObjectArrayGenerator; 7 | import org.csystem.util.console.Console; 8 | 9 | import java.util.Random; 10 | 11 | public class DemoObjectArrayGeneratorApp { 12 | public static void run() 13 | { 14 | int count = Console.readInt("Input count:"); 15 | 16 | ObjectArrayGenerator generator = new ObjectArrayGenerator(); 17 | 18 | for (Object o : generator.createObjectArray(count)) { 19 | Console.writeLine("----------------------------------------------------"); 20 | Console.writeLine("Dynamic type: %s", o.getClass().getName()); 21 | 22 | switch (o) { 23 | case Point p -> Console.writeLine("Distance to origin of %s is %f", p.toString(), p.euclideanDistance()); 24 | case Complex c -> Console.writeLine("Norm of %s is %f", c.toString(), c.getNorm()); 25 | case Circle c -> Console.writeLine("Radius:%f, Area:%f", c.getRadius(), c.getArea()); 26 | case String s -> Console.writeLine("Text:%s, Upper:%s", s, s.toUpperCase()); 27 | case Integer i -> {int a = i; Console.writeLine("%d * %d = %d", a, a, a * a);} 28 | case Character c -> {char ch = c; Console.writeLine("ch = %c, lower: %c", ch, Character.toLowerCase(ch));} 29 | case Double d -> {double a = d; Console.writeLine("%f + %f = %f", a, a, a + a);} 30 | case Boolean b -> {boolean flag = b; Console.writeLine("flag = %b, !flag = %b", flag, !flag);} 31 | default -> {Random random = (Random) o; Console.writeLine("Random number:%d", random.nextInt()); } 32 | } 33 | 34 | Console.writeLine("----------------------------------------------------"); 35 | } 36 | } 37 | 38 | public static void main(String[] args) 39 | { 40 | run(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/school/grade/GradeCalculator.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.school.grade; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class GradeCalculator { 6 | private final String m_dataStr; 7 | 8 | public GradeCalculator(String str) 9 | { 10 | //... 11 | m_dataStr = str; 12 | } 13 | 14 | public GradeInfo getGradeInfo() 15 | { 16 | String [] gradeInfo = StringUtil.split(m_dataStr, ":"); 17 | 18 | GradeInfo gi = new GradeInfo(); 19 | 20 | gi.setStudentNumber(gradeInfo[0]); 21 | gi.setStudentName(gradeInfo[1]); 22 | gi.setBirthDate(gradeInfo[2]); 23 | gi.setLectureName(gradeInfo[3]); 24 | gi.setMidTermGrade(Integer.parseInt(gradeInfo[4])); 25 | gi.setFinalGrade(Integer.parseInt(gradeInfo[5])); 26 | 27 | return gi; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/school/grade/GradeCalculatorApp.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.school.grade; 2 | 3 | import org.csystem.app.datetime.DateUtil; 4 | import org.csystem.util.string.StringUtil; 5 | 6 | import java.util.Scanner; 7 | 8 | public class GradeCalculatorApp { 9 | public static void printGradeInfo(GradeInfo gi) 10 | { 11 | String [] birthDateInfo = StringUtil.split(gi.getBirthDate(), "-"); 12 | String birthDateStr = DateUtil.getLongDateEN(Integer.parseInt(birthDateInfo[2]), 13 | Integer.parseInt(birthDateInfo[1]), Integer.parseInt(birthDateInfo[0])); 14 | 15 | System.out.println("Student Information:"); 16 | System.out.printf("Number: %s%n", gi.getStudentNumber()); 17 | System.out.printf("Name: %s%n", gi.getStudentName()); 18 | System.out.printf("Birth Date: %s%n", birthDateStr); 19 | System.out.printf("Lecture Name: %s%n", gi.getLectureName()); 20 | System.out.printf("Midterm Grade: %d%n", gi.getMidTermGrade()); 21 | System.out.printf("Final Grade: %d%n", gi.getFinalGrade()); 22 | System.out.printf("Grade: %.1f%n", gi.getGrade()); 23 | System.out.printf("Status: %s%n", gi.isSuccess() ? "Success" : "Fail"); 24 | } 25 | 26 | public static void run() 27 | { 28 | Scanner kb = new Scanner(System.in); 29 | 30 | System.out.print("Input data:"); 31 | GradeCalculator gc = new GradeCalculator(kb.nextLine()); 32 | 33 | GradeInfo gi = gc.getGradeInfo(); 34 | 35 | printGradeInfo(gi); 36 | } 37 | 38 | public static void main(String[] args) 39 | { 40 | run(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/school/grade/GradeInfo.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.school.grade; 2 | 3 | public class GradeInfo { 4 | private String m_studentNumber; 5 | private String m_studentName; 6 | private String m_birthDate; 7 | private String m_lectureName; 8 | private int m_midTermGrade; 9 | private int m_finalGrade; 10 | 11 | public String getStudentNumber() 12 | { 13 | return m_studentNumber; 14 | } 15 | 16 | public void setStudentNumber(String studentNumber) 17 | { 18 | m_studentNumber = studentNumber; 19 | } 20 | 21 | public String getStudentName() 22 | { 23 | return m_studentName; 24 | } 25 | 26 | public void setStudentName(String studentName) 27 | { 28 | m_studentName = studentName; 29 | } 30 | 31 | public String getBirthDate() 32 | { 33 | return m_birthDate; 34 | } 35 | 36 | public void setBirthDate(String birthDate) 37 | { 38 | m_birthDate = birthDate; 39 | } 40 | 41 | public String getLectureName() 42 | { 43 | return m_lectureName; 44 | } 45 | 46 | public void setLectureName(String lectureName) 47 | { 48 | m_lectureName = lectureName; 49 | } 50 | 51 | public int getMidTermGrade() 52 | { 53 | return m_midTermGrade; 54 | } 55 | 56 | public void setMidTermGrade(int midTermGrade) 57 | { 58 | m_midTermGrade = midTermGrade; 59 | } 60 | 61 | public int getFinalGrade() 62 | { 63 | return m_finalGrade; 64 | } 65 | 66 | public void setFinalGrade(int finalGrade) 67 | { 68 | m_finalGrade = finalGrade; 69 | } 70 | 71 | public double getGrade() 72 | { 73 | return m_midTermGrade * 0.4 + m_finalGrade * 0.6; 74 | } 75 | 76 | public boolean isSuccess() 77 | { 78 | return getGrade() >= 50; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/simulation/exam/ExamInfo.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.simulation.exam; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ExamInfo { 6 | private final String m_lectureName; 7 | private final int [][] m_grades; 8 | private final double [] m_averages; 9 | private double m_totalAverage; 10 | 11 | public ExamInfo(String lectureName, int n) 12 | { 13 | m_lectureName = lectureName; 14 | m_grades = new int[n][]; 15 | m_averages = new double[n]; 16 | } 17 | 18 | public String getLectureName() 19 | { 20 | return m_lectureName; 21 | } 22 | 23 | public int getNumberOfClasses() 24 | { 25 | return m_grades.length; 26 | } 27 | 28 | public int getNumberOfStudents(int i) 29 | { 30 | return m_grades[i].length; 31 | } 32 | 33 | public void setNumberOfStudents(int i, int count) 34 | { 35 | m_grades[i] = new int[count]; 36 | } 37 | 38 | public int getGrade(int i, int k) 39 | { 40 | return m_grades[i][k]; 41 | } 42 | 43 | public void setGrade(int i, int k, int grade) 44 | { 45 | m_grades[i][k] = grade; 46 | } 47 | 48 | public double getTotalAverage() 49 | { 50 | return m_totalAverage; 51 | } 52 | 53 | public double getAverage(int i) 54 | { 55 | return m_averages[i]; 56 | } 57 | 58 | public void run() 59 | { 60 | int totalNumberOfStudents = 0; 61 | int totalGrades = 0; 62 | 63 | for (int i = 0; i < m_grades.length; ++i) { 64 | int total = (int)ArrayUtil.sum(m_grades[i]); 65 | 66 | m_averages[i] = (double)total / m_grades[i].length; 67 | totalNumberOfStudents += m_grades[i].length; 68 | totalGrades += total; 69 | } 70 | 71 | m_totalAverage = (double)totalGrades / totalNumberOfStudents; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/simulation/exam/ExamSimulation.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.simulation.exam; 2 | 3 | import java.util.Random; 4 | import java.util.Scanner; 5 | 6 | public class ExamSimulation { 7 | public static void set(ExamInfo examInfo, Scanner kb) 8 | { 9 | Random random = new Random(); 10 | 11 | for (int i = 0; i < examInfo.getNumberOfClasses(); ++i) { 12 | System.out.printf("Input number of student of class %d:", i + 1); 13 | examInfo.setNumberOfStudents(i, Integer.parseInt(kb.nextLine())); 14 | 15 | for (int k = 0; k < examInfo.getNumberOfStudents(i); ++k) 16 | examInfo.setGrade(i, k, random.nextInt(0, 11)); 17 | } 18 | } 19 | 20 | public static void printGrades(ExamInfo examInfo) 21 | { 22 | for (int i = 0; i < examInfo.getNumberOfClasses(); ++i) { 23 | int numberOfStudents = examInfo.getNumberOfStudents(i); 24 | System.out.printf("Class %d (%d student) -> ", i + 1, numberOfStudents); 25 | for (int k = 0; k < numberOfStudents; ++k) 26 | System.out.printf("%02d ", examInfo.getGrade(i, k)); 27 | 28 | System.out.println(); 29 | } 30 | } 31 | 32 | public static void printReport(ExamInfo examInfo) 33 | { 34 | System.out.printf("Report of '%s':%n", examInfo.getLectureName()); 35 | printGrades(examInfo); 36 | examInfo.run(); 37 | for (int i = 0; i < examInfo.getNumberOfClasses(); ++i) 38 | System.out.printf("Average of Class is %f%n", examInfo.getAverage(i)); 39 | 40 | System.out.printf("Total average is %f%n", examInfo.getTotalAverage()); 41 | } 42 | 43 | public static void run() 44 | { 45 | System.out.print("Input number of classes:"); 46 | Scanner kb = new Scanner(System.in); 47 | ExamInfo examInfo = new ExamInfo("Mathematics", Integer.parseInt(kb.nextLine())); 48 | 49 | set(examInfo, kb); 50 | printReport(examInfo); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/simulation/exam/ExamSimulationApp.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.simulation.exam; 2 | 3 | public class ExamSimulationApp { 4 | public static void main(String[] args) 5 | { 6 | ExamSimulation.run(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/string/store/ConcatWithHyphenApp.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.string.store; 2 | 3 | import org.csystem.util.console.Console; 4 | 5 | public class ConcatWithHyphenApp { 6 | public static void run() 7 | { 8 | StringBuilder sb = new StringBuilder(); 9 | 10 | Console.writeLine("Length:%d", sb.length()); 11 | Console.writeLine("Capacity:%d", sb.capacity()); 12 | Console.writeLine("----------------------------------"); 13 | 14 | while (true) { 15 | String s = Console.readString("Input a text:"); 16 | 17 | if ("exit".equals(s)) 18 | break; 19 | 20 | sb.append(s).append('-'); 21 | 22 | Console.writeLine("Length:%d", sb.length()); 23 | Console.writeLine("Capacity:%d", sb.capacity()); 24 | Console.writeLine("----------------------------------"); 25 | } 26 | sb.deleteCharAt(sb.length() - 1); 27 | Console.writeLine("Length:%d", sb.length()); 28 | Console.writeLine("Capacity:%d", sb.capacity()); 29 | } 30 | 31 | public static void main(String[] args) 32 | { 33 | run(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/app/string/store/StoreStringsApp.java: -------------------------------------------------------------------------------- 1 | package org.csystem.app.string.store; 2 | 3 | import org.csystem.util.console.Console; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class StoreStringsApp { 8 | public static void run() 9 | { 10 | ArrayList texts = new ArrayList(4); 11 | 12 | while (true) { 13 | String s = Console.readString("Input a text:"); 14 | 15 | if ("exit".equals(s)) 16 | break; 17 | 18 | texts.add(s); 19 | } 20 | 21 | for (Object o : texts) 22 | Console.writeLine((String)o); 23 | } 24 | 25 | public static void main(String[] args) 26 | { 27 | run(); 28 | } 29 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/datetime/DayOfWeek.java: -------------------------------------------------------------------------------- 1 | package org.csystem.datetime; 2 | 3 | /** 4 | * enum class that represents day of week 5 | * Last Update: 9th August 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | public enum DayOfWeek { 9 | SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY 10 | } 11 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/datetime/Month.java: -------------------------------------------------------------------------------- 1 | package org.csystem.datetime; 2 | 3 | 4 | /** 5 | * Enumeration class that represents month 6 | * Last Update: 9th August 2025 7 | * @author Java-Sep-2024 Group 8 | */ 9 | public enum Month { 10 | JANUARY(31), FEBRUARY(28), MARCH(31), APRIL(30), MAY(31), JUNE(30), 11 | JULY(31), AUGUST(31), SEPTEMBER(30), OCTOBER(31), NOVEMBER(30), DECEMBER(31); 12 | private final int m_days; 13 | 14 | Month(int days) 15 | { 16 | m_days = days; 17 | } 18 | 19 | static boolean isLeapYear(int year) 20 | { 21 | return year % 4 == 0 && year % 100 != 0 || year % 400 == 0; 22 | } 23 | 24 | public int getDays(int year) 25 | { 26 | return isLeapYear(year) && ordinal() == 1 ? 29 : m_days; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/game/banner/ballfall/BallFall.java: -------------------------------------------------------------------------------- 1 | package org.csystem.game.banner.ballfall; 2 | 3 | public class BallFall { 4 | private String m_shape; 5 | 6 | private static void writeSpaces(StringBuilder sb, int begin, int end) 7 | { 8 | sb.append(" ".repeat(Math.max(0, end - begin))); 9 | } 10 | 11 | private static void writeBall(StringBuilder sb, int ballIndex, int end) 12 | { 13 | writeSpaces(sb, 0, ballIndex); 14 | sb.append('*'); 15 | writeSpaces(sb, ballIndex + 1, end); 16 | } 17 | 18 | private static boolean updateRightFlag(boolean isRight, int ballIndex, int width) 19 | { 20 | if (ballIndex == 0) 21 | return true; 22 | 23 | if (ballIndex == width - 1) 24 | return false; 25 | 26 | return isRight; 27 | } 28 | 29 | private static int updateBallIndex(boolean isRight, int ballIndex) 30 | { 31 | if (isRight) 32 | return ballIndex + 1; 33 | 34 | return ballIndex - 1; 35 | } 36 | 37 | public String getShape() 38 | { 39 | return m_shape; 40 | } 41 | 42 | public void play(int width, int height) 43 | { 44 | StringBuilder sb = new StringBuilder(); 45 | int ballIndex = 0; 46 | boolean isRight = false; 47 | 48 | for (int i = 1; i <= height; ++i) { 49 | sb.append('|'); 50 | writeBall(sb, ballIndex, width); 51 | if (width != 1) { 52 | isRight = updateRightFlag(isRight, ballIndex, width); 53 | ballIndex = updateBallIndex(isRight, ballIndex); 54 | } 55 | sb.append('|').append("\r\n"); 56 | } 57 | 58 | m_shape = sb.toString(); 59 | } 60 | 61 | public String toString() 62 | { 63 | return m_shape; 64 | } 65 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/game/card/Card.java: -------------------------------------------------------------------------------- 1 | package org.csystem.game.card; 2 | 3 | public class Card { 4 | private CardType m_cardType; 5 | private CardValue m_cardValue; 6 | 7 | public Card(CardType cardType, CardValue cardValue) 8 | { 9 | m_cardType = cardType; 10 | m_cardValue = cardValue; 11 | } 12 | 13 | public CardType getCardType() 14 | { 15 | return m_cardType; 16 | } 17 | 18 | public void setCardType(CardType cardType) 19 | { 20 | m_cardType = cardType; 21 | } 22 | 23 | public CardValue getCardValue() 24 | { 25 | return m_cardValue; 26 | } 27 | 28 | public void setCardValue(CardValue cardValue) 29 | { 30 | m_cardValue = cardValue; 31 | } 32 | 33 | public String toString() 34 | { 35 | return "%s-%s".formatted(m_cardType.toString(), m_cardValue.toString()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/game/card/CardType.java: -------------------------------------------------------------------------------- 1 | package org.csystem.game.card; 2 | 3 | public enum CardType { 4 | SPADE, CLUB, HEART, DIAMOND 5 | } 6 | 7 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/game/card/CardValue.java: -------------------------------------------------------------------------------- 1 | package org.csystem.game.card; 2 | 3 | public enum CardValue { 4 | TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, KNAVE, QUEEN, KING, ACE 5 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/game/card/RandomCardGenerator.java: -------------------------------------------------------------------------------- 1 | package org.csystem.game.card; 2 | 3 | import java.util.Random; 4 | 5 | public class RandomCardGenerator { 6 | private static final CardType [] CARD_TYPES = CardType.values(); 7 | private static final CardValue [] CARD_VALUES = CardValue.values(); 8 | private final Random m_random; 9 | 10 | public RandomCardGenerator(Random random) 11 | { 12 | m_random = random; 13 | } 14 | 15 | public Card createCard() 16 | { 17 | return new Card(CARD_TYPES[m_random.nextInt(CARD_TYPES.length)], CARD_VALUES[m_random.nextInt(CARD_VALUES.length)]); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/game/lottery/NumericLottery.java: -------------------------------------------------------------------------------- 1 | package org.csystem.game.lottery; 2 | 3 | import java.util.Random; 4 | 5 | public class NumericLottery { 6 | private final Random m_random; 7 | 8 | public static int [] getColumns(boolean [] flags) 9 | { 10 | int [] column = new int[6]; 11 | 12 | int idx = 0; 13 | 14 | for (int i = 1; i < flags.length; ++i) 15 | if (flags[i]) 16 | column[idx++] = i; 17 | 18 | return column; 19 | } 20 | 21 | public boolean [] getFlags() 22 | { 23 | boolean [] flags = new boolean[50]; 24 | 25 | for (int i = 0; i < 6; ++i) { 26 | int val; 27 | 28 | while (true) { 29 | val = m_random.nextInt(1, 50); 30 | 31 | if (!flags[val]) 32 | break; 33 | } 34 | 35 | flags[val] = true; 36 | } 37 | 38 | return flags; 39 | } 40 | 41 | public NumericLottery(Random r) 42 | { 43 | m_random = r; 44 | } 45 | 46 | public int [] getNumbers() 47 | { 48 | return getColumns(getFlags()); 49 | } 50 | 51 | public int [][] getNumbers(int n) 52 | { 53 | int [][] columns = new int[n][]; 54 | 55 | for (int i = 0; i < n; ++i) 56 | columns[i] = getNumbers(); 57 | 58 | return columns; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/Complex.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math; 2 | 3 | /** 4 | * Complex class that represents a complex number 5 | * Last Update: 5th October 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | 9 | public class Complex { 10 | public double real; 11 | public double imag; 12 | 13 | private static Complex add(double re1, double im1, double re2, double im2) 14 | { 15 | return new Complex(re1 + re2, im1 + im2); 16 | } 17 | 18 | private static Complex subtract(double re1, double im1, double re2, double im2) 19 | { 20 | return add(re1, im1, -re2, -im2); 21 | } 22 | 23 | private static Complex multiply(double re1, double im1, double re2, double im2) 24 | { 25 | return new Complex(re1 * re2 - im1 * im2, re1 * im2 + re2 * im1); 26 | } 27 | 28 | public Complex() 29 | { 30 | } 31 | 32 | public Complex(double real) 33 | { 34 | this.real = real; 35 | } 36 | 37 | public Complex(double real, double imag) 38 | { 39 | this.real = real; 40 | this.imag = imag; 41 | } 42 | 43 | public static Complex add(double value, Complex z) 44 | { 45 | return add(value, 0, z.real, z.imag); 46 | } 47 | 48 | public Complex add(double value) 49 | { 50 | return add(real, imag, value, 0); 51 | } 52 | 53 | public Complex add(Complex other) 54 | { 55 | return add(real, imag, other.real, other.imag); 56 | } 57 | 58 | public static Complex subtract(double value, Complex z) 59 | { 60 | return subtract(value, 0, z.real, z.imag); 61 | } 62 | 63 | public Complex subtract(double value) 64 | { 65 | return subtract(real, imag, value, 0); 66 | } 67 | 68 | public Complex subtract(Complex other) 69 | { 70 | return subtract(real, imag, other.real, other.imag); 71 | } 72 | 73 | public static Complex multiply(double value, Complex z) 74 | { 75 | return multiply(value, 0, z.real, z.imag); 76 | } 77 | 78 | public Complex multiply(double value) 79 | { 80 | return multiply(real, imag, value, 0); 81 | } 82 | 83 | public Complex multiply(Complex other) 84 | { 85 | return multiply(real, imag, other.real, other.imag); 86 | } 87 | 88 | //... 89 | 90 | public Complex getConjugate() 91 | { 92 | return new Complex(real, -imag); 93 | } 94 | 95 | public double getNorm() 96 | { 97 | return Math.sqrt(real * real + imag * imag); 98 | } 99 | 100 | public double getLength() 101 | { 102 | return getNorm(); 103 | } 104 | 105 | public String toString() 106 | { 107 | return "|(%f, %f)| = %.3f".formatted(real, imag, getLength()); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/AnalyticalCircle.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry; 2 | 3 | /** 4 | * AnalyticalCircle class that represents a circle in Cartesian plane 5 | * Last Update: 19th October 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | public class AnalyticalCircle extends Circle { 9 | private static final double DELTA = 0.000001; 10 | 11 | private final MutablePoint m_center; 12 | 13 | public AnalyticalCircle() 14 | { 15 | this(0); 16 | } 17 | 18 | public AnalyticalCircle(double radius) 19 | { 20 | this(radius, 0, 0); 21 | } 22 | 23 | public AnalyticalCircle(double x, double y) 24 | { 25 | this(0, x, y); 26 | } 27 | 28 | public AnalyticalCircle(double radius, double x, double y) 29 | { 30 | super(radius); 31 | m_center = MutablePoint.createCartesian(x, y); 32 | } 33 | 34 | public double getX() 35 | { 36 | return m_center.getX(); 37 | } 38 | 39 | public void setX(double x) 40 | { 41 | m_center.setX(x); 42 | } 43 | 44 | public double getY() 45 | { 46 | return m_center.getY(); 47 | } 48 | 49 | public void setY(double y) 50 | { 51 | m_center.setY(y); 52 | } 53 | 54 | public double centerDistance(AnalyticalCircle other) 55 | { 56 | return m_center.euclideanDistance(other.m_center); 57 | } 58 | 59 | public boolean isTangent(AnalyticalCircle other) 60 | { 61 | return Math.abs(getRadius() + other.getRadius() - centerDistance(other)) < DELTA; 62 | } 63 | 64 | public void offset(double dxy) 65 | { 66 | offset(dxy, dxy); 67 | } 68 | 69 | public void offset(double dx, double dy) 70 | { 71 | m_center.offset(dx, dy); 72 | } 73 | 74 | public String toString() 75 | { 76 | return "%s, Center:%s".formatted(super.toString(), m_center); 77 | } 78 | //... 79 | } 80 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/Circle.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry; 2 | 3 | /** 4 | * Circle class that represents a circle 5 | * Last Update: 22nd June 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | public class Circle { 9 | private double m_radius; 10 | 11 | public Circle() 12 | { 13 | } 14 | 15 | public Circle(double radius) 16 | { 17 | setRadius(radius); 18 | } 19 | 20 | public double getRadius() 21 | { 22 | return m_radius; 23 | } 24 | 25 | public void setRadius(double radius) 26 | { 27 | m_radius = Math.abs(radius); 28 | } 29 | 30 | public double getArea() 31 | { 32 | return Math.PI * m_radius * m_radius; 33 | } 34 | 35 | public double getCircumference() 36 | { 37 | return 2 * Math.PI * m_radius; 38 | } 39 | 40 | public String toString() 41 | { 42 | return "Radius:%.2f, Area:%.2f, Circumference:%.2f".formatted(m_radius, getArea(), getCircumference()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/MutablePoint.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry; 2 | 3 | /** 4 | * MutablePoint class that represents a point in cartesian coordinates 5 | * Last Update: 19th October 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | 9 | public class MutablePoint { 10 | public double m_x, m_y; 11 | 12 | private MutablePoint(double x, double y) 13 | { 14 | m_x = x; 15 | m_y = y; 16 | } 17 | 18 | public static MutablePoint createCartesian() 19 | { 20 | return createCartesian(0); 21 | } 22 | 23 | public static MutablePoint createCartesian(double x) 24 | { 25 | return createCartesian(x, 0); 26 | } 27 | 28 | public static MutablePoint createCartesian(double x, double y) 29 | { 30 | return new MutablePoint(x, y); 31 | } 32 | 33 | public static MutablePoint createPolar(double radius, double theta) 34 | { 35 | return new MutablePoint(PointCommon.getXByPolar(radius, theta), PointCommon.getYByPolar(radius, theta)); 36 | } 37 | 38 | public double getX() 39 | { 40 | return m_x; 41 | } 42 | 43 | public void setX(double x) 44 | { 45 | m_x = x; 46 | } 47 | 48 | public double getY() 49 | { 50 | return m_y; 51 | } 52 | 53 | public void setY(double y) 54 | { 55 | m_y = y; 56 | } 57 | 58 | public double euclideanDistance() 59 | { 60 | return euclideanDistance(0, 0); 61 | } 62 | 63 | public double euclideanDistance(MutablePoint other) 64 | { 65 | return euclideanDistance(other.m_x, other.m_y); 66 | } 67 | 68 | public double euclideanDistance(double x, double y) 69 | { 70 | return PointCommon.euclideanDistance(m_x, m_y, x, y); 71 | } 72 | 73 | public void offset(double dxy) 74 | { 75 | offset(dxy, dxy); 76 | } 77 | 78 | public void offset(double dx, double dy) 79 | { 80 | m_x += dx; 81 | m_y += dy; 82 | } 83 | 84 | public boolean equals(Object other) 85 | { 86 | return other instanceof MutablePoint p && PointCommon.equals(m_x, m_y, p.m_x, p.m_y); 87 | } 88 | 89 | public String toString() 90 | { 91 | return PointCommon.toString(m_x, m_y); 92 | } 93 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/Point.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry; 2 | 3 | /** 4 | * Immutable Point class that represents a point in cartesian coordinates 5 | * Last Update: 19th October 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | public class Point { 9 | public final double m_x, m_y; 10 | 11 | private Point(double x, double y) 12 | { 13 | m_x = x; 14 | m_y = y; 15 | } 16 | 17 | public static Point createCartesian() 18 | { 19 | return createCartesian(0); 20 | } 21 | 22 | public static Point createCartesian(double x) 23 | { 24 | return createCartesian(x, 0); 25 | } 26 | 27 | public static Point createCartesian(double x, double y) 28 | { 29 | return new Point(x, y); 30 | } 31 | 32 | public static Point createPolar(double radius, double theta) 33 | { 34 | return new Point(PointCommon.getXByPolar(radius, theta), PointCommon.getYByPolar(radius, theta)); 35 | } 36 | 37 | public double getX() 38 | { 39 | return m_x; 40 | } 41 | public double getY() 42 | { 43 | return m_y; 44 | } 45 | 46 | public double euclideanDistance() 47 | { 48 | return euclideanDistance(0, 0); 49 | } 50 | 51 | public double euclideanDistance(Point other) 52 | { 53 | return euclideanDistance(other.m_x, other.m_y); 54 | } 55 | 56 | public double euclideanDistance(double x, double y) 57 | { 58 | return PointCommon.euclideanDistance(m_x, m_y, x, y); 59 | } 60 | 61 | public boolean equals(Object other) 62 | { 63 | return other instanceof Point p && PointCommon.equals(m_x, m_y, p.m_x, p.m_y); 64 | } 65 | 66 | public String toString() 67 | { 68 | return PointCommon.toString(m_x, m_y); 69 | } 70 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/PointCommon.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry; 2 | 3 | import static java.lang.Math.sqrt; 4 | 5 | /** 6 | * Friendly PointCommon class that that is used by Point and MutablePoint to prevent code duplication 7 | * Last Update: 19th October 2025 8 | * @author Java-Sep-2024 Group 9 | */ 10 | class PointCommon { 11 | private PointCommon() 12 | { 13 | } 14 | 15 | static final double DELTA = 0.000001; 16 | 17 | static double euclideanDistance(double x1, double y1, double x2, double y2) 18 | { 19 | return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); 20 | } 21 | 22 | static boolean equals(double x1, double y1, double x2, double y2) 23 | { 24 | return Math.abs(x1 - x2) < PointCommon.DELTA && Math.abs(y1 - y2) < PointCommon.DELTA; 25 | } 26 | 27 | static String toString(double x, double y) 28 | { 29 | return "(%f, %f)".formatted(x, y); 30 | } 31 | 32 | static double getXByPolar(double radius, double theta) 33 | { 34 | return radius * Math.cos(theta); 35 | } 36 | 37 | static double getYByPolar(double radius, double theta) 38 | { 39 | return radius * Math.sin(theta); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleCenterDistanceTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry.test; 2 | 3 | import org.csystem.math.geometry.AnalyticalCircle; 4 | import org.csystem.util.console.Console; 5 | 6 | public class AnalyticalCircleCenterDistanceTest { 7 | private static final double DELTA = 0.000001; 8 | 9 | public static void run() 10 | { 11 | AnalyticalCircle ac1 = new AnalyticalCircle(3.4, -100, 200); 12 | AnalyticalCircle ac2 = new AnalyticalCircle(6.7, -103, 196); 13 | double expected = 5; 14 | 15 | Console.writeLine(Math.abs(ac1.centerDistance(ac2) - expected) < DELTA); 16 | } 17 | 18 | public static void main(String[] args) 19 | { 20 | run(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleCenterTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry.test; 2 | 3 | import org.csystem.math.geometry.AnalyticalCircle; 4 | import org.csystem.util.console.Console; 5 | 6 | public class AnalyticalCircleCenterTest { 7 | private static final double DELTA = 0.000001; 8 | 9 | public static void run() 10 | { 11 | AnalyticalCircle ac = new AnalyticalCircle(3.4, -100.8, 100.9); 12 | 13 | Console.writeLine(Math.abs(ac.getX() - -100.8) < DELTA); 14 | Console.writeLine(Math.abs(ac.getY() - 100.9) < DELTA); 15 | 16 | ac.offset(-30, 20); 17 | 18 | Console.writeLine(Math.abs(ac.getX() - -130.8) < DELTA); 19 | Console.writeLine(Math.abs(ac.getY() - 120.9) < DELTA); 20 | 21 | } 22 | 23 | public static void main(String[] args) 24 | { 25 | run(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleIsTangentTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry.test; 2 | 3 | import org.csystem.math.geometry.AnalyticalCircle; 4 | import org.csystem.util.console.Console; 5 | 6 | public class AnalyticalCircleIsTangentTest { 7 | public static void run() 8 | { 9 | AnalyticalCircle ac1 = new AnalyticalCircle(3, -100, 200); 10 | AnalyticalCircle ac2 = new AnalyticalCircle(2, -103, 196); 11 | 12 | Console.writeLine(ac1.isTangent(ac2)); 13 | } 14 | 15 | public static void main(String[] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/geometry/test/CircleRadiusPositiveTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.geometry.test; 2 | 3 | import org.csystem.math.geometry.Circle; 4 | 5 | public class CircleRadiusPositiveTest { 6 | public static void run() 7 | { 8 | Circle c = new Circle(-3.4); 9 | 10 | System.out.printf(c.toString()); 11 | System.out.println(c.getRadius() >= 0); 12 | } 13 | 14 | public static void main(String[] args) 15 | { 16 | run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/math/util/MathUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.math.util; 2 | 3 | import org.csystem.math.Complex; 4 | import org.csystem.math.geometry.Point; 5 | 6 | import java.util.Random; 7 | 8 | /** 9 | * Utility class for classes in that library 10 | * Last Update: 4th October 2025 11 | * @author Java-Sep-2024 Group 12 | */ 13 | public final class MathUtil { 14 | private MathUtil() 15 | { 16 | } 17 | 18 | public static Point createRandomPoint(Random random, double origin, double bound) 19 | { 20 | return Point.createCartesian(random.nextDouble(origin, bound), random.nextDouble(origin, bound)); 21 | } 22 | 23 | public static Point[] createRandomPoints(Random random, int count, double origin, double bound) 24 | { 25 | Point [] points = new Point[count]; 26 | 27 | for (int i = 0; i < count; ++i) 28 | points[i] = createRandomPoint(random, origin, bound); 29 | 30 | return points; 31 | } 32 | 33 | public static Complex createRandomComplex(Random random, double origin, double bound) 34 | { 35 | return new Complex(random.nextDouble(origin, bound), random.nextDouble(origin, bound)); 36 | } 37 | 38 | public static Complex[] createRandomComplexNumbers(Random random, int count, double origin, double bound) 39 | { 40 | Complex [] numbers = new Complex[count]; 41 | 42 | for (int i = 0; i < count; ++i) 43 | numbers[i] = createRandomComplex(random, origin, bound); 44 | 45 | return numbers; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/random/generator/ObjectArrayGenerator.java: -------------------------------------------------------------------------------- 1 | package org.csystem.random.generator; 2 | 3 | import org.csystem.math.Complex; 4 | import org.csystem.math.geometry.AnalyticalCircle; 5 | import org.csystem.math.geometry.Circle; 6 | import org.csystem.math.geometry.Point; 7 | import org.csystem.util.string.StringUtil; 8 | 9 | import java.util.Random; 10 | 11 | public class ObjectArrayGenerator { 12 | private final Random m_random = new Random(); 13 | 14 | 15 | private Object createObject() 16 | { 17 | return switch (m_random.nextInt(0, 10)) { 18 | case 0 -> Point.createCartesian(m_random.nextDouble(-100, 100), m_random.nextDouble(-100, 100)); 19 | case 1 -> new Complex(m_random.nextDouble(-10, 10), m_random.nextDouble(-10, 10)); 20 | case 2 -> new Circle(m_random.nextInt(-10, 10)); 21 | case 3 -> new AnalyticalCircle(m_random.nextInt(-10, 10), m_random.nextInt(-100, 100), m_random.nextInt(-100, 100)); 22 | case 4 -> StringUtil.randomTextEN(m_random, m_random.nextInt(5, 16)); 23 | case 5 -> m_random.nextInt(-128, 128); 24 | case 6 -> (char)((m_random.nextBoolean() ? 'A' : 'a') + m_random.nextInt(26)); 25 | case 7 -> m_random.nextDouble(); 26 | case 8 -> m_random.nextBoolean(); 27 | default -> new Random(); 28 | }; 29 | } 30 | 31 | public Object [] createObjectArray(int count) 32 | { 33 | Object [] objects = new Object[count]; 34 | 35 | for (int i = 0; i < count; ++i) 36 | objects[i] = createObject(); 37 | 38 | return objects; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/random/generator/RandomStringArrayGenerator.java: -------------------------------------------------------------------------------- 1 | package org.csystem.random.generator; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | import java.util.Random; 6 | 7 | public class RandomStringArrayGenerator { 8 | private final String [] m_texts; 9 | 10 | public RandomStringArrayGenerator(Random random, int count, int origin, int bound) 11 | { 12 | m_texts = StringUtil.randomTextsEN(random, count, origin, bound); 13 | } 14 | 15 | public int count() 16 | { 17 | return m_texts.length; 18 | } 19 | 20 | public String get(int i) 21 | { 22 | return m_texts[i]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/string/CSDStringBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Mutable class for some string operations 3 | * Last Update: 12th October 2025 4 | * @author Java-Sep-2024 Group 5 | */ 6 | package org.csystem.string; 7 | 8 | public class CSDStringBuilder { 9 | public CSDStringBuilder() 10 | { 11 | throw new UnsupportedOperationException("TODO"); 12 | } 13 | 14 | public CSDStringBuilder(int capacity) 15 | { 16 | throw new UnsupportedOperationException("TODO"); 17 | } 18 | 19 | public CSDStringBuilder(String str) 20 | { 21 | throw new UnsupportedOperationException("TODO"); 22 | } 23 | 24 | public CSDStringBuilder append(String str) 25 | { 26 | throw new UnsupportedOperationException("TODO"); 27 | } 28 | 29 | public CSDStringBuilder append(char ch) 30 | { 31 | throw new UnsupportedOperationException("TODO"); 32 | } 33 | 34 | public CSDStringBuilder append(int a) 35 | { 36 | throw new UnsupportedOperationException("TODO"); 37 | } 38 | 39 | public CSDStringBuilder append(long a) 40 | { 41 | throw new UnsupportedOperationException("TODO"); 42 | } 43 | 44 | public CSDStringBuilder append(double a) 45 | { 46 | throw new UnsupportedOperationException("TODO"); 47 | } 48 | 49 | public CSDStringBuilder append(char [] str) 50 | { 51 | throw new UnsupportedOperationException("TODO"); 52 | } 53 | 54 | public int capacity() 55 | { 56 | throw new UnsupportedOperationException("TODO"); 57 | } 58 | 59 | public char charAt(int index) 60 | { 61 | throw new UnsupportedOperationException("TODO"); 62 | } 63 | 64 | public CSDStringBuilder deleteCharAt(int index) 65 | { 66 | throw new UnsupportedOperationException("TODO"); 67 | } 68 | 69 | public CSDStringBuilder delete(int start, int end) 70 | { 71 | throw new UnsupportedOperationException("TODO"); 72 | } 73 | 74 | public void ensureCapacity(int minCapacity) 75 | { 76 | throw new UnsupportedOperationException("TODO"); 77 | } 78 | 79 | public int indexOf(String str) 80 | { 81 | throw new UnsupportedOperationException("TODO"); 82 | } 83 | 84 | public int indexOf(String str, int startIndex) 85 | { 86 | throw new UnsupportedOperationException("TODO"); 87 | } 88 | 89 | public CSDStringBuilder insert(int index, String str) 90 | { 91 | throw new UnsupportedOperationException("TODO:"); 92 | } 93 | 94 | public CSDStringBuilder insert(int index, char ch) 95 | { 96 | throw new UnsupportedOperationException("TODO"); 97 | } 98 | 99 | public CSDStringBuilder insert(int index, int a) 100 | { 101 | throw new UnsupportedOperationException("TODO"); 102 | } 103 | 104 | public CSDStringBuilder insert(int index, long a) 105 | { 106 | throw new UnsupportedOperationException("TODO"); 107 | } 108 | 109 | public CSDStringBuilder insert(int index, double a) 110 | { 111 | throw new UnsupportedOperationException("TODO"); 112 | } 113 | 114 | public CSDStringBuilder insert(int index, char [] str) 115 | { 116 | throw new UnsupportedOperationException("TODO"); 117 | } 118 | 119 | public int length() 120 | { 121 | throw new UnsupportedOperationException("TODO"); 122 | } 123 | 124 | public void trimToSize() 125 | { 126 | throw new UnsupportedOperationException("TODO"); 127 | } 128 | 129 | public boolean equals(Object other) 130 | { 131 | throw new UnsupportedOperationException("TODO"); 132 | } 133 | 134 | public String toString() 135 | { 136 | throw new UnsupportedOperationException("TODO"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/ArrayUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * Utility class for array operations 7 | * Last Update: 7th September 2025 8 | * @author Java-Sep-2024 Group 9 | */ 10 | public final class ArrayUtil { 11 | private ArrayUtil() 12 | { 13 | } 14 | 15 | private static void bubbleSortAscending(int [] a) 16 | { 17 | for (int i = 0; i < a.length - 1; ++i) 18 | for (int k = 0; k < a.length - 1 - i; ++k) 19 | if (a[k + 1] < a[k]) 20 | swap(a, k, k + 1); 21 | } 22 | 23 | private static void bubbleSortDescending(int [] a) 24 | { 25 | for (int i = 0; i < a.length - 1; ++i) 26 | for (int k = 0; k < a.length - 1 - i; ++k) 27 | if (a[k] < a[k + 1]) 28 | swap(a, k, k + 1); 29 | } 30 | 31 | private static void selectionSortAscending(int [] a) 32 | { 33 | int min, minIndex; 34 | 35 | for (int i = 0; i < a.length - 1; ++i) { 36 | min = a[i]; 37 | minIndex = i; 38 | 39 | for (int k = i + 1; k < a.length; ++k) 40 | if (a[k] < min) { 41 | min = a[k]; 42 | minIndex = k; 43 | } 44 | 45 | a[minIndex] = a[i]; 46 | a[i] = min; 47 | } 48 | } 49 | 50 | private static void selectionSortDescending(int [] a) 51 | { 52 | int max, maxIndex; 53 | 54 | for (int i = 0; i < a.length - 1; ++i) { 55 | max = a[i]; 56 | maxIndex = i; 57 | 58 | for (int k = i + 1; k < a.length; ++k) 59 | if (max < a[k]) { 60 | max = a[k]; 61 | maxIndex = k; 62 | } 63 | 64 | a[maxIndex] = a[i]; 65 | a[i] = max; 66 | } 67 | } 68 | 69 | public static void add(int [] a, int val) 70 | { 71 | for (int i = 0; i < a.length; ++i) 72 | a[i] += val; 73 | } 74 | 75 | public static void addBy(int [][] a, int value) 76 | { 77 | for (int i = 0; i < a.length; ++i) 78 | for (int j = 0; j < a[i].length; ++j) 79 | a[i][j] += value; 80 | } 81 | 82 | public static double average(int [] a) 83 | { 84 | return (double) sum(a) / a.length; 85 | } 86 | 87 | public static void bubbleSort(int [] a) 88 | { 89 | bubbleSort(a, false); 90 | } 91 | 92 | 93 | public static void bubbleSort(int [] a, boolean descending) 94 | { 95 | if (descending) 96 | bubbleSortDescending(a); 97 | else 98 | bubbleSortAscending(a); 99 | } 100 | 101 | public static boolean equals(int [] a, int [] b) 102 | { 103 | if (a.length != b.length) 104 | return false; 105 | 106 | for (int i = 0; i < a.length; ++i) 107 | if (a[i] != b[i]) 108 | return false; 109 | 110 | return true; 111 | } 112 | 113 | public static boolean equals(int [][] a, int [][] b) 114 | { 115 | if (a.length != b.length) 116 | return false; 117 | 118 | int len = a.length; 119 | 120 | for (int i = 0; i < len; ++i) 121 | if (!equals(a[i], b[i])) 122 | return false; 123 | 124 | return true; 125 | } 126 | 127 | public static boolean equals(String [] a, String [] b) 128 | { 129 | if (a.length != b.length) 130 | return false; 131 | 132 | for (int i = 0; i < a.length; ++i) 133 | if (!a[i].equals(b[i])) 134 | return false; 135 | 136 | return true; 137 | } 138 | 139 | public static boolean equalsIgnoreCase(String [] a, String [] b) 140 | { 141 | if (a.length != b.length) 142 | return false; 143 | 144 | for (int i = 0; i < a.length; ++i) 145 | if (!a[i].equalsIgnoreCase(b[i])) 146 | return false; 147 | 148 | return true; 149 | } 150 | 151 | public static void fillRandomArray(int [][] a, Random random, int min, int bound) 152 | { 153 | for (int i = 0; i < a.length; ++i) 154 | for (int j = 0; j < a[i].length; ++j) 155 | a[i][j] = random.nextInt(min, bound); 156 | } 157 | 158 | public static void fillRandomArray(int [] a, Random random, int min, int bound) 159 | { 160 | for (int i = 0; i < a.length; ++i) 161 | a[i] = random.nextInt(min, bound); 162 | } 163 | 164 | public static int [] randomArray(Random random, int count, int min, int bound) 165 | { 166 | int [] a = new int[count]; 167 | 168 | fillRandomArray(a, random, min, bound); 169 | 170 | return a; 171 | } 172 | 173 | public static int [] histogramData(int [] a, int n) 174 | { 175 | int [] counts = new int[n + 1]; 176 | 177 | for (int val : a) 178 | ++counts[val]; 179 | 180 | return counts; 181 | } 182 | 183 | public static int max(int [] a) 184 | { 185 | int result = a[0]; 186 | 187 | for (int i = 1; i < a.length; ++i) 188 | result = Math.max(result, a[i]); 189 | 190 | return result; 191 | } 192 | 193 | public static int min(int [] a) 194 | { 195 | int result = a[0]; 196 | 197 | for (int i = 1; i < a.length; ++i) 198 | result = Math.min(result, a[i]); 199 | 200 | return result; 201 | } 202 | public static void multiply(int [] a, int val) 203 | { 204 | for (int i = 0; i < a.length; ++i) 205 | a[i] *= val; 206 | } 207 | 208 | public static void multiplyBy(int [][] a, int value) 209 | { 210 | for (int i = 0; i < a.length; ++i) 211 | for (int j = 0; j < a[i].length; ++j) 212 | a[i][j] *= value; 213 | } 214 | 215 | public static int partition(int [] a, int threshold) 216 | { 217 | int pi = 0; 218 | 219 | while (pi != a.length && a[pi] < threshold) 220 | ++pi; 221 | 222 | if (pi == a.length) 223 | return pi; 224 | 225 | for (int i = pi + 1; i < a.length; ++i) 226 | if (a[i] < threshold) 227 | swap(a, i, pi++); 228 | 229 | return pi; 230 | } 231 | 232 | public static int partitionByEven(int [] a) 233 | { 234 | int pi = 0; 235 | 236 | while (pi != a.length && a[pi] % 2 == 0) 237 | ++pi; 238 | 239 | if (pi == a.length) 240 | return pi; 241 | 242 | for (int i = pi + 1; i < a.length; ++i) 243 | if (a[i] % 2 == 0) 244 | swap(a, i, pi++); 245 | 246 | return pi; 247 | } 248 | 249 | public static void print(int [] a, int n, String sep, String end) 250 | { 251 | String fmt = "%%0%dd%%s".formatted(n); 252 | for (int i = 0; i < a.length - 1; ++i) 253 | System.out.printf(fmt, a[i], sep); 254 | 255 | System.out.printf(fmt, a[a.length - 1], end); 256 | } 257 | 258 | public static void print(int [] a, String sep, String end) 259 | { 260 | print(a, 1, sep, end); 261 | } 262 | 263 | public static void print(int [] a) 264 | { 265 | print(a, " ", "\n"); 266 | } 267 | public static void print(int [] a, int n) 268 | { 269 | print(a, n, " ", "\n"); 270 | } 271 | 272 | 273 | public static void print(int [][] a, int n) 274 | { 275 | for (int [] array : a) 276 | print(array, n); 277 | } 278 | 279 | public static void print(int [][] a) 280 | { 281 | print(a, 1); 282 | } 283 | 284 | public static void reverse(int [] a) 285 | { 286 | int first = 0; 287 | int last = a.length - 1; 288 | 289 | while (first < last) 290 | swap(a, first++, last--); 291 | } 292 | 293 | public static void reverse(char [] a) 294 | { 295 | int first = 0; 296 | int last = a.length - 1; 297 | 298 | while (first < last) 299 | swap(a, first++, last--); 300 | } 301 | 302 | public static int [] reversed(int [] a) 303 | { 304 | int [] result = new int[a.length]; 305 | int len = a.length; 306 | 307 | for (int i = len - 1; i >= 0; --i) 308 | result[len - 1 - i] = a[i]; 309 | 310 | return result; 311 | } 312 | 313 | public static void selectionSort(int [] a) 314 | { 315 | selectionSort(a, false); 316 | } 317 | 318 | 319 | public static void selectionSort(int [] a, boolean descending) 320 | { 321 | if (descending) 322 | selectionSortDescending(a); 323 | else 324 | selectionSortAscending(a); 325 | } 326 | 327 | public static void subtract(int [] a, int val) 328 | { 329 | add(a, -val); 330 | } 331 | 332 | public static void subtractBy(int [][] a, int value) 333 | { 334 | addBy(a, -value); 335 | } 336 | 337 | public static long sum(int [] a) 338 | { 339 | long total = 0; 340 | 341 | for (int val : a) 342 | total += val; 343 | 344 | return total; 345 | } 346 | 347 | public static void swap(int [] a, int i, int k) 348 | { 349 | int temp = a[i]; 350 | 351 | a[i] = a[k]; 352 | a[k] = temp; 353 | } 354 | 355 | public static void swap(char [] a, int i, int k) 356 | { 357 | char temp = a[i]; 358 | 359 | a[i] = a[k]; 360 | a[k] = temp; 361 | } 362 | } 363 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilAddTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import java.util.Random; 4 | 5 | import static org.csystem.util.array.ArrayUtil.add; 6 | import static org.csystem.util.array.ArrayUtil.randomArray; 7 | import static org.csystem.util.array.ArrayUtil.print; 8 | 9 | public class ArrayUtilAddTest { 10 | public static void run() 11 | { 12 | Random random = new Random(); 13 | 14 | int [] a = randomArray(random, 10, -10, 11); 15 | int val = random.nextInt(-10, 10); 16 | 17 | System.out.printf("val = %d%n", val); 18 | print(a); 19 | add(a, val); 20 | print(a); 21 | } 22 | 23 | public static void main(String [] args) 24 | { 25 | run(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilArrayOfIntArrayEqualsTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilArrayOfIntArrayEqualsTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 9 | int [][] b = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 10 | int [][] c = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; 11 | int [][] d = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; 12 | int [][] e = {{1, 2, 5, 6, 6}, {4, 5}, {7, 8, 9}, {0, 1, 2, 6}}; 13 | int [][] f = {{1, 2, 5, 6, 6}, {4, 5}, {7, 8, 9}, {0, 1, 2, 6}}; 14 | 15 | System.out.println(ArrayUtil.equals(a, b)); 16 | System.out.println(ArrayUtil.equals(c, d)); 17 | System.out.println(!ArrayUtil.equals(a, c)); 18 | System.out.println(ArrayUtil.equals(e, f)); 19 | System.out.println(!ArrayUtil.equals(a, f)); 20 | } 21 | 22 | public static void main(String [] args) 23 | { 24 | run(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilAverageTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilAverageTest { 6 | public static void run() 7 | { 8 | int [] a = {1, 2, 3, 4, 5, 6}; 9 | double delta = 0.00000001; 10 | 11 | System.out.println(Math.abs(ArrayUtil.average(a) - 3.5) < delta); 12 | } 13 | 14 | public static void main(String [] args) 15 | { 16 | run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilBubbleSortAscendingTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilBubbleSortAscendingTest { 6 | public static void run() 7 | { 8 | int [] a = {3, 9, -5, 6, 7, -8}; 9 | int [] target = {-8, -5, 3, 6, 7, 9}; 10 | 11 | ArrayUtil.bubbleSort(a); 12 | System.out.println(ArrayUtil.equals(a, target)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilBubbleSortDescendingTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilBubbleSortDescendingTest { 6 | public static void run() 7 | { 8 | int [] a = {3, 9, -5, 6, 7, -8}; 9 | int [] target = {9, 7, 6, 3, -5, -8}; 10 | 11 | ArrayUtil.bubbleSort(a, true); 12 | System.out.println(ArrayUtil.equals(a, target)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilEqualsTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilEqualsTest { 6 | public static void run() 7 | { 8 | int [] a = {1, 2, 3, 4, 5}; 9 | int [] b = {1, 2, 3, 4, 5}; 10 | int [] c = {1, 2, 3, 4, 6}; 11 | int [] d = {1, 2, 3, 4}; 12 | String [] s1 = {"Şeyma", "Oğuz", "Deniz"}; 13 | String [] s2 = {"Şeyma", "Oğuz", "Deniz"}; 14 | String [] s3 = {"şeyma", "oğuz", "deniz"}; 15 | 16 | System.out.println(ArrayUtil.equals(a, b)); 17 | System.out.println(ArrayUtil.equals(a, c)); 18 | System.out.println(ArrayUtil.equals(b, c)); 19 | System.out.println(ArrayUtil.equals(a, d)); 20 | System.out.println(ArrayUtil.equals(s1, s2)); 21 | System.out.println(ArrayUtil.equalsIgnoreCase(s1, s3)); 22 | System.out.println(ArrayUtil.equals(s1, s3)); 23 | System.out.println(ArrayUtil.equals(s2, s3)); 24 | } 25 | 26 | public static void main(String [] args) 27 | { 28 | run(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilHistogramDataTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilHistogramDataTest { 6 | public static void run() 7 | { 8 | int [] a = {1, 2, 9, 2, 8, 9, 2, 1, 0, 0, 1, 3, 4, 3, 0, 9, 9, 8, 2, 1, 9}; 9 | int [] counts = {3, 4, 4, 2, 1, 0, 0, 0, 2, 5, 0}; 10 | 11 | System.out.println(ArrayUtil.equals(ArrayUtil.histogramData(a, 10), counts)); 12 | } 13 | 14 | public static void main(String [] args) 15 | { 16 | run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilMinMaxTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import static org.csystem.util.array.ArrayUtil.max; 4 | import static org.csystem.util.array.ArrayUtil.min; 5 | 6 | public class ArrayUtilMinMaxTest { 7 | public static void run() 8 | { 9 | int [] a = {1, -3, 5, 90, -34, 56, 89, 3, -4}; 10 | 11 | System.out.println(max(a) == 90); 12 | System.out.println(min(a) == -34); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilMultiplyTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import java.util.Random; 4 | 5 | import static org.csystem.util.array.ArrayUtil.randomArray; 6 | import static org.csystem.util.array.ArrayUtil.multiply; 7 | import static org.csystem.util.array.ArrayUtil.print; 8 | 9 | public class ArrayUtilMultiplyTest { 10 | public static void run() 11 | { 12 | Random random = new Random(); 13 | 14 | int [] a = randomArray(random, 10, -10, 11); 15 | int val = random.nextInt(-10, 10); 16 | 17 | System.out.printf("val = %d%n", val); 18 | print(a); 19 | multiply(a, val); 20 | print(a); 21 | } 22 | 23 | public static void main(String [] args) 24 | { 25 | run(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilPartitionTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilPartitionTest { 6 | public static void run() 7 | { 8 | int [] a = {3, 9, -5, 6, 7}; 9 | int [] target = {3, -5, 9, 6, 7}; 10 | int pi = 2; 11 | 12 | int result = ArrayUtil.partition(a, 6); 13 | System.out.println(ArrayUtil.equals(a, target)); 14 | System.out.println(pi == result); 15 | } 16 | 17 | public static void main(String [] args) 18 | { 19 | run(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilReverseTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import java.util.Random; 4 | 5 | import static org.csystem.util.array.ArrayUtil.randomArray; 6 | import static org.csystem.util.array.ArrayUtil.print; 7 | import static org.csystem.util.array.ArrayUtil.reverse; 8 | 9 | public class ArrayUtilReverseTest { 10 | public static void run() 11 | { 12 | Random random = new Random(); 13 | 14 | int [] a = randomArray(random, random.nextInt(5, 11), 0, 10); 15 | 16 | print(a); 17 | reverse(a); 18 | print(a); 19 | 20 | } 21 | 22 | public static void main(String [] args) 23 | { 24 | run(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilReversedTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import java.util.Random; 4 | 5 | import static org.csystem.util.array.ArrayUtil.randomArray; 6 | import static org.csystem.util.array.ArrayUtil.print; 7 | import static org.csystem.util.array.ArrayUtil.reversed; 8 | 9 | public class ArrayUtilReversedTest { 10 | public static void run() 11 | { 12 | Random random = new Random(); 13 | 14 | int [] a = randomArray(random, random.nextInt(5, 11), 0, 10); 15 | 16 | print(a); 17 | int [] r = reversed(a); 18 | print(a); 19 | print(r); 20 | } 21 | 22 | public static void main(String [] args) 23 | { 24 | run(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilSelectionSortAscendingTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilSelectionSortAscendingTest { 6 | public static void run() 7 | { 8 | int [] a = {3, 9, -5, 6, 7, -8}; 9 | int [] target = {-8, -5, 3, 6, 7, 9}; 10 | 11 | ArrayUtil.selectionSort(a); 12 | System.out.println(ArrayUtil.equals(a, target)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilSelectionSortDescendingTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilSelectionSortDescendingTest { 6 | public static void run() 7 | { 8 | int [] a = {3, 9, -5, 6, 7, -8}; 9 | int [] target = {9, 7, 6, 3, -5, -8}; 10 | 11 | ArrayUtil.selectionSort(a, true); 12 | System.out.println(ArrayUtil.equals(a, target)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilSubtractTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import java.util.Random; 4 | 5 | import static org.csystem.util.array.ArrayUtil.randomArray; 6 | import static org.csystem.util.array.ArrayUtil.print; 7 | import static org.csystem.util.array.ArrayUtil.subtract; 8 | 9 | public class ArrayUtilSubtractTest { 10 | public static void run() 11 | { 12 | Random random = new Random(); 13 | 14 | int [] a = randomArray(random, 10, -10, 11); 15 | int val = random.nextInt(-10, 10); 16 | 17 | System.out.printf("val = %d%n", val); 18 | print(a); 19 | subtract(a, val); 20 | print(a); 21 | } 22 | 23 | public static void main(String [] args) 24 | { 25 | run(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/array/test/ArrayUtilSumTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.array.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class ArrayUtilSumTest { 6 | public static void run() 7 | { 8 | int [] a = {1, 2, 3, 4, 5, 6}; 9 | 10 | System.out.println(ArrayUtil.sum(a) == 21); 11 | } 12 | 13 | public static void main(String [] args) 14 | { 15 | run(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/console/Console.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.console; 2 | 3 | 4 | import java.util.Scanner; 5 | 6 | /** 7 | * Utility class for console operations 8 | * Last Update: 20th September 2025 9 | * @author Java-Sep-2024 Group 10 | */ 11 | public final class Console { 12 | private static final int RADIX_DECIMAL = 10; 13 | private static final int RADIX_HEXADECIMAL = 16; 14 | private static final int RADIX_BINARY = 2; 15 | private static final Scanner KB = new Scanner(System.in); 16 | 17 | private Console() 18 | {} 19 | 20 | public static int readInt() 21 | { 22 | return readInt(""); 23 | } 24 | 25 | public static int readInt(String prompt) 26 | { 27 | return readInt(prompt, RADIX_DECIMAL); 28 | } 29 | 30 | public static int readInt(int radix) 31 | { 32 | return readInt("", radix); 33 | } 34 | 35 | public static int readInt(String prompt, int radix) 36 | { 37 | System.out.print(prompt); 38 | 39 | return Integer.parseInt(KB.nextLine(), radix); 40 | } 41 | 42 | public static int readIntHexadecimal() 43 | { 44 | return readIntHexadecimal(""); 45 | } 46 | 47 | public static int readIntHexadecimal(String prompt) 48 | { 49 | return readInt(prompt, RADIX_HEXADECIMAL); 50 | } 51 | 52 | public static int readIntBinary() 53 | { 54 | return readIntBinary(""); 55 | } 56 | 57 | public static int readIntBinary(String prompt) 58 | { 59 | return readInt(prompt, RADIX_BINARY); 60 | } 61 | 62 | public static double readDouble() 63 | { 64 | return readDouble(""); 65 | } 66 | 67 | public static double readDouble(String prompt) 68 | { 69 | System.out.print(prompt); 70 | 71 | return Double.parseDouble(KB.nextLine()); 72 | } 73 | 74 | public static long readLong() 75 | { 76 | return readLong(""); 77 | } 78 | 79 | public static long readLong(String prompt) 80 | { 81 | return readLong(prompt, RADIX_DECIMAL); 82 | } 83 | 84 | public static long readLong(int radix) 85 | { 86 | return readLong("", radix); 87 | } 88 | 89 | public static long readLong(String prompt, int radix) 90 | { 91 | System.out.print(prompt); 92 | 93 | return Long.parseLong(KB.nextLine()); 94 | } 95 | 96 | public static long readLongHexadecimal() 97 | { 98 | return readLongHexadecimal(""); 99 | } 100 | 101 | public static long readLongHexadecimal(String prompt) 102 | { 103 | return readLong(prompt, RADIX_HEXADECIMAL); 104 | } 105 | 106 | public static long readLongBinary() 107 | { 108 | return readLongBinary(""); 109 | } 110 | 111 | public static long readLongBinary(String prompt) 112 | { 113 | return readLong(prompt, RADIX_BINARY); 114 | } 115 | 116 | public static String readString() 117 | { 118 | return readString(""); 119 | } 120 | 121 | public static String readString(String prompt) 122 | { 123 | System.out.print(prompt); 124 | return KB.nextLine(); 125 | } 126 | 127 | //... 128 | 129 | public static void write(Object o) 130 | { 131 | System.out.print(o); 132 | } 133 | 134 | public static void write(String format, Object...args) 135 | { 136 | System.out.printf(format, args); 137 | } 138 | 139 | public static void writeLine() 140 | { 141 | System.out.println(); 142 | } 143 | 144 | public static void writeLine(Object o) 145 | { 146 | System.out.println(o); 147 | } 148 | 149 | public static void writeLine(String format, Object...args) 150 | { 151 | write(format + "%n", args); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/console/commanline/CommandLineArgsUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.console.commanline; 2 | 3 | /** 4 | * Utility class for command line arguments operations 5 | * Last Update: 7th September 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | public final class CommandLineArgsUtil { 9 | private CommandLineArgsUtil() 10 | { 11 | } 12 | 13 | public static void checkLengthEquals(int length, int argsLength, String errorMessage, int exitCode) 14 | { 15 | if (argsLength != length) { 16 | System.err.println(errorMessage); 17 | System.exit(exitCode); 18 | } 19 | } 20 | 21 | public static void checkLengthEquals(int length, int argsLength, String errorMessage) 22 | { 23 | checkLengthEquals(length, argsLength, errorMessage, 1); 24 | } 25 | 26 | public static void checkLengthGreater(int length, int argsLength, String errorMessage) 27 | { 28 | checkLengthGreater(length, argsLength, errorMessage, 1); 29 | } 30 | 31 | public static void checkLengthGreater(int length, int argsLength, String errorMessage, int exitCode) 32 | { 33 | if (argsLength <= length) { 34 | System.err.println(errorMessage); 35 | System.exit(exitCode); 36 | } 37 | } 38 | 39 | public static void checkLengthLess(int length, int argsLength, String errorMessage) 40 | { 41 | checkLengthLess(length, argsLength, errorMessage, 1); 42 | } 43 | 44 | public static void checkLengthLess(int length, int argsLength, String errorMessage, int exitCode) 45 | { 46 | if (argsLength >= length) { 47 | System.err.println(errorMessage); 48 | System.exit(exitCode); 49 | } 50 | } 51 | 52 | //... 53 | } 54 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/datetime/DateTimeUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.datetime; 2 | 3 | import org.csystem.datetime.DayOfWeek; 4 | import org.csystem.datetime.Month; 5 | 6 | import java.util.Random; 7 | 8 | 9 | /** 10 | * Utility class for date-time operations 11 | * Last Update: 7th September 2025 12 | * @author Java-Sep-2024 Group 13 | */ 14 | public final class DateTimeUtil { 15 | private DateTimeUtil() 16 | { 17 | } 18 | 19 | private static final Month[] MONTHS = Month.values(); 20 | private static final DayOfWeek[] DAY_OF_WEEKS = DayOfWeek.values(); 21 | 22 | public static Month randomMonth(Random random) 23 | { 24 | return MONTHS[random.nextInt(MONTHS.length)]; 25 | } 26 | 27 | public static DayOfWeek randomDayOfWeek(Random random) 28 | { 29 | return DAY_OF_WEEKS[random.nextInt(DAY_OF_WEEKS.length)]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/MatrixUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | import java.util.Random; 6 | 7 | /** 8 | * Utility class for matrix operations 9 | * Last Update: 7th September 2025 10 | * @author Java-Sep-2024 Group 11 | */ 12 | public final class MatrixUtil { 13 | private MatrixUtil() 14 | { 15 | } 16 | 17 | public static int [][] add(int [][] a, int [][] b) 18 | { 19 | int row = a.length; 20 | int col = a[0].length; 21 | 22 | int [][] r = new int[row][col]; 23 | 24 | for (int i = 0; i < row; ++i) 25 | for (int j = 0; j < col; ++j) 26 | r[i][j] = a[i][j] + b[i][j]; 27 | 28 | return r; 29 | } 30 | 31 | public static void addBy(int [][] a, int value) 32 | { 33 | ArrayUtil.addBy(a, value); 34 | } 35 | 36 | public static boolean equals(int [][] a, int [][] b) 37 | { 38 | return isMatrix(a) && isMatrix(b) && ArrayUtil.equals(a, b); 39 | } 40 | 41 | public static void fillRandomMatrix(int [][] a, Random random, int min, int bound) 42 | { 43 | ArrayUtil.fillRandomArray(a, random, min, bound); 44 | } 45 | 46 | public static boolean isMatrix(int [][] a) 47 | { 48 | for (int i = 1; i < a.length; ++i) 49 | if (a[i].length != a[0].length) 50 | return false; 51 | 52 | return true; 53 | } 54 | 55 | public static boolean isSquareMatrix(int [][] a) 56 | { 57 | return isMatrix(a) && a[0].length == a.length; 58 | } 59 | 60 | public static int [][] multiply(int [][] a, int [][] b) 61 | { 62 | int m = a.length; 63 | int n = a[0].length; 64 | int p = b[0].length; 65 | int [][] r = new int[m][p]; 66 | 67 | for (int i = 0; i < m; ++i) 68 | for (int j = 0; j < n; ++j) 69 | for (int k = 0; k < p; ++k) 70 | r[i][k] += a[i][j] * b[j][k]; 71 | 72 | return r; 73 | } 74 | 75 | public static void multiplyBy(int [][] a, int value) 76 | { 77 | ArrayUtil.multiplyBy(a, value); 78 | } 79 | 80 | public static int [][] randomMatrix(Random random, int m, int n, int min, int bound) 81 | { 82 | int [][] a = new int[m][n]; 83 | 84 | fillRandomMatrix(a, random, min, bound); 85 | 86 | return a; 87 | } 88 | 89 | public static int [][] subtract(int [][] a, int [][] b) 90 | { 91 | int row = a.length; 92 | int col = a[0].length; 93 | 94 | int [][] r = new int[row][col]; 95 | 96 | for (int i = 0; i < row; ++i) 97 | for (int j = 0; j < col; ++j) 98 | r[i][j] = a[i][j] - b[i][j]; 99 | 100 | return r; 101 | } 102 | 103 | public static void subtractBy(int [][] a, int value) 104 | { 105 | addBy(a, -value); 106 | } 107 | 108 | public static long sumDiagonal(int [][] a) 109 | { 110 | long total = 0; 111 | 112 | for (int i = 0; i < a.length; ++i) 113 | total += a[i][i]; 114 | 115 | return total; 116 | } 117 | 118 | public static int [][] transpose(int [][] a) 119 | { 120 | int row = a.length; 121 | int col = a[0].length; 122 | int [][] t = new int[col][row]; 123 | 124 | for (int i = 0; i < row; ++i) 125 | for (int j = 0; j < col; ++j) 126 | t[j][i] = a[i][j]; 127 | 128 | return t; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilAddByTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilAddByTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}}; 9 | int value = 2; 10 | int [][] r = {{3, 4, 5}, {6, 7, 8}}; 11 | 12 | MatrixUtil.addBy(a, value); 13 | System.out.println(MatrixUtil.equals(a, r)); 14 | } 15 | 16 | public static void main(String [] args) 17 | { 18 | run(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilAddTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilAddTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}}; 9 | int [][] b = {{7, 8, 9}, {5, 8, 9}}; 10 | int [][] r = {{8, 10, 12}, {9, 13, 15}}; 11 | 12 | System.out.println(MatrixUtil.equals(MatrixUtil.add(a, b), r)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilArrayOfIntArrayEqualsTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | public class MatrixUtilArrayOfIntArrayEqualsTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 9 | int [][] b = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 10 | int [][] c = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; 11 | int [][] d = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; 12 | 13 | System.out.println(ArrayUtil.equals(a, b)); 14 | System.out.println(ArrayUtil.equals(c, d)); 15 | System.out.println(!ArrayUtil.equals(a, c)); 16 | } 17 | 18 | public static void main(String [] args) 19 | { 20 | run(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilIsMatrixTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilIsMatrixTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; 9 | int [][] b = {{1, 2, 5, 6, 6}, {4, 5}, {7, 8, 9}, {0, 1, 2, 6}}; 10 | 11 | System.out.println(MatrixUtil.isMatrix(a)); 12 | System.out.println(!MatrixUtil.isMatrix(b)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilIsSquareMatrixTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilIsSquareMatrixTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 9 | int [][] b = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {0, 1, 2}}; 10 | int [][] c = {{1, 2, 5, 6, 6}, {4, 5}, {7, 8, 9}, {0, 1, 2, 6}}; 11 | 12 | System.out.println(MatrixUtil.isSquareMatrix(a)); 13 | System.out.println(!MatrixUtil.isSquareMatrix(b)); 14 | System.out.println(!MatrixUtil.isSquareMatrix(c)); 15 | } 16 | 17 | public static void main(String [] args) 18 | { 19 | run(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilMultiplyByTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilMultiplyByTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}}; 9 | int value = 2; 10 | int [][] r = {{2, 4, 6}, {8, 10, 12}}; 11 | 12 | MatrixUtil.multiplyBy(a, value); 13 | System.out.println(MatrixUtil.equals(a, r)); 14 | } 15 | 16 | public static void main(String [] args) 17 | { 18 | run(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilMultiplyTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilMultiplyTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 0, 1}, {2, 1, 1}, {0, 1, 1}, {1, 1, 2}}; 9 | int [][] b = {{1, 2, 1}, {2, 3, 1}, {4, 2, 2}}; 10 | int [][] r = {{5, 4, 3}, {8, 9, 5}, {6, 5, 3}, {11, 9, 6}}; 11 | 12 | System.out.println(MatrixUtil.equals(MatrixUtil.multiply(a, b), r)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilSubtractByTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilSubtractByTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}}; 9 | int value = 2; 10 | int [][] r = {{-1, -0, 1}, {2, 3, 4}}; 11 | 12 | MatrixUtil.subtractBy(a, value); 13 | System.out.println(MatrixUtil.equals(a, r)); 14 | } 15 | 16 | public static void main(String [] args) 17 | { 18 | run(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilSubtractTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilSubtractTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}}; 9 | int [][] b = {{7, 8, 9}, {5, 8, 9}}; 10 | int [][] r = {{-6, -6, -6}, {-1, -3, -3}}; 11 | 12 | System.out.println(MatrixUtil.equals(MatrixUtil.subtract(a, b), r)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilSumDiagonalTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilSumDiagonalTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 9 | 10 | System.out.println(MatrixUtil.sumDiagonal(a) == 15L); 11 | } 12 | 13 | public static void main(String [] args) 14 | { 15 | run(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/matrix/test/MatrixUtilTransposeTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.matrix.test; 2 | 3 | import org.csystem.util.matrix.MatrixUtil; 4 | 5 | public class MatrixUtilTransposeTest { 6 | public static void run() 7 | { 8 | int [][] a = {{1, 2, 3}, {4, 5, 6}}; 9 | int [][] t = {{1, 4}, {2, 5}, {3, 6}}; 10 | 11 | System.out.println(MatrixUtil.equals(MatrixUtil.transpose(a), t)); 12 | System.out.println(MatrixUtil.equals(MatrixUtil.transpose(t), a)); 13 | } 14 | 15 | public static void main(String [] args) 16 | { 17 | run(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/numeric/NumberUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.numeric; 2 | 3 | /** 4 | * Utility class for numeric operations 5 | * Last Update: 7th September 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | public final class NumberUtil { 9 | private static final String [] ONES_TR = {"", "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz"}; 10 | private static final String [] TENS_TR = {"", "on", "yirmi", "otuz", "kırk", "elli", "altmış", "yetmiş", "seksen", "doksan"}; 11 | 12 | private static final String [] ONES_EN = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; 13 | private static final String [] TENS_EN = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; 14 | 15 | private NumberUtil() 16 | { 17 | } 18 | 19 | private static int [] digits(long a, int n) 20 | { 21 | a = Math.abs(a); 22 | int divider = (int)Math.pow(10, n); 23 | int [] result = new int[(a != 0) ? ((int)Math.log10(Math.abs(a)) / n + 1) : 1]; 24 | 25 | for (int i = result.length - 1; i >= 0; result[i--] = (int)(a % divider), a /= divider) 26 | ; 27 | 28 | return result; 29 | } 30 | 31 | private static String numToStr3DigitTR(int val) 32 | { 33 | if (val == 0) 34 | return "sıfır"; 35 | 36 | StringBuilder sb = new StringBuilder(val < 0 ? "eksi" : ""); 37 | 38 | val = Math.abs(val); 39 | int a = val / 100; 40 | int b = val / 10 % 10; 41 | int c = val % 10; 42 | 43 | if (a != 0) { 44 | if (a != 1) 45 | sb.append(ONES_TR[a]); 46 | 47 | sb.append("yüz"); 48 | } 49 | 50 | sb.append(TENS_TR[b]); 51 | sb.append(ONES_TR[c]); 52 | 53 | return sb.toString(); 54 | } 55 | 56 | private static long calculateDigitsPowSum(long a) 57 | { 58 | long result = 0; 59 | int n = countDigits(a); 60 | 61 | while (a != 0) { 62 | result += (long) Math.pow(a % 10, n); 63 | a /= 10; 64 | } 65 | 66 | return result; 67 | } 68 | 69 | public static int countHardyRamanujan(int n) 70 | { 71 | int count = 0; 72 | 73 | EXIT_LOOP: 74 | for (int x = 1; x * x * x < n; ++x) 75 | for (int y = x + 1; x * x * x + y * y * y <= n; ++y) { 76 | if (x * x * x + y * y * y == n) { 77 | if (++count == 2) 78 | break EXIT_LOOP; 79 | 80 | ++x; 81 | } 82 | } 83 | 84 | return count; 85 | } 86 | 87 | public static int sumFactorialOfDigits(int n) 88 | { 89 | int total = 0; 90 | 91 | while (n != 0) { 92 | total += factorial(n % 10); 93 | n /= 10; 94 | } 95 | 96 | return total; 97 | } 98 | 99 | public static int countDigits(long a) 100 | { 101 | return (a != 0) ? ((int)Math.log10(Math.abs(a)) + 1) : 1; 102 | } 103 | 104 | public static int [] digits(long a) 105 | { 106 | return digits(a, 1); 107 | } 108 | 109 | public static int [] digitsInTwos(long a) 110 | { 111 | return digits(a, 2); 112 | } 113 | 114 | public static int [] digitsInThrees(long a) 115 | { 116 | return digits(a, 3); 117 | } 118 | 119 | public static int factorial(int n) 120 | { 121 | int result = 1; 122 | 123 | for (int i = 2; i <= n; ++i) 124 | result *= i; 125 | 126 | return result; 127 | } 128 | 129 | public static int fibonacciNumber(int n) 130 | { 131 | if (n <= 2) 132 | return n - 1; 133 | 134 | int prev1 = 1, prev2 = 0, result = 1; 135 | 136 | for (int i = 3; i < n; ++i) { 137 | prev2 = prev1; 138 | prev1 = result; 139 | result = prev1 + prev2; 140 | } 141 | 142 | return result; 143 | } 144 | 145 | public static int indexOfPrime(long a) 146 | { 147 | int i = 1; 148 | long val = 2; 149 | 150 | while (true) { 151 | if (val == a) 152 | return i; 153 | 154 | if (isPrime(val)) 155 | ++i; 156 | 157 | ++val; 158 | } 159 | } 160 | 161 | public static boolean isArmstrong(long a) 162 | { 163 | return a >= 0 && calculateDigitsPowSum(a) == a; 164 | } 165 | 166 | public static boolean isDecimalHarshad(int a) 167 | { 168 | return a > 0 && a % sumDigits(a) == 0; 169 | } 170 | 171 | public static boolean isEven(int a) 172 | { 173 | return a % 2 == 0; 174 | } 175 | 176 | public static boolean isFactorian(int n) 177 | { 178 | return n > 0 && sumFactorialOfDigits(n) == n; 179 | } 180 | 181 | public static boolean isHardyRamanujan(int n) 182 | { 183 | return n > 0 && countHardyRamanujan(n) == 2; 184 | } 185 | 186 | public static boolean isOdd(int a) 187 | { 188 | return !isEven(a); 189 | } 190 | 191 | public static boolean isPrime(long a) 192 | { 193 | if (a <= 1) 194 | return false; 195 | 196 | if (a % 2 == 0) 197 | return a == 2; 198 | 199 | if (a % 3 == 0) 200 | return a == 3; 201 | 202 | if (a % 5 == 0) 203 | return a == 5; 204 | 205 | if (a % 7 == 0) 206 | return a == 7; 207 | 208 | for (long i = 11; i * i <= a; i += 2) 209 | if (a % i == 0) 210 | return false; 211 | 212 | return true; 213 | } 214 | 215 | public static boolean isPrimeX(long a) 216 | { 217 | long sum = a; 218 | boolean result; 219 | 220 | while ((result = isPrime(sum)) && sum > 9) 221 | sum = sumDigits(sum); 222 | 223 | return result; 224 | } 225 | 226 | public static boolean isSuperPrime(long a) 227 | { 228 | return isPrime(a) && isPrime(indexOfPrime(a)); 229 | } 230 | 231 | public static int mid(int a, int b, int c) 232 | { 233 | int result = c; 234 | 235 | if (a <= b && b <= c || c <= b && b <= a) 236 | result = b; 237 | else if (b <= a && a <= c || c <= a && a <= b) 238 | result = a; 239 | 240 | return result; 241 | } 242 | 243 | public static int nextClosestFibonacciNumber(int a) 244 | { 245 | if (a < 0) 246 | return 0; 247 | 248 | int prev1 = 1, prev2 = 0, next; 249 | 250 | while (true) { 251 | next = prev1 + prev2; 252 | if (next > a) 253 | break; 254 | 255 | prev2 = prev1; 256 | prev1 = next; 257 | } 258 | 259 | return next; 260 | } 261 | 262 | public static long nextClosestPrime(int a) 263 | { 264 | if (a < 2) 265 | return 2; 266 | 267 | long i; 268 | 269 | for (i = a + 1; !isPrime(i); ++i) 270 | ; 271 | 272 | return i; 273 | } 274 | 275 | public static String numToStrTR(int val) 276 | { 277 | //... 278 | 279 | return numToStr3DigitTR(val); 280 | } 281 | 282 | public static long nthPrime(int n) 283 | { 284 | long val = 2; 285 | int count = 0; 286 | 287 | for (long i = 2; count < n; ++i) 288 | if (isPrime(i)) { 289 | ++count; 290 | val = i; 291 | } 292 | 293 | return val; 294 | } 295 | 296 | public static int reverse(int a) 297 | { 298 | int result = 0; 299 | 300 | while (a != 0) { 301 | result = result * 10 + a % 10; 302 | a /= 10; 303 | } 304 | 305 | return result; 306 | } 307 | 308 | public static int sumDigits(long a) 309 | { 310 | int total = 0; 311 | 312 | while (a != 0) { 313 | total += a % 10; 314 | a /= 10; 315 | } 316 | 317 | return Math.abs(total); 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/numeric/test/NumberUtilDigitsInThreesTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.numeric.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | import static org.csystem.util.numeric.NumberUtil.digitsInThrees; 6 | 7 | public class NumberUtilDigitsInThreesTest { 8 | public static void run() 9 | { 10 | long a = 12_345_678_901_234L; 11 | int [] ad = {12, 345, 678, 901, 234}; 12 | long b = -12_345_678_901_234L; 13 | 14 | System.out.println(ArrayUtil.equals(digitsInThrees(a), ad)); 15 | System.out.println(ArrayUtil.equals(digitsInThrees(b), ad)); 16 | 17 | a = 0; 18 | ad = new int[1]; 19 | System.out.println(ArrayUtil.equals(digitsInThrees(a), ad)); 20 | } 21 | 22 | public static void main(String[] args) 23 | { 24 | run(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/numeric/test/NumberUtilDigitsInTwosTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.numeric.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | import static org.csystem.util.numeric.NumberUtil.digitsInTwos; 6 | 7 | public class NumberUtilDigitsInTwosTest { 8 | public static void run() 9 | { 10 | long a = 12345678901234L; 11 | int [] ad = {12, 34, 56, 78, 90, 12, 34}; 12 | long b = -12345678901234L; 13 | 14 | System.out.println(ArrayUtil.equals(digitsInTwos(a), ad)); 15 | System.out.println(ArrayUtil.equals(digitsInTwos(b), ad)); 16 | 17 | a = 0; 18 | ad = new int[1]; 19 | System.out.println(ArrayUtil.equals(digitsInTwos(a), ad)); 20 | } 21 | 22 | public static void main(String[] args) 23 | { 24 | run(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/numeric/test/NumberUtilDigitsTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.numeric.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | 5 | import static org.csystem.util.numeric.NumberUtil.digits; 6 | 7 | public class NumberUtilDigitsTest { 8 | public static void run() 9 | { 10 | long a = 12345678901234L; 11 | int [] ad = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4}; 12 | long b = -12345678901234L; 13 | 14 | System.out.println(ArrayUtil.equals(digits(a), ad)); 15 | System.out.println(ArrayUtil.equals(digits(b), ad)); 16 | 17 | a = 0; 18 | ad = new int[1]; 19 | System.out.println(ArrayUtil.equals(digits(a), ad)); 20 | } 21 | 22 | public static void main(String[] args) 23 | { 24 | run(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/numeric/test/NumberUtilNumToStrTRTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.numeric.test; 2 | 3 | import static org.csystem.util.numeric.NumberUtil.numToStrTR; 4 | 5 | public class NumberUtilNumToStrTRTest { 6 | public static void run() 7 | { 8 | System.out.println(numToStrTR(123).equals("yüzyirmiüç")); 9 | System.out.println(numToStrTR(-123).equals("eksiyüzyirmiüç")); 10 | System.out.println(numToStrTR(103).equals("yüzüç")); 11 | System.out.println(numToStrTR(-103).equals("eksiyüzüç")); 12 | System.out.println(numToStrTR(604).equals("altıyüzdört")); 13 | System.out.println(numToStrTR(-604).equals("eksialtıyüzdört")); 14 | } 15 | 16 | public static void main(String[] args) 17 | { 18 | run(); 19 | } 20 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/StringSplitOptions.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string; 2 | 3 | 4 | /** 5 | * enum class for split method in StringUtil class 6 | * Last Update: 2nd August 2025 7 | * @author Java-Sep-2024 Group 8 | */ 9 | public enum StringSplitOptions { 10 | NONE, REMOVE_EMPTIES 11 | } 12 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/StringUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Random; 5 | 6 | /** 7 | * Utility class for string operations 8 | * Last Update: 12th October 2025 9 | * @author Java-Sep-2024 Group 10 | */ 11 | public final class StringUtil { 12 | private static final String LETTERS_TR = "abcçdefgğhıijklmnoöprsştuüvyz"; 13 | private static final String LETTERS_EN = "abcdefghijklmnopqrstuvwxyz"; 14 | private static final String CAPITAL_LETTERS_TR = "ABCÇDEFGĞHIİJKLMOÖPRSŞTUÜVYZ"; 15 | private static final String CAPITAL_LETTERS_EN = "ABCDEFGHIJKLMOPQRSTUVWXYZ"; 16 | private static final String ALL_LETTERS_TR = LETTERS_TR + CAPITAL_LETTERS_TR; 17 | private static final String ALL_LETTERS_EN = LETTERS_EN + CAPITAL_LETTERS_EN; 18 | 19 | private StringUtil() 20 | { 21 | } 22 | 23 | public static String capitalize(String s) 24 | { 25 | return s.isEmpty() ? s : Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase(); 26 | } 27 | 28 | public static String changeCase(String s) 29 | { 30 | StringBuilder sb = new StringBuilder(s); 31 | 32 | for (int i = 0; i < sb.length(); ++i) { 33 | char c = sb.charAt(i); 34 | 35 | sb.setCharAt(i, Character.isLowerCase(c) ? Character.toUpperCase(c) : Character.toLowerCase(c)); 36 | } 37 | 38 | return sb.toString(); 39 | } 40 | 41 | public static int countString(String s1, String s2) 42 | { 43 | int count = 0; 44 | 45 | for (int i = -1; (i = s1.indexOf(s2, i + 1)) != -1; ++count) 46 | ; 47 | 48 | return count; 49 | } 50 | 51 | public static String digits(String s) 52 | { 53 | StringBuilder sb = new StringBuilder(); 54 | 55 | for (int i = 0; i < s.length(); ++i) { 56 | char c = s.charAt(i); 57 | 58 | if (Character.isDigit(c)) 59 | sb.append(c); 60 | } 61 | 62 | return sb.toString(); 63 | } 64 | 65 | public static boolean isPalindrome(String s) 66 | { 67 | int left = 0; 68 | int right = s.length() - 1; 69 | 70 | while (left < right) { 71 | char cLeft = s.charAt(left); 72 | 73 | if (!Character.isLetter(cLeft)) { 74 | ++left; 75 | continue; 76 | } 77 | 78 | char cRight = s.charAt(right); 79 | 80 | if (!Character.isLetter(cRight)) { 81 | --right; 82 | continue; 83 | } 84 | 85 | if (Character.toLowerCase(cLeft) != Character.toLowerCase(cRight)) 86 | return false; 87 | 88 | ++left; 89 | --right; 90 | } 91 | 92 | return true; 93 | } 94 | 95 | public static boolean isPangram(String s, String alphabet) 96 | { 97 | for (int i = 0; i < alphabet.length(); ++i) 98 | if (s.indexOf(alphabet.charAt(i)) == -1) 99 | return false; 100 | 101 | return true; 102 | } 103 | 104 | public static boolean isPangramEN(String s) 105 | { 106 | return isPangram(s.toLowerCase(), LETTERS_EN); 107 | } 108 | 109 | public static boolean isPangramTR(String s) 110 | { 111 | return isPangram(s.toLowerCase(), LETTERS_TR); 112 | } 113 | 114 | public static String join(String [] s) 115 | { 116 | return join(s, ""); 117 | } 118 | 119 | public static String join(String [] s, char delimiter) 120 | { 121 | return join(s, String.valueOf(delimiter)); 122 | } 123 | 124 | public static String join(String [] str, String delimiter) 125 | { 126 | StringBuilder sb = new StringBuilder(); 127 | 128 | for (String s : str) 129 | sb.append(s).append(delimiter); 130 | 131 | return sb.substring(0, sb.length() - delimiter.length()); 132 | } 133 | 134 | public static String join(String [] s, char delimiter, boolean ignoreEmpties) 135 | { 136 | return join(s, String.valueOf(delimiter), ignoreEmpties); 137 | } 138 | 139 | public static String join(String [] str, String delimiter, boolean ignoreEmpties) 140 | { 141 | StringBuilder sb = new StringBuilder(); 142 | 143 | for (String s : str) { 144 | if (ignoreEmpties) { 145 | if (!s.isEmpty()) 146 | sb.append(s).append(delimiter); 147 | } 148 | else 149 | sb.append(s).append(delimiter); 150 | } 151 | 152 | return sb.substring(0, sb.length() - delimiter.length()); 153 | } 154 | 155 | public static String join(String [] s, char delimiter, int ignoreStatus) 156 | { 157 | return join(s, String.valueOf(delimiter), ignoreStatus); 158 | } 159 | 160 | public static String join(String [] str, String delimiter, int ignoreStatus) 161 | { 162 | StringBuilder sb = new StringBuilder(); 163 | 164 | for (String s : str) { 165 | if (ignoreStatus == 1) { 166 | if (!s.isEmpty()) 167 | sb.append(s).append(delimiter); 168 | } 169 | else if (ignoreStatus == 2) { 170 | if (!s.isBlank()) 171 | sb.append(s).append(delimiter); 172 | } 173 | else 174 | sb.append(s).append(delimiter); 175 | } 176 | 177 | return sb.substring(0, sb.length() - delimiter.length()); 178 | } 179 | 180 | public static String join(ArrayList strList, String delimiter, int ignoreStatus) 181 | { 182 | StringBuilder sb = new StringBuilder(); 183 | 184 | for (Object o : strList) { 185 | String s = (String)o; 186 | if (ignoreStatus == 1) { 187 | if (!s.isEmpty()) 188 | sb.append(s).append(delimiter); 189 | } 190 | else if (ignoreStatus == 2) { 191 | if (!s.isBlank()) 192 | sb.append(s).append(delimiter); 193 | } 194 | else 195 | sb.append(s).append(delimiter); 196 | } 197 | 198 | return sb.substring(0, sb.length() - delimiter.length()); 199 | } 200 | 201 | public static String letters(String s) 202 | { 203 | StringBuilder sb = new StringBuilder(); 204 | 205 | for (int i = 0; i < s.length(); ++i) { 206 | char c = s.charAt(i); 207 | 208 | if (Character.isLetter(c)) 209 | sb.append(c); 210 | } 211 | 212 | return sb.toString(); 213 | } 214 | 215 | public static String padLeading(String s, int n, char ch) 216 | { 217 | int len = s.length(); 218 | 219 | return len < n ? String.valueOf(ch).repeat(n - len) + s : s; 220 | } 221 | 222 | public static String padLeading(String s, int n) 223 | { 224 | return padLeading(s, n, ' '); 225 | } 226 | 227 | public static String padTrailing(String s, int n, char ch) 228 | { 229 | int len = s.length(); 230 | 231 | return len < n ? s + String.valueOf(ch).repeat(n - len) : s; 232 | } 233 | 234 | public static String padTrailing(String s, int n) 235 | { 236 | return padTrailing(s, n, ' '); 237 | } 238 | 239 | public static String randomText(Random random, int count, String sourceText) 240 | { 241 | StringBuilder sb = new StringBuilder(count); 242 | 243 | for (int i = 0; i < count; ++i) 244 | sb.append(sourceText.charAt(random.nextInt(sourceText.length()))); 245 | 246 | return sb.toString(); 247 | } 248 | 249 | public static String randomTextTR(Random random, int count) 250 | { 251 | return randomText(random, count, ALL_LETTERS_TR); 252 | } 253 | 254 | public static String randomTextEN(Random random, int count) 255 | { 256 | return randomText(random, count, ALL_LETTERS_EN); 257 | } 258 | 259 | public static String [] randomTexts(Random random, int count, int min, int bound, String sourceText) 260 | { 261 | String [] texts = new String[count]; 262 | 263 | for (int i = 0; i < count; ++i) 264 | texts[i] = randomText(random, random.nextInt(min, bound), sourceText); 265 | 266 | return texts; 267 | } 268 | 269 | public static String [] randomTextsTR(Random random, int count, int min, int bound) 270 | { 271 | return randomTexts(random, count, min, bound, ALL_LETTERS_TR); 272 | } 273 | 274 | public static String [] randomTextsEN(Random random, int count, int min, int bound) 275 | { 276 | return randomTexts(random, count, min, bound, ALL_LETTERS_EN); 277 | } 278 | 279 | public static String [] randomTexts(Random random, int count, int n, String sourceText) 280 | { 281 | String [] texts = new String[count]; 282 | 283 | for (int i = 0; i < count; ++i) 284 | texts[i] = randomText(random, n, sourceText); 285 | 286 | return texts; 287 | } 288 | 289 | public static String [] randomTextsTR(Random random, int count, int n) 290 | { 291 | return randomTexts(random, count, n, ALL_LETTERS_TR); 292 | } 293 | 294 | public static String [] randomTextsEN(Random random, int count, int n) 295 | { 296 | return randomTexts(random, count, n, ALL_LETTERS_EN); 297 | } 298 | 299 | public static String reverse(String s) 300 | { 301 | return new StringBuilder(s).reverse().toString(); 302 | } 303 | 304 | public static String [] split(String s, String delimiters) 305 | { 306 | return split(s, delimiters, false); 307 | } 308 | 309 | public static String [] split(String s, String delimiters, boolean removeEmpties) 310 | { 311 | StringBuilder sbRegex = new StringBuilder("["); 312 | 313 | for (int i = 0; i < delimiters.length(); ++i) { 314 | char c = delimiters.charAt(i); 315 | 316 | if (c == ']' || c == '[') 317 | sbRegex.append('\\'); 318 | 319 | sbRegex.append(c); 320 | } 321 | 322 | sbRegex.append(']'); 323 | 324 | if (removeEmpties) 325 | sbRegex.append('+'); 326 | 327 | return s.split(sbRegex.toString()); 328 | } 329 | 330 | public static String trim(String s) 331 | { 332 | return trimLeading(trimTrailing(s)); 333 | } 334 | 335 | public static String trimLeading(String s) 336 | { 337 | int i = 0; 338 | 339 | for (; i < s.length() && Character.isWhitespace(s.charAt(i)); ++i) 340 | ; 341 | 342 | return s.substring(i); 343 | } 344 | 345 | public static String trimTrailing(String s) 346 | { 347 | int i = s.length() - 1; 348 | 349 | for (; i >= 0 && Character.isWhitespace(s.charAt(i)); --i) 350 | ; 351 | 352 | return s.substring(0, i + 1); 353 | } 354 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilChangeCaseTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class StringUtilChangeCaseTest { 6 | public static void run() 7 | { 8 | String s = "AnKaRa"; 9 | String expected = "aNkArA"; 10 | 11 | System.out.println(StringUtil.changeCase(s).equals(expected)); 12 | } 13 | 14 | public static void main(String [] args) 15 | { 16 | run(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilDigitsTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class StringUtilDigitsTest { 6 | public static void run() 7 | { 8 | String s = "Bugün hava 23 derece yarın 25 derece olacakmış"; 9 | String expected = "2325"; 10 | 11 | System.out.println(StringUtil.digits(s).equals(expected)); 12 | } 13 | 14 | public static void main(String[] args) 15 | { 16 | run(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilJoinDirectTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class StringUtilJoinDirectTest { 6 | public static void run() 7 | { 8 | String [] s1 = {"ankara", "istanbul", "izmir", "zonguldak", "kastamonu"}; 9 | String [] s2 = {"ankara"}; 10 | String s1Expected = "ankaraistanbulizmirzonguldakkastamonu"; 11 | String s2Expected = "ankara"; 12 | 13 | System.out.println(StringUtil.join(s1).equals(s1Expected)); 14 | System.out.println(StringUtil.join(s2).equals(s2Expected)); 15 | } 16 | 17 | public static void main(String[] args) 18 | { 19 | run(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilJoinWithCharDelimiterTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class StringUtilJoinWithCharDelimiterTest { 6 | public static void run() 7 | { 8 | String [] s1 = {"ankara", "istanbul", "izmir", "zonguldak", "kastamonu"}; 9 | String [] s2 = {"ankara"}; 10 | String s1Expected = "ankara-istanbul-izmir-zonguldak-kastamonu"; 11 | String s2Expected = "ankara"; 12 | 13 | System.out.println(StringUtil.join(s1, '-').equals(s1Expected)); 14 | System.out.println(StringUtil.join(s2, '-').equals(s2Expected)); 15 | } 16 | 17 | public static void main(String[] args) 18 | { 19 | run(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilJoinWithDelimiterIgnoreEmptiesTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class StringUtilJoinWithDelimiterIgnoreEmptiesTest { 6 | public static void run() 7 | { 8 | String [] s1 = {"ankara", "istanbul", "izmir", "", "zonguldak", "", "kastamonu", ""}; 9 | String [] s2 = {"ankara"}; 10 | String s1ExpectedWithEmpties = "ankara, istanbul, izmir, , zonguldak, , kastamonu, "; 11 | String s1ExpectedIgnoreEmpties = "ankara, istanbul, izmir, zonguldak, kastamonu"; 12 | String s2Expected = "ankara"; 13 | 14 | System.out.println(StringUtil.join(s1, ", ", true).equals(s1ExpectedIgnoreEmpties)); 15 | System.out.println(StringUtil.join(s1, ", ", false).equals(s1ExpectedWithEmpties)); 16 | System.out.println(StringUtil.join(s2, ", ", true).equals(s2Expected)); 17 | System.out.println(StringUtil.join(s2, ", ", false).equals(s2Expected)); 18 | } 19 | 20 | public static void main(String[] args) 21 | { 22 | run(); 23 | } 24 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilJoinWithDelimiterIgnoreStatusTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class StringUtilJoinWithDelimiterIgnoreStatusTest { 6 | public static void run() 7 | { 8 | String [] s1 = {"ankara", "istanbul", " ", "izmir", "", "zonguldak", "", " ", "kastamonu", ""}; 9 | String [] s2 = {"ankara"}; 10 | String s1ExpectedWithAll = "ankara, istanbul, , izmir, , zonguldak, , , kastamonu, "; 11 | String s1ExpectedIgnoreEmpties = "ankara, istanbul, , izmir, zonguldak, , kastamonu"; 12 | String s1ExpectedIgnoreBlanks = "ankara, istanbul, izmir, zonguldak, kastamonu"; 13 | String s2Expected = "ankara"; 14 | 15 | System.out.println(StringUtil.join(s1, ", ", 1).equals(s1ExpectedIgnoreEmpties)); 16 | System.out.println(StringUtil.join(s1, ", ", 2).equals(s1ExpectedIgnoreBlanks)); 17 | System.out.println(StringUtil.join(s1, ", ", 0).equals(s1ExpectedWithAll)); 18 | System.out.println(StringUtil.join(s2, ", ", 1).equals(s2Expected)); 19 | System.out.println(StringUtil.join(s2, ", ", 2).equals(s2Expected)); 20 | System.out.println(StringUtil.join(s2, ", ", 0).equals(s2Expected)); 21 | } 22 | 23 | public static void main(String[] args) 24 | { 25 | run(); 26 | } 27 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilJoinWithDelimiterTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | public class StringUtilJoinWithDelimiterTest { 6 | public static void run() 7 | { 8 | String [] s1 = {"ankara", "istanbul", "izmir", "zonguldak", "kastamonu"}; 9 | String [] s2 = {"ankara"}; 10 | String s1Expected = "ankara, istanbul, izmir, zonguldak, kastamonu"; 11 | String s2Expected = "ankara"; 12 | 13 | System.out.println(StringUtil.join(s1, ", ").equals(s1Expected)); 14 | System.out.println(StringUtil.join(s2, ", ").equals(s2Expected)); 15 | } 16 | 17 | public static void main(String[] args) 18 | { 19 | run(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilRandomTextTRENTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | import java.util.Random; 6 | import java.util.Scanner; 7 | 8 | public class StringUtilRandomTextTRENTest { 9 | public static void run() 10 | { 11 | Scanner kb = new Scanner(System.in); 12 | Random random = new Random(); 13 | 14 | System.out.print("Input count:"); 15 | int count = kb.nextInt(); 16 | 17 | System.out.println(StringUtil.randomTextTR(random, count)); 18 | System.out.println(StringUtil.randomTextEN(random, count)); 19 | } 20 | 21 | public static void main(String[] args) 22 | { 23 | run(); 24 | } 25 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilRandomTextsTRENFixedTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | import java.util.Random; 6 | import java.util.Scanner; 7 | 8 | public class StringUtilRandomTextsTRENFixedTest { 9 | public static void run() 10 | { 11 | Scanner kb = new Scanner(System.in); 12 | Random random = new Random(); 13 | 14 | System.out.print("Input count:"); 15 | int count = kb.nextInt(); 16 | 17 | System.out.print("Input n:"); 18 | int n = kb.nextInt(); 19 | 20 | String [] textsTR = StringUtil.randomTextsTR(random, count, n); 21 | String [] textsEN = StringUtil.randomTextsEN(random, count, n); 22 | 23 | for (int i = 0; i < textsTR.length; ++i) 24 | System.out.printf("%s ", textsTR[i]); 25 | 26 | System.out.println(); 27 | 28 | for (int i = 0; i < textsEN.length; ++i) 29 | System.out.printf("%s ", textsEN[i]); 30 | } 31 | 32 | public static void main(String[] args) 33 | { 34 | run(); 35 | } 36 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilRandomTextsTRENTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.string.StringUtil; 4 | 5 | import java.util.Random; 6 | import java.util.Scanner; 7 | 8 | public class StringUtilRandomTextsTRENTest { 9 | public static void run() 10 | { 11 | Scanner kb = new Scanner(System.in); 12 | Random random = new Random(); 13 | 14 | System.out.print("Input count:"); 15 | int count = kb.nextInt(); 16 | 17 | String [] textsTR = StringUtil.randomTextsTR(random, count, 5, 11); 18 | String [] textsEN = StringUtil.randomTextsEN(random, count, 5, 11); 19 | 20 | for (int i = 0; i < textsTR.length; ++i) 21 | System.out.printf("%s ", textsTR[i]); 22 | 23 | System.out.println(); 24 | 25 | for (int i = 0; i < textsEN.length; ++i) 26 | System.out.printf("%s ", textsEN[i]); 27 | } 28 | 29 | public static void main(String[] args) 30 | { 31 | run(); 32 | } 33 | } -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/string/test/StringUtilSplitTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.string.test; 2 | 3 | import org.csystem.util.array.ArrayUtil; 4 | import org.csystem.util.string.StringUtil; 5 | 6 | public class StringUtilSplitTest { 7 | public static void run() 8 | { 9 | String s = "The quick brown [fox] jumps over the lazy dog."; 10 | String [] str = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}; 11 | String [] strWithEmpties = {"The", "quick", "brown", "", "fox", "", "jumps", "over", "the", "lazy", "dog"}; 12 | 13 | System.out.println(ArrayUtil.equals(StringUtil.split(s, " ][.", false), strWithEmpties)); 14 | System.out.println(ArrayUtil.equals(StringUtil.split(s, " ][.", true), str)); 15 | } 16 | 17 | public static void main(String [] args) 18 | { 19 | run(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/util/thread/ThreadUtil.java: -------------------------------------------------------------------------------- 1 | package org.csystem.util.thread; 2 | 3 | 4 | /** 5 | * Utility class for thread operations 6 | * Last Update: 7th September 2025 7 | * @author Java-Sep-2024 Group 8 | */ 9 | public final class ThreadUtil { 10 | private ThreadUtil() 11 | { 12 | } 13 | 14 | public static void sleep(long ms) 15 | { 16 | try { 17 | Thread.sleep(ms); 18 | } 19 | catch (InterruptedException ignore) { 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/wrapper/IntValue.java: -------------------------------------------------------------------------------- 1 | package org.csystem.wrapper; 2 | 3 | /** 4 | * Immutable class that wraps an int value by using cache for values between [-128, 127] 5 | * Last Update: 26th July 2025 6 | * @author Java-Sep-2024 Group 7 | */ 8 | public final class IntValue { 9 | private static final int CACHE_MIN = -128; 10 | private static final int CACHE_MAX = 127; 11 | private static final int INDEX_DIFF = -CACHE_MIN; 12 | private static final IntValue [] CACHE = new IntValue[CACHE_MAX - CACHE_MIN + 1]; 13 | private final int m_value; 14 | 15 | private IntValue(int value) 16 | { 17 | m_value = value; 18 | } 19 | 20 | public static IntValue of(int value) 21 | { 22 | if (value < CACHE_MIN || value > CACHE_MAX) 23 | return new IntValue(value); 24 | 25 | if (CACHE[value + INDEX_DIFF] == null) 26 | CACHE[value + INDEX_DIFF] = new IntValue(value); 27 | 28 | return CACHE[value + INDEX_DIFF]; 29 | } 30 | 31 | public int getValue() 32 | { 33 | return m_value; 34 | } 35 | 36 | public String toString() 37 | { 38 | return String.valueOf(m_value); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Sample/src/org/csystem/wrapper/test/IntValueCacheTest.java: -------------------------------------------------------------------------------- 1 | package org.csystem.wrapper.test; 2 | 3 | import org.csystem.wrapper.IntValue; 4 | 5 | public class IntValueCacheTest { 6 | public static void run() 7 | { 8 | IntValue i1 = IntValue.of(67); 9 | IntValue i2 = IntValue.of(67); 10 | IntValue i3 = IntValue.of(128); 11 | IntValue i4 = IntValue.of(128); 12 | 13 | System.out.println(i1 == i2); 14 | System.out.println(i3 != i4); 15 | } 16 | 17 | public static void main(String[] args) 18 | { 19 | run(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/csd/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/src/csd/App.class -------------------------------------------------------------------------------- /src/csd/App.java: -------------------------------------------------------------------------------- 1 | package csd; 2 | 3 | public class App { 4 | public static void main(String[] args) 5 | { 6 | System.out.println("App.main"); 7 | } 8 | } 9 | 10 | class Sample { 11 | //.. 12 | } 13 | 14 | class Mample { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/csd/Mample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/src/csd/Mample.class -------------------------------------------------------------------------------- /src/csd/Sample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/src/csd/Sample.class -------------------------------------------------------------------------------- /src/msd/Sample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oguzkaran/Java-Sep-2024/304bbf3287aa138771ac19f98f9e85fa56a7b44b/src/msd/Sample.class -------------------------------------------------------------------------------- /src/msd/Sample.java: -------------------------------------------------------------------------------- 1 | package msd; 2 | 3 | public class Sample { 4 | public static void main(String [] args) 5 | { 6 | System.out.println("Sample.main"); 7 | } 8 | } --------------------------------------------------------------------------------