├── .gitignore
├── README.md
├── doc
├── JavaNotes.md
├── JavaNotes.pdf
├── ReadLinesViaScannerApp.java
└── media
│ ├── Aggregation.PNG
│ ├── AnalyticalCircle.PNG
│ ├── Association.PNG
│ ├── BasicExceptionClasses.png
│ ├── Composition.PNG
│ ├── DemoCompanyApp-last.PNG
│ ├── DemoCompanyApp.PNG
│ ├── DemoRaceAppClasses.PNG
│ ├── DemoTaxiAutomationApp.PNG
│ ├── Inheritance.PNG
│ ├── Inheritance2.PNG
│ ├── Inheritance3.PNG
│ ├── InheritanceMemory.PNG
│ ├── Vehicles.PNG
│ ├── hardware.png
│ ├── ram.png
│ ├── ram2.png
│ └── ram3.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
└── Solutions.md
└── src
├── Sample
├── .gitignore
├── .idea
│ ├── .gitignore
│ ├── codeStyles
│ │ └── codeStyleConfig.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── uiDesigner.xml
│ └── vcs.xml
├── Sample.iml
├── people.txt
├── question.txt
├── questions.txt
└── src
│ └── org
│ └── csystem
│ ├── app
│ ├── App.java
│ ├── company
│ │ ├── DemoCompanyApp.java
│ │ ├── employee
│ │ │ ├── Employee.java
│ │ │ ├── Manager.java
│ │ │ ├── ProjectWorker.java
│ │ │ ├── SalesManager.java
│ │ │ ├── Worker.java
│ │ │ └── insurance
│ │ │ │ └── IInsured.java
│ │ └── hr
│ │ │ └── HumanResources.java
│ ├── datetime
│ │ ├── DateUtil.java
│ │ └── DemoDateApp.java
│ ├── generator
│ │ ├── DemoObjectArrayGeneratorApp.java
│ │ └── DemoPointListGeneratorApp.java
│ ├── io
│ │ ├── concat
│ │ │ └── ConcatFilesApp.java
│ │ └── input
│ │ │ └── ReadLinesViaScannerApp.java
│ ├── lottery
│ │ └── numeric
│ │ │ ├── NumericLottery.java
│ │ │ └── NumericLotteryApp.java
│ ├── school
│ │ ├── GradeInfo.java
│ │ ├── GradeInfoApp.java
│ │ └── GradeInfoHelper.java
│ ├── simulation
│ │ └── grades
│ │ │ ├── Classroom.java
│ │ │ ├── Exam.java
│ │ │ ├── ExamSimulation.java
│ │ │ ├── ExamSimulationApp.java
│ │ │ └── GradeInfo.java
│ └── string
│ │ └── join
│ │ └── JoinWithTwoHyphenApp.java
│ ├── datetime
│ ├── Date.java
│ ├── DateTime.java
│ ├── DateTimeException.java
│ ├── DayOfWeek.java
│ ├── Month.java
│ └── Time.java
│ ├── game
│ └── card
│ │ ├── Card.java
│ │ ├── CardType.java
│ │ ├── CardValue.java
│ │ └── RandomCardGenerator.java
│ ├── generator
│ ├── object
│ │ └── ObjectArrayGenerator.java
│ └── random
│ │ ├── point
│ │ └── RandomPointGenerator.java
│ │ └── string
│ │ └── RandomStringArrayGeneratorTR.java
│ ├── math
│ ├── Complex.java
│ ├── Fraction.java
│ ├── MutableComplex.java
│ └── geometry
│ │ ├── AnalyticalCircle.java
│ │ ├── Circle.java
│ │ ├── MutablePoint.java
│ │ ├── Point.java
│ │ ├── PointCommon.java
│ │ └── test
│ │ ├── AnalyticalCircleDefaultCtorTest.java
│ │ ├── AnalyticalCircleOffsetTest.java
│ │ ├── AnalyticalCircleTest.java
│ │ ├── AnalyticalCircleZeroCenterCtorTest.java
│ │ ├── AnalyticalCircleZeroRadiusCtorTest.java
│ │ ├── CircleTest.java
│ │ ├── FractionArithmeticOperationsTest.java
│ │ ├── FractionComparisonTest.java
│ │ ├── FractionCtorsTest.java
│ │ ├── FractionEqualityTest.java
│ │ └── FractionSettersTest.java
│ ├── string
│ ├── CSDStringBuilder.java
│ └── test
│ │ ├── CSDStringBuilderCapacityIncrementTest.java
│ │ ├── CSDStringBuilderInitialCapacityZeroTest.java
│ │ ├── CSDStringBuilderInitialEnsureCapacityTest.java
│ │ ├── CSDStringBuilderInitialToStringTest.java
│ │ ├── CSDStringBuilderStringParameterCtorTest.java
│ │ └── CSDStringBuilderTrimToSizeTest.java
│ ├── util
│ ├── array
│ │ ├── ArrayUtil.java
│ │ └── test
│ │ │ ├── ArrayUtilBubbleSortTest.java
│ │ │ ├── ArrayUtilHistogramDataTest.java
│ │ │ ├── ArrayUtilMinMaxTest.java
│ │ │ ├── ArrayUtilPartitionTest.java
│ │ │ ├── ArrayUtilReverseCharArrayTest.java
│ │ │ ├── ArrayUtilReverseIntArrayTest.java
│ │ │ ├── ArrayUtilSelectionSortTest.java
│ │ │ └── ArrayUtilSumTest.java
│ ├── collection
│ │ └── CollectionUtil.java
│ ├── console
│ │ ├── CommandLineArgsUtil.java
│ │ └── Console.java
│ ├── math
│ │ └── MathUtil.java
│ ├── matrix
│ │ ├── MatrixUtil.java
│ │ └── test
│ │ │ ├── MatrixUtilAddTest.java
│ │ │ ├── MatrixUtilIsMatrixTest.java
│ │ │ ├── MatrixUtilIsSquareMatrixTest.java
│ │ │ ├── MatrixUtilMinMaxTest.java
│ │ │ ├── MatrixUtilMultiplyByTest.java
│ │ │ ├── MatrixUtilMultiplyTest.java
│ │ │ ├── MatrixUtilSubtractTest.java
│ │ │ ├── MatrixUtilSumDiagonalTest.java
│ │ │ └── MatrixUtilTransposeTest.java
│ ├── numeric
│ │ ├── NumberUtil.java
│ │ └── test
│ │ │ ├── NumberUtilGetDigitsTest.java
│ │ │ ├── NumberUtilNumToStrENTest.java
│ │ │ └── NumberUtilNumToStrTRTest.java
│ ├── random
│ │ ├── IRandomGeneratorFactory.java
│ │ └── RandomGeneratorAlgorithm.java
│ ├── string
│ │ ├── StringUtil.java
│ │ └── test
│ │ │ ├── StringUtilChangeCaseTest.java
│ │ │ └── StringUtilJoinTest.java
│ └── thread
│ │ └── ThreadUtil.java
│ └── wrapper
│ └── primitive
│ ├── IntValue.java
│ └── test
│ ├── IntValueInCacheTest.java
│ └── IntValueNotInCacheTest.java
└── src-console
├── arman
├── Sample.class
└── Sample.java
├── csd
├── App.class
└── App.java
└── onur
├── Mample.class
├── Mample.java
└── Test.class
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Java-Jan-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/JavaNotes.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/JavaNotes.pdf
--------------------------------------------------------------------------------
/doc/ReadLinesViaScannerApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.io.input;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Path;
5 | import java.util.NoSuchElementException;
6 | import java.util.Scanner;
7 |
8 | import static org.csystem.util.console.CommandLineArgsUtil.checkLengthEquals;
9 |
10 | public class ReadLinesViaScannerApp {
11 | private static void readLines(Scanner s)
12 | {
13 | try (s) {
14 | while (true) {
15 | String line = s.nextLine();
16 |
17 | System.out.println(line);
18 | }
19 | }
20 | catch (NoSuchElementException ex) {
21 | System.out.println("All lines read successfully");
22 | }
23 | }
24 |
25 | public static void run(String[] args)
26 | {
27 | checkLengthEquals(1, args.length, "wrong number of arguments");
28 |
29 | try {
30 | Scanner s = new Scanner(Path.of(args[0]));
31 |
32 | readLines(s);
33 | }
34 | catch (IOException ex) {
35 | System.err.printf("Exception occurred:%s%n", ex.getMessage());
36 | }
37 | }
38 | public static void main(String[] args)
39 | {
40 | run(args);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/doc/media/Aggregation.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/Aggregation.PNG
--------------------------------------------------------------------------------
/doc/media/AnalyticalCircle.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/AnalyticalCircle.PNG
--------------------------------------------------------------------------------
/doc/media/Association.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/Association.PNG
--------------------------------------------------------------------------------
/doc/media/BasicExceptionClasses.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/BasicExceptionClasses.png
--------------------------------------------------------------------------------
/doc/media/Composition.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/Composition.PNG
--------------------------------------------------------------------------------
/doc/media/DemoCompanyApp-last.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/DemoCompanyApp-last.PNG
--------------------------------------------------------------------------------
/doc/media/DemoCompanyApp.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/DemoCompanyApp.PNG
--------------------------------------------------------------------------------
/doc/media/DemoRaceAppClasses.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/DemoRaceAppClasses.PNG
--------------------------------------------------------------------------------
/doc/media/DemoTaxiAutomationApp.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/DemoTaxiAutomationApp.PNG
--------------------------------------------------------------------------------
/doc/media/Inheritance.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/Inheritance.PNG
--------------------------------------------------------------------------------
/doc/media/Inheritance2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/Inheritance2.PNG
--------------------------------------------------------------------------------
/doc/media/Inheritance3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/Inheritance3.PNG
--------------------------------------------------------------------------------
/doc/media/InheritanceMemory.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/InheritanceMemory.PNG
--------------------------------------------------------------------------------
/doc/media/Vehicles.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/Vehicles.PNG
--------------------------------------------------------------------------------
/doc/media/hardware.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/hardware.png
--------------------------------------------------------------------------------
/doc/media/ram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/ram.png
--------------------------------------------------------------------------------
/doc/media/ram2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/ram2.png
--------------------------------------------------------------------------------
/doc/media/ram3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/doc/media/ram3.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 | **Açıklama:** Math sınıfının signum metodu **kullanılmayacaktır.**
43 |
44 | **Çözümlerinizi eğitmene kontrol ettiriniz.**
45 |
46 | **Tekrar yapıyor musunuz? ...**
47 |
48 | **İyi Çalışmalar\...**
49 |
--------------------------------------------------------------------------------
/homework/Homework-002.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-002.pdf
--------------------------------------------------------------------------------
/homework/Homework-003.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-003.pdf
--------------------------------------------------------------------------------
/homework/Homework-004.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-004.pdf
--------------------------------------------------------------------------------
/homework/Homework-005.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-005.pdf
--------------------------------------------------------------------------------
/homework/Homework-006.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-006.pdf
--------------------------------------------------------------------------------
/homework/Homework-007.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-007.pdf
--------------------------------------------------------------------------------
/homework/Homework-008.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-008.pdf
--------------------------------------------------------------------------------
/homework/Homework-009.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-009.pdf
--------------------------------------------------------------------------------
/homework/Homework-010.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-010.pdf
--------------------------------------------------------------------------------
/homework/Homework-011.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/homework/Homework-011.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 | >*Homework-001-1.sorunun bir çözümü*
9 | >
10 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
11 |
12 | ```java
13 | package csd;
14 |
15 | class App {
16 | public static void main(String [] args)
17 | {
18 | DisplayRelationsApp.run();
19 | }
20 | }
21 |
22 | class DisplayRelationsApp {
23 | public static void displayRelations(int a, int b, int c)
24 | {
25 | int min = Math.min(Math.min(a, b), c);
26 | int max = Math.max(Math.max(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", max);
36 | else
37 | System.out.printf("= %d", max);
38 |
39 | System.out.println();
40 | }
41 |
42 | public static void run()
43 | {
44 | java.util.Scanner kb = new java.util.Scanner(System.in);
45 |
46 | System.out.print("Üç tane sayı giriniz:");
47 | int a = kb.nextInt();
48 | int b = kb.nextInt();
49 | int c = kb.nextInt();
50 |
51 | displayRelations(a, b, c);
52 | }
53 | }
54 | ```
55 |
56 | >*Homework-001-2.sorunun bir çözümü*
57 | >
58 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
59 |
60 | ```java
61 | package csd;
62 |
63 | class App {
64 | public static void main(String [] args)
65 | {
66 | NumberUtilMidTest.run();
67 | }
68 | }
69 |
70 | class NumberUtilMidTest {
71 |
72 | public static void run()
73 | {
74 | java.util.Scanner kb = new java.util.Scanner(System.in);
75 |
76 | System.out.print("Üç tane sayı giriniz:");
77 | int a = kb.nextInt();
78 | int b = kb.nextInt();
79 | int c = kb.nextInt();
80 |
81 | System.out.printf("mid(%d, %d, %d) = %d%n", a, b, c, NumberUtil.mid(a, b, c));
82 | }
83 | }
84 |
85 |
86 | class NumberUtil {
87 | public static int mid(int a, int b, int c)
88 | {
89 | if (a <= b && b <= c || c <= b && b <= a)
90 | return b;
91 |
92 | if (b <= a && a <= c || c <= a && a <= b)
93 | return a;
94 |
95 | return c;
96 | }
97 | }
98 | ```
99 |
100 | >*Homework-001-3.sorunun bir çözümü*
101 | >
102 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
103 |
104 | ```java
105 | package csd;
106 |
107 | class App {
108 | public static void main(String [] args)
109 | {
110 | NumberUtilSignumTest.run();
111 | }
112 | }
113 |
114 | class NumberUtilSignumTest {
115 |
116 | public static void run()
117 | {
118 | java.util.Scanner kb = new java.util.Scanner(System.in);
119 |
120 | System.out.print("Bir sayı giriniz:");
121 | int a = kb.nextInt();
122 |
123 | System.out.printf("sign(%d) = %d%n", a, NumberUtil.signum(a));
124 | }
125 | }
126 |
127 | class NumberUtil {
128 | public static int signum(int a)
129 | {
130 | if (a > 0)
131 | return 1;
132 |
133 | if (a == 0)
134 | return 0;
135 |
136 | return -1;
137 | }
138 | }
139 | ```
140 |
141 | >*Homework-001-3.sorunun bir çözümü*
142 | >
143 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
144 |
145 | ```java
146 | package csd;
147 |
148 | class App {
149 | public static void main(String [] args)
150 | {
151 | NumberUtilSignumTest.run();
152 | }
153 | }
154 |
155 | class NumberUtilSignumTest {
156 |
157 | public static void run()
158 | {
159 | java.util.Scanner kb = new java.util.Scanner(System.in);
160 |
161 | System.out.print("Bir sayı giriniz:");
162 | int a = kb.nextInt();
163 |
164 | System.out.printf("sign(%d) = %d%n", a, NumberUtil.signum(a));
165 | }
166 | }
167 |
168 | class NumberUtil {
169 | public static int signum(int a)
170 | {
171 | int result = -1;
172 |
173 | if (a > 0)
174 | result = 1;
175 | else if (a == 0)
176 | result = 0;
177 |
178 | return result;
179 | }
180 | }
181 | ```
182 |
183 | #### Homework-002
184 |
185 | >*Homework-002-1.sorunun bir çözümü*
186 | >
187 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
188 |
189 | ```java
190 | package csd;
191 |
192 | class App {
193 | public static void main(String [] args)
194 | {
195 | PrintDiamondApp.run();
196 | }
197 | }
198 |
199 | class PrintDiamondApp {
200 | public static void printAbove(int n)
201 | {
202 | for (int i = 0; i < n; ++i) {
203 | for (int k = 0; k < n - i; ++k)
204 | System.out.print(' ');
205 |
206 | for (int k = 0; k < 2 * i - 1; ++k)
207 | System.out.print('*');
208 |
209 | System.out.println();
210 | }
211 | }
212 |
213 | public static void printBelow(int n)
214 | {
215 | for (int i = 0; i < n; ++i) {
216 | for (int k = 0; k < i; ++k)
217 | System.out.print(' ');
218 |
219 | for (int k = 0; k < 2 * (n - i) - 1; ++k)
220 | System.out.print('*');
221 |
222 | System.out.println();
223 | }
224 | }
225 |
226 | public static void printDiamond(int n)
227 | {
228 | printAbove(n);
229 | printBelow(n);
230 | }
231 |
232 | public static void run()
233 | {
234 | java.util.Scanner kb = new java.util.Scanner(System.in);
235 |
236 | System.out.print("Bir sayı giriniz:");
237 | int n = kb.nextInt();
238 |
239 | printDiamond(n);
240 | }
241 | }
242 | ```
243 |
244 | >*Homework-002-2.sorunun bir çözümü*
245 | >
246 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
247 |
248 | ```java
249 | package csd;
250 |
251 | class App {
252 | public static void main(String [] args)
253 | {
254 | PrintDurationTest.run();
255 | }
256 | }
257 |
258 | class PrintDurationTest {
259 | public static void run()
260 | {
261 | java.util.Scanner kb = new java.util.Scanner(System.in);
262 |
263 | while (true) {
264 | System.out.print("Toplam saniye değeri giriniz:");
265 | long totalSeconds = Long.parseLong(kb.nextLine());
266 |
267 | TimeUtil.printDuration(totalSeconds);
268 |
269 | if (totalSeconds <= 0)
270 | break;
271 | }
272 | }
273 | }
274 |
275 | class TimeUtil {
276 | public static void printDuration(long totalSeconds)
277 | {
278 | long hours = totalSeconds / 60 / 60;
279 | long minutes = totalSeconds / 60 % 60;
280 | long seconds = totalSeconds % 60;
281 |
282 | if (hours != 0)
283 | System.out.printf("%d saat ", hours);
284 |
285 | if (minutes != 0)
286 | System.out.printf("%d dakika ", minutes);
287 |
288 | if (seconds != 0)
289 | System.out.printf("%d saniye ", seconds);
290 |
291 | System.out.println();
292 | }
293 | }
294 | ```
295 |
296 | >*Homework-002-3.sorunun bir çözümü*
297 | >
298 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
299 |
300 | ```java
301 | package csd;
302 |
303 | class App {
304 | public static void main(String [] args)
305 | {
306 | PrintPrimeFactorsApp.run();
307 | }
308 | }
309 |
310 | class PrintPrimeFactorsApp {
311 | public static void run()
312 | {
313 | java.util.Scanner kb = new java.util.Scanner(System.in);
314 |
315 | while (true) {
316 | System.out.print("Bir sayı giriniz:");
317 | int a = Integer.parseInt(kb.nextLine());
318 |
319 | if (a <= 0)
320 | break;
321 |
322 | NumberUtil.printPrimeFactors(a);
323 | }
324 | }
325 | }
326 |
327 | class NumberUtil {
328 | public static void printPrimeFactors(int a)
329 | {
330 | if (a == 0)
331 | return;
332 |
333 | a = Math.abs(a);
334 |
335 | int val = 2;
336 |
337 | while (a != 1) {
338 | if (a % val == 0) {
339 | System.out.printf("%d ", val);
340 | a /= val;
341 | }
342 | else
343 | ++val;
344 | }
345 |
346 | System.out.println();
347 | }
348 | }
349 | ```
350 |
351 | >*Homework-002-4.sorunun bir çözümü*
352 | >
353 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
354 |
355 | ```java
356 | package csd;
357 |
358 | class App {
359 | public static void main(String [] args)
360 | {
361 | BallFallApp.run();
362 | }
363 | }
364 |
365 | class BallFallApp {
366 | public static void run()
367 | {
368 | java.util.Scanner kb = new java.util.Scanner(System.in);
369 |
370 | while (true) {
371 | System.out.print("Genişliği giriniz:");
372 | int width = Integer.parseInt(kb.nextLine());
373 |
374 | System.out.print("Yüksekliği giriniz:");
375 | int height = Integer.parseInt(kb.nextLine());
376 |
377 | if (width <= 0 || height <= 0)
378 | break;
379 |
380 | BallFall.play(width, height);
381 | }
382 | }
383 | }
384 |
385 | class BallFall {
386 | public static void writeSpace(int begin, int end)
387 | {
388 | for (int i = begin; i < end; ++i)
389 | System.out.print(' ');
390 | }
391 |
392 | public static void writeBall(int ballPosition, int end)
393 | {
394 | writeSpace(0, ballPosition);
395 | System.out.print('*');
396 | writeSpace(ballPosition + 1, end);
397 | }
398 |
399 | public static boolean updateRightFlagIfNecessary(boolean currentStatus, int balllPosition, int width)
400 | {
401 | if (balllPosition == 0)
402 | currentStatus = true;
403 | else if (balllPosition == width - 1)
404 | currentStatus = false;
405 |
406 | return currentStatus;
407 | }
408 |
409 | public static int updateBallPosition(int currentPosition, boolean right)
410 | {
411 | if (right)
412 | return currentPosition + 1;
413 |
414 | return currentPosition - 1;
415 | }
416 |
417 | public static void play(int width, int height)
418 | {
419 | boolean right = false;
420 | int ballPosition = 0;
421 |
422 | for (int i = 1; i <= height; ++i) {
423 | System.out.print('|');
424 | writeBall(ballPosition, width);
425 |
426 | if (width != 1) {
427 | right = updateRightFlagIfNecessary(right, ballPosition, width);
428 | ballPosition = updateBallPosition(ballPosition, right);
429 | }
430 | System.out.println('|');
431 | }
432 | }
433 | }
434 | ```
435 |
436 | >*Homework-002-5.sorunun bir çözümü*
437 | >
438 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
439 |
440 | ```java
441 | package csd;
442 |
443 | class App {
444 | public static void main(String [] args)
445 | {
446 | PrintGoldbachApp.run();
447 | }
448 | }
449 |
450 | class PrintGoldbachApp {
451 | public static void run()
452 | {
453 | java.util.Scanner kb = new java.util.Scanner(System.in);
454 |
455 | while (true) {
456 | System.out.print("2'den büyük çift bir sayı giriniz:");
457 | int a = Integer.parseInt(kb.nextLine());
458 |
459 | if (a <= 2)
460 | break;
461 |
462 | if (a % 2 != 0) {
463 | System.out.println("Hatalı giriş!...");
464 | continue;
465 | }
466 |
467 | NumberUtil.printGoldbach(a);
468 | }
469 | }
470 | }
471 |
472 | class NumberUtil {
473 | public static void printGoldbach(int a)
474 | {
475 | for (int x = a - 1; x >= 2; --x) {
476 | int y = a - x;
477 |
478 | if (isPrime(x) && isPrime(y) && x >= y)
479 | System.out.printf("%d + %d = %d == %d%n", x, y, x + y, a);
480 | }
481 | }
482 |
483 | public static boolean isPrime(long a)
484 | {
485 | if (a <= 1)
486 | return false;
487 |
488 | if (a % 2 == 0)
489 | return a == 2;
490 |
491 | if (a % 3 == 0)
492 | return a == 3;
493 |
494 | if (a % 5 == 0)
495 | return a == 5;
496 |
497 | if (a % 7 == 0)
498 | return a == 7;
499 |
500 | for (long i = 11; i * i <= a; i += 2)
501 | if (a % i == 0)
502 | return false;
503 |
504 | return true;
505 | }
506 | }
507 | ```
508 |
509 | #### Homework-003
510 |
511 | >*Homework-003-1. sorunun bir çözümü*
512 | >
513 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
514 |
515 | ```java
516 | package csd;
517 |
518 | class App {
519 | public static void main(String [] args)
520 | {
521 | SatisfyConditionsApp.run();
522 | }
523 | }
524 |
525 | class SatisfyConditionsApp {
526 | public static boolean isCondition1Satisfied(int a, int b, int c)
527 | {
528 | return 100 * c + 10 * b + a > 100 * a + 10 * b + c;
529 | }
530 |
531 | public static boolean isCondition2Satisfied(int a, int b, int c)
532 | {
533 | return NumberUtil.isPrime(100 * a + 10 * b + c);
534 | }
535 |
536 | public static boolean isCondition3Satisfied(int a, int b, int c)
537 | {
538 | return NumberUtil.isPrime(100 * c + 10 * b + a);
539 | }
540 |
541 |
542 | public static boolean isCondition4Satisfied(int a, int b)
543 | {
544 | return NumberUtil.isPrime(10 * a + b);
545 | }
546 |
547 | public static boolean isCondition5Satisfied(int b, int c)
548 | {
549 | return NumberUtil.isPrime(10 * b + c);
550 | }
551 |
552 | public static boolean isCondition6Satisfied(int c, int b)
553 | {
554 | return NumberUtil.isPrime(10 * c + b);
555 | }
556 |
557 | public static boolean isCondition7Satisfied(int b, int a)
558 | {
559 | return NumberUtil.isPrime(10 * b + a);
560 | }
561 |
562 | public static boolean isAllSatisfied(int val)
563 | {
564 | int a = val / 100;
565 | int b = val / 10 % 10;
566 | int c = val % 10;
567 |
568 | return isCondition1Satisfied(a, b, c) && isCondition2Satisfied(a, b, c)
569 | && isCondition3Satisfied(a, b, c) && isCondition4Satisfied(a, b)
570 | && isCondition5Satisfied(b, c) && isCondition6Satisfied(c, b)
571 | && isCondition7Satisfied(b, a);
572 | }
573 |
574 | public static void run()
575 | {
576 | for (int val = 100; val <= 999; ++val)
577 | if (isAllSatisfied(val))
578 | System.out.printf("%d ", val);
579 |
580 | System.out.println();
581 | }
582 | }
583 |
584 | class NumberUtil {
585 | public static boolean isPrime(long a)
586 | {
587 | if (a <= 1)
588 | return false;
589 |
590 | if (a % 2 == 0)
591 | return a == 2;
592 |
593 | if (a % 3 == 0)
594 | return a == 3;
595 |
596 | if (a % 5 == 0)
597 | return a == 5;
598 |
599 | if (a % 7 == 0)
600 | return a == 7;
601 |
602 | for (long i = 11; i * i <= a; i += 2)
603 | if (a % i == 0)
604 | return false;
605 |
606 | return true;
607 | }
608 | }
609 | ```
610 |
611 | >*Homework-003-2. sorunun bir çözümü*
612 | >
613 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
614 |
615 | ```java
616 | package csd;
617 |
618 | class App {
619 | public static void main(String [] args)
620 | {
621 | IsPrimeXTest.run();
622 | }
623 | }
624 |
625 | class IsPrimeXTest {
626 |
627 | public static void run()
628 | {
629 | java.util.Scanner kb = new java.util.Scanner(System.in);
630 |
631 | System.out.print("Bir sayı giriniz:");
632 | long n = kb.nextLong();
633 |
634 | for (long i = 0; i <= n; ++i)
635 | if (NumberUtil.isPrimeX(i))
636 | System.out.println(i);
637 |
638 | System.out.println("Tekrar yapıyor musunuz?");
639 | }
640 | }
641 |
642 | class NumberUtil {
643 | public static boolean isPrimeX(long a)
644 | {
645 | long sum = a;
646 | boolean result;
647 |
648 | while ((result = isPrime(sum)) && sum > 9)
649 | sum = sumDigits(sum);
650 |
651 | return result;
652 | }
653 |
654 | public static int sumDigits(long a)
655 | {
656 | int sum = 0;
657 |
658 | while (a != 0) {
659 | sum += a % 10;
660 | a /= 10;
661 | }
662 |
663 | return Math.abs(sum);
664 | }
665 |
666 | public static boolean isPrime(long a)
667 | {
668 | if (a <= 1)
669 | return false;
670 |
671 | if (a % 2 == 0)
672 | return a == 2;
673 |
674 | if (a % 3 == 0)
675 | return a == 3;
676 |
677 | if (a % 5 == 0)
678 | return a == 5;
679 |
680 | if (a % 7 == 0)
681 | return a == 7;
682 |
683 | for (long i = 11; i * i <= a; i += 2)
684 | if (a % i == 0)
685 | return false;
686 |
687 | return true;
688 | }
689 | }
690 | ```
691 |
692 | >*Homework-003-2. sorunun bir çözümü*
693 | >
694 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
695 |
696 | ```java
697 | package csd;
698 |
699 | class App {
700 | public static void main(String [] args)
701 | {
702 | IsPrimeXTest.run();
703 | }
704 | }
705 |
706 | class IsPrimeXTest {
707 |
708 | public static void run()
709 | {
710 | java.util.Scanner kb = new java.util.Scanner(System.in);
711 |
712 | System.out.print("Bir sayı giriniz:");
713 | long n = kb.nextLong();
714 |
715 | for (long i = 0; i <= n; ++i)
716 | if (NumberUtil.isPrimeX(i))
717 | System.out.println(i);
718 |
719 | System.out.println("Tekrar yapıyor musunuz?");
720 | }
721 | }
722 |
723 | class NumberUtil {
724 | public static boolean isPrimeX(long a)
725 | {
726 | boolean result;
727 |
728 | for (long sum = a; (result = isPrime(sum)) && sum > 9; sum = sumDigits(sum))
729 | ;
730 |
731 | return result;
732 | }
733 |
734 | public static int sumDigits(long a)
735 | {
736 | int sum = 0;
737 |
738 | while (a != 0) {
739 | sum += a % 10;
740 | a /= 10;
741 | }
742 |
743 | return Math.abs(sum);
744 | }
745 |
746 | public static boolean isPrime(long a)
747 | {
748 | if (a <= 1)
749 | return false;
750 |
751 | if (a % 2 == 0)
752 | return a == 2;
753 |
754 | if (a % 3 == 0)
755 | return a == 3;
756 |
757 | if (a % 5 == 0)
758 | return a == 5;
759 |
760 | if (a % 7 == 0)
761 | return a == 7;
762 |
763 | for (long i = 11; i * i <= a; i += 2)
764 | if (a % i == 0)
765 | return false;
766 |
767 | return true;
768 | }
769 | }
770 | ```
771 |
772 | >*Homework-003-3. sorunun bir çözümü*
773 | >
774 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
775 |
776 | ```java
777 | package csd;
778 |
779 | class App {
780 | public static void main(String [] args)
781 | {
782 | CalculateDigitalRootTest.run();
783 | }
784 | }
785 |
786 | class CalculateDigitalRootTest {
787 | public static void run()
788 | {
789 | java.util.Scanner kb = new java.util.Scanner(System.in);
790 |
791 | System.out.print("Bir sayı giriniz:");
792 | int n = kb.nextInt();
793 |
794 | for (int i = 0; i <= n; ++i)
795 | System.out.printf("%d sayısının basamaksal kökü: %d%n", i, NumberUtil.calculateDigitalRoot(i));
796 |
797 | System.out.println("Tekrar yapıyor musunuz?");
798 | }
799 | }
800 |
801 | class NumberUtil {
802 | public static int calculateDigitalRoot(int a)
803 | {
804 | int root = a;
805 |
806 | while ((root = sumDigits(root)) > 9)
807 | ;
808 |
809 | return root;
810 | }
811 |
812 | public static int sumDigits(long a)
813 | {
814 | int sum = 0;
815 |
816 | while (a != 0) {
817 | sum += a % 10;
818 | a /= 10;
819 | }
820 |
821 | return Math.abs(sum);
822 | }
823 | }
824 | ```
825 |
826 | >*Homework-003-3. sorunun bir çözümü*
827 | >
828 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
829 |
830 | ```java
831 | package csd;
832 |
833 | class App {
834 | public static void main(String [] args)
835 | {
836 | CalculateDigitalRootTest.run();
837 | }
838 | }
839 |
840 | class CalculateDigitalRootTest {
841 | public static void run()
842 | {
843 | java.util.Scanner kb = new java.util.Scanner(System.in);
844 |
845 | System.out.print("Bir sayı giriniz:");
846 | int n = kb.nextInt();
847 |
848 | for (int i = 0; i <= n; ++i)
849 | System.out.printf("%d sayısının basamaksal kökü: %d%n", i, NumberUtil.calculateDigitalRoot(i));
850 |
851 | System.out.println("Tekrar yapıyor musunuz?");
852 | }
853 | }
854 |
855 | class NumberUtil {
856 | public static int calculateDigitalRoot(int a)
857 | {
858 | int root = Math.abs(a);
859 |
860 | while (root > 9)
861 | root = sumDigits(root);
862 |
863 | return root;
864 | }
865 |
866 | public static int sumDigits(long a)
867 | {
868 | int sum = 0;
869 |
870 | while (a != 0) {
871 | sum += a % 10;
872 | a /= 10;
873 | }
874 |
875 | return Math.abs(sum);
876 | }
877 | }
878 | ```
879 |
880 | >*Homework-003-4. sorunun bir çözümü*
881 | >
882 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
883 |
884 | ```java
885 | package csd;
886 |
887 | class App {
888 | public static void main(String [] args)
889 | {
890 | IsFactorianTest.run();
891 | }
892 | }
893 |
894 | class IsFactorianTest {
895 | public static void run()
896 | {
897 | for (int i = 1; i <= 100_000; ++i)
898 | if (NumberUtil.isFactorian(i))
899 | System.out.printf("%d ", i);
900 |
901 | System.out.println();
902 | }
903 | }
904 |
905 | class NumberUtil {
906 | public static boolean isFactorian(int n)
907 | {
908 | return n > 0 && sumFactorialDigits(n) == n;
909 | }
910 |
911 | public static int sumFactorialDigits(int n)
912 | {
913 | int sum = 0;
914 |
915 | while (n != 0) {
916 | sum += factorial(n % 10);
917 | n /= 10;
918 | }
919 |
920 | return sum;
921 | }
922 |
923 | public static int factorial(int n)
924 | {
925 | int result = 1;
926 |
927 | for (int i = 2; i <= n; ++i)
928 | result *= i;
929 |
930 | return result;
931 | }
932 | }
933 | ```
934 |
935 | >*Homework-003-5. sorunun bir çözümü*
936 | >
937 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
938 |
939 | ```java
940 | package csd;
941 |
942 | class App {
943 | public static void main(String [] args)
944 | {
945 | IsSuperPrimeTest.run();
946 | }
947 | }
948 |
949 | class IsSuperPrimeTest {
950 | public static void run()
951 | {
952 | java.util.Scanner kb = new java.util.Scanner(System.in);
953 |
954 | for (;;) {
955 | System.out.print("Bir sayı giriniz:");
956 | long val = Long.parseLong(kb.nextLine());
957 |
958 | if (val == 0)
959 | break;
960 |
961 | if (!NumberUtil.isPrime(val))
962 | continue;
963 |
964 | if (NumberUtil.isSuperPrime(val))
965 | System.out.printf("%d sayısı süper asaldır%n", val);
966 | else
967 | System.out.printf("%d sayısı süper asal değildir%n", val);
968 | }
969 |
970 | System.out.println("Tekrar yapıyor musunuz?");
971 | }
972 | }
973 |
974 | class NumberUtil {
975 | public static boolean isSuperPrime(long a)
976 | {
977 | return isPrime(a) && isPrime(indexOfPrime(a));
978 | }
979 |
980 | public static int indexOfPrime(long a)
981 | {
982 | int i = 1;
983 | long val = 2;
984 |
985 | for (;;) {
986 | if (val == a)
987 | return i;
988 |
989 | if (isPrime(val))
990 | ++i;
991 |
992 | ++val;
993 | }
994 | }
995 |
996 | public static boolean isPrime(long a)
997 | {
998 | if (a <= 1)
999 | return false;
1000 |
1001 | if (a % 2 == 0)
1002 | return a == 2;
1003 |
1004 | if (a % 3 == 0)
1005 | return a == 3;
1006 |
1007 | if (a % 5 == 0)
1008 | return a == 5;
1009 |
1010 | if (a % 7 == 0)
1011 | return a == 7;
1012 |
1013 | for (long i = 11; i * i <= a; i += 2)
1014 | if (a % i == 0)
1015 | return false;
1016 |
1017 | return true;
1018 | }
1019 | }
1020 | ```
1021 |
1022 | >*Homework-003-6. sorunun bir çözümü*
1023 | >
1024 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
1025 |
1026 | ```java
1027 | package csd;
1028 |
1029 | class App {
1030 | public static void main(String [] args)
1031 | {
1032 | IsHardyRamanujanApp.run();
1033 | }
1034 | }
1035 |
1036 | class IsHardyRamanujanApp {
1037 | public static void run()
1038 | {
1039 | for (int n = 1; n < 100_000; ++n)
1040 | if (NumberUtil.isHardyRamanujan(n))
1041 | System.out.printf("%d ", n);
1042 |
1043 | System.out.println();
1044 | System.out.println("Tekrar yapıyor musunuz?");
1045 | }
1046 | }
1047 |
1048 | class NumberUtil {
1049 | public static boolean isHardyRamanujan(int n)
1050 | {
1051 | return n > 0 && getHardyRamanujanCount(n) == 2;
1052 | }
1053 |
1054 | public static int getHardyRamanujanCount(int n)
1055 | {
1056 | int count = 0;
1057 |
1058 | EXIT_LOOP:
1059 | for (int a = 1; a * a * a < n; ++a)
1060 | for (int b = a + 1; a * a * a + b * b * b <= n; ++b)
1061 | if (a * a * a + b * b * b == n) {
1062 | if (++count == 2)
1063 | break EXIT_LOOP;
1064 | ++a;
1065 | }
1066 |
1067 | return count;
1068 | }
1069 | }
1070 | ```
1071 |
1072 | >*Homework-003-7. sorunun bir çözümü*
1073 | >
1074 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
1075 |
1076 | ```java
1077 | package csd;
1078 |
1079 | class App {
1080 | public static void main(String [] args)
1081 | {
1082 | IsDecimalHarshadTest.run();
1083 | }
1084 | }
1085 |
1086 | class IsDecimalHarshadTest {
1087 | public static void run()
1088 | {
1089 | java.util.Scanner kb = new java.util.Scanner(System.in);
1090 |
1091 | System.out.print("Bir sayı giriniz:");
1092 | int n = kb.nextInt();
1093 |
1094 | while (n-- > 0)
1095 | if (NumberUtil.isDecimalHarshad(n + 1))
1096 | System.out.println(n + 1);
1097 | }
1098 | }
1099 |
1100 | class NumberUtil {
1101 | public static boolean isDecimalHarshad(int val)
1102 | {
1103 | return val > 0 && val % sumDigits(val) == 0;
1104 | }
1105 |
1106 | public static int sumDigits(long a)
1107 | {
1108 | int sum = 0;
1109 |
1110 | while (a != 0) {
1111 | sum += a % 10;
1112 | a /= 10;
1113 | }
1114 |
1115 | return Math.abs(sum);
1116 | }
1117 | }
1118 | ```
1119 |
1120 | >*Homework-003-8. sorunun bir çözümü*
1121 | >
1122 | >**Not:** Çözüm çalışma sorusunun verildiği tarihe kadar işlenmiş olan konulara göre yazılmıştır
1123 |
1124 | ```java
1125 | package csd;
1126 |
1127 | class App {
1128 | public static void main(String [] args)
1129 | {
1130 | PrintCollatzTest.run();
1131 | }
1132 | }
1133 |
1134 | class PrintCollatzTest {
1135 | public static void run()
1136 | {
1137 | java.util.Scanner kb = new java.util.Scanner(System.in);
1138 |
1139 | for (;;) {
1140 | System.out.print("Bir sayı giriniz:");
1141 | int n = Integer.parseInt(kb.nextLine());
1142 |
1143 | if (n == 0)
1144 | break;
1145 |
1146 | System.out.println("-----------------");
1147 | NumberUtil.printCollatz(n);
1148 | System.out.println("-----------------");
1149 | }
1150 | System.out.println("Tekrar yapıyor musunuz?");
1151 | }
1152 | }
1153 |
1154 | class NumberUtil {
1155 | public static void printCollatz(int n)
1156 | {
1157 | if (n <= 0) {
1158 | System.out.println("Geçersiz sayı!...");
1159 | return;
1160 | }
1161 |
1162 | System.out.println(n);
1163 |
1164 | while (n != 1) {
1165 | if (n % 2 == 0)
1166 | n /= 2;
1167 | else
1168 | n = 3 * n + 1;
1169 |
1170 | System.out.println(n);
1171 | }
1172 | }
1173 | }
1174 | ```
1175 |
1176 | >*Homework-003-8.sorunun bir çözümü*
1177 | >
1178 | >**Not:** Çözümde koşul operatörü kullanılmıştır
1179 |
1180 | ```java
1181 | package csd;
1182 |
1183 | class App {
1184 | public static void main(String [] args)
1185 | {
1186 | PrintCollatzTest.run();
1187 | }
1188 | }
1189 |
1190 | class PrintCollatzTest {
1191 | public static void run()
1192 | {
1193 | java.util.Scanner kb = new java.util.Scanner(System.in);
1194 |
1195 | for (;;) {
1196 | System.out.print("Bir sayı giriniz:");
1197 | int n = Integer.parseInt(kb.nextLine());
1198 |
1199 | if (n == 0)
1200 | break;
1201 |
1202 | System.out.println("-----------------");
1203 | NumberUtil.printCollatz(n);
1204 | System.out.println("-----------------");
1205 | }
1206 | System.out.println("Tekrar yapıyor musunuz?");
1207 | }
1208 | }
1209 |
1210 | class NumberUtil {
1211 | public static void printCollatz(int n)
1212 | {
1213 | if (n <= 0) {
1214 | System.out.println("Geçersiz sayı!...");
1215 | return;
1216 | }
1217 |
1218 | System.out.println(n);
1219 |
1220 | while (n != 1)
1221 | System.out.println(n = (n % 2 == 0) ? (n / 2) : (3 * n + 1));
1222 | }
1223 | }
1224 | ```
1225 |
1226 | #### Homework-005
1227 |
1228 | >*Homework-005-1.sorunun bir çözümü*
1229 | >
1230 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
1231 |
1232 | ```java
1233 | package csd;
1234 |
1235 | class App {
1236 | public static void main(String [] args)
1237 | {
1238 | System.out.println(Util.e());
1239 | }
1240 | }
1241 |
1242 | class Util {
1243 | public static double e()
1244 | {
1245 | double result = 2;
1246 |
1247 | for (int i = 2; i <= 8; ++i)
1248 | result += 1. / NumberUtil.factorial(i);
1249 |
1250 | return result;
1251 | }
1252 | }
1253 |
1254 | class NumberUtil {
1255 | public static int factorial(int n)
1256 | {
1257 | int result = 1;
1258 |
1259 | for (int i = 2; i <= n; ++i)
1260 | result *= i;
1261 |
1262 | return result;
1263 | }
1264 | }
1265 | ```
1266 |
1267 | >*Homework-XXX-X.sorunun bir çözümü*
1268 | >
1269 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
1270 |
1271 | ```java
1272 |
1273 | ```
1274 |
1275 | >*Homework-XXX-X.sorunun bir çözümü*
1276 | >
1277 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
1278 |
1279 | ```java
1280 |
1281 | ```
1282 |
1283 | >*Homework-XXX-X.sorunun bir çözümü*
1284 | >
1285 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
1286 |
1287 | ```java
1288 |
1289 | ```
1290 |
1291 | #### Homework-XXX
1292 |
1293 | >*Homework-XXX-X.sorunun bir çözümü*
1294 | >
1295 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
1296 |
1297 | ```java
1298 |
1299 | ```
1300 |
1301 | >*Homework-XXX-X.sorunun bir çözümü*
1302 | >
1303 | >**Not:** Çözüm çalışma sorusunun verildiği tarihte işlenmiş konulara göre yazılmıştır
1304 |
1305 | ```java
1306 |
1307 | ```
--------------------------------------------------------------------------------
/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 |
4 |
5 |
--------------------------------------------------------------------------------
/src/Sample/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/Sample/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Sample/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/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/people.txt:
--------------------------------------------------------------------------------
1 | Elif 18.07.1997
2 | Nurullah 23.08.2000
3 | Onur 28.07.2004
4 | Poyraz 23.07.2000
5 | Oğuz 10.09.1976
6 | Canan 12.01.1987
--------------------------------------------------------------------------------
/src/Sample/question.txt:
--------------------------------------------------------------------------------
1 | package org.csystem.app;
2 |
3 | class App {
4 | public static void main(String[] args)
5 | {
6 | final Sample s = new Sample(20);
7 |
8 | s.x = 10;
9 | }
10 | }
11 |
12 | class Sample {
13 | public int x;
14 |
15 | public Sample(int a)
16 | {
17 | x = a;
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/src/Sample/questions.txt:
--------------------------------------------------------------------------------
1 | package org.csystem.app;
2 |
3 | import org.csystem.app.Sample;
4 | import gorkem.Sample;
5 |
6 | class App {
7 | public static void main(String [] args)
8 | {
9 | Sample s;
10 | }
11 | }
12 |
13 | 1. Error oluşur ....
14 | 2. Derlenir arman paketi içerisindeki Sample olur
15 | 3. Derlenir gorkem paketi içerisindeki Sample olur
16 | 4. Hiçbiri. ...
17 |
18 |
19 | Ey Edip Adana'da pide ye
--------------------------------------------------------------------------------
/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 | }
9 |
10 | class B implements IA {
11 | //...
12 | public String foo(Boolean a)
13 | {
14 | //...
15 |
16 | return String.valueOf(a);
17 | }
18 | }
19 |
20 |
21 | interface IA {
22 | K foo(T t);
23 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/DemoCompanyApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company;
2 |
3 | import org.csystem.app.company.employee.Employee;
4 | import org.csystem.app.company.employee.Manager;
5 | import org.csystem.app.company.employee.ProjectWorker;
6 | import org.csystem.app.company.employee.SalesManager;
7 | import org.csystem.app.company.employee.Worker;
8 | import org.csystem.app.company.hr.HumanResources;
9 | import org.csystem.util.thread.ThreadUtil;
10 |
11 | import java.util.Random;
12 |
13 | public class DemoCompanyApp {
14 | private static Manager getManager()
15 | {
16 | return new Manager("Kaan Aslan", "12345678945", "Mecidiyeköy", "Yazılım", 300000);
17 | }
18 |
19 | private static Worker getWorker()
20 | {
21 | return new Worker("Güray Sönmez", "12345789321", "Bodrum", 400, 8);
22 | }
23 |
24 | private static ProjectWorker getProjectWorker()
25 | {
26 | return new ProjectWorker("Lokman Köse", "23456789233", "Çağlayan", 200, 8, "Dernek", 2000);
27 | }
28 |
29 | private static SalesManager getSalesManager()
30 | {
31 | return new SalesManager("Ali Serçe", "34567892345", "Geyikli", "Pazarlama", 400000, 30000);
32 | }
33 |
34 | private static Employee getEmployee(Random random)
35 | {
36 | return switch (random.nextInt(4)) {
37 | case 0 -> getWorker();
38 | case 1 -> getProjectWorker();
39 | case 2 -> getSalesManager();
40 | default -> getManager();
41 | };
42 | }
43 |
44 |
45 | public static void run()
46 | {
47 | Random random = new Random();
48 | HumanResources humanResources = new HumanResources();
49 |
50 | while (true) {
51 | Employee employee = getEmployee(random);
52 |
53 | humanResources.payInsurance(employee);
54 | ThreadUtil.sleep(1000);
55 | }
56 | }
57 |
58 | public static void main(String[] args)
59 | {
60 | run();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/employee/Employee.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company.employee;
2 |
3 | import org.csystem.app.company.employee.insurance.IInsured;
4 |
5 | public abstract class Employee implements IInsured {
6 | private String m_name;
7 | private String m_citizenId;
8 | private String m_address;
9 |
10 | //...
11 |
12 | protected Employee(String name, String citizenId, String address)
13 | {
14 | //...
15 | m_name = name;
16 | m_citizenId = citizenId;
17 | m_address = address;
18 | }
19 |
20 | public String getName()
21 | {
22 | return m_name;
23 | }
24 |
25 | public void setName(String name)
26 | {
27 | //...
28 | m_name = name;
29 | }
30 |
31 | public String getId()
32 | {
33 | return m_citizenId;
34 | }
35 |
36 | public void setId(String citizenId)
37 | {
38 | //...
39 | m_citizenId = citizenId;
40 | }
41 |
42 | public String getAddress()
43 | {
44 | return m_address;
45 | }
46 |
47 | public void setAddress(String address)
48 | {
49 | //...
50 | m_address = address;
51 | }
52 |
53 |
54 | //...
55 | }
56 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/employee/Manager.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company.employee;
2 |
3 | public class Manager extends Employee {
4 | private String m_department;
5 | private double m_salary;
6 |
7 | public Manager(String name, String citizenId, String address, String department, double salary)
8 | {
9 | super(name, citizenId, address);
10 | m_department = department;
11 | m_salary = salary;
12 | }
13 |
14 | public String getDepartment()
15 | {
16 | return m_department;
17 | }
18 |
19 | public void setDepartment(String department)
20 | {
21 | //...
22 | m_department = department;
23 | }
24 |
25 | public double getSalary()
26 | {
27 | return m_salary;
28 | }
29 |
30 | public void setSalary(double salary)
31 | {
32 | //...
33 | m_salary = salary;
34 | }
35 |
36 | public double calculateInsurancePayment()
37 | {
38 | return m_salary * 1.5;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/employee/ProjectWorker.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company.employee;
2 |
3 | public class ProjectWorker extends Worker {
4 | private String m_projectName;
5 | private double m_extraFee;
6 |
7 | public ProjectWorker(String name, String citizenId, String address, double feePerHour, int hourPerDay, String projectName, double extraFee)
8 | {
9 | super(name, citizenId, address, feePerHour, hourPerDay);
10 | m_projectName = projectName;
11 | m_extraFee = extraFee;
12 | }
13 |
14 | public String getProjectName()
15 | {
16 | return m_projectName;
17 | }
18 |
19 | public void setProjectName(String projectName)
20 | {
21 | m_projectName = projectName;
22 | }
23 |
24 | public double getExtraFee()
25 | {
26 | return m_extraFee;
27 | }
28 |
29 | public void setExtraFee(double extraFee)
30 | {
31 | m_extraFee = extraFee;
32 | }
33 |
34 | public double calculateInsurancePayment()
35 | {
36 | return super.calculateInsurancePayment() + m_extraFee * 30;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/employee/SalesManager.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company.employee;
2 |
3 | public class SalesManager extends Manager {
4 | private double m_saleExtra;
5 |
6 | public SalesManager(String name, String citizenId, String address, String department, double salary, double saleExtra)
7 | {
8 | super(name, citizenId, address, department, salary);
9 | m_saleExtra = saleExtra;
10 | }
11 |
12 | public double getSaleExtra()
13 | {
14 | return m_saleExtra;
15 | }
16 |
17 | public void setSaleExtra(double saleExtra)
18 | {
19 | m_saleExtra = saleExtra;
20 | }
21 |
22 | public double calculateInsurancePayment()
23 | {
24 | return super.calculateInsurancePayment() + m_saleExtra;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/employee/Worker.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company.employee;
2 |
3 | public class Worker extends Employee {
4 | private double m_feePerHour;
5 | private int m_hourPerDay;
6 |
7 | public Worker(String name, String citizenId, String address, double feePerHour, int hourPerDay)
8 | {
9 | super(name, citizenId, address);
10 | m_feePerHour = feePerHour;
11 | m_hourPerDay = hourPerDay;
12 | }
13 |
14 | public double getFeePerHour()
15 | {
16 | return m_feePerHour;
17 | }
18 |
19 | public void setFeePerHour(double feePerHour)
20 | {
21 | m_feePerHour = feePerHour;
22 | }
23 |
24 | public int getHourPerDay()
25 | {
26 | return m_hourPerDay;
27 | }
28 |
29 | public void setHourPerDay(int hourPerDay)
30 | {
31 | m_hourPerDay = hourPerDay;
32 | }
33 |
34 | public double calculateInsurancePayment()
35 | {
36 | return m_feePerHour * m_hourPerDay * 30;
37 | }
38 |
39 | //...
40 | }
41 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/employee/insurance/IInsured.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company.employee.insurance;
2 |
3 | public interface IInsured {
4 | String getId();
5 | double calculateInsurancePayment();
6 | }
7 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/company/hr/HumanResources.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.company.hr;
2 |
3 | import org.csystem.app.company.employee.insurance.IInsured;
4 | import org.csystem.util.console.Console;
5 |
6 | public class HumanResources {
7 | //...
8 |
9 | public void payInsurance(IInsured insured)
10 | {
11 | Console.writeLine("--------------------------------------------------------");
12 | Console.writeLine("CitizenId:%s", insured.getId());
13 | Console.writeLine("Insurance payment:%f", insured.calculateInsurancePayment());
14 | Console.writeLine("--------------------------------------------------------");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/datetime/DateUtil.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.datetime;
2 |
3 | public class DateUtil {
4 | private static final int [] DAYS_OF_MONTHS = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
5 | private static final String [] DAYS_OF_WEEK_TR = {"Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi"};
6 | private static final String [] DAYS_OF_WEEK_EN = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
7 | private static final String [] MONTHS_TR = {"", "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran",
8 | "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"};
9 | private static final String [] MONTHS_EN = {"", "January", "February", "March", "April", "May", "June",
10 | "July", "August", "September", "October", "November", "December"};
11 |
12 | public static void printDateTR(int day, int month, int year)
13 | {
14 | if (!isValidDate(day, month, year)) {
15 | System.out.println("Geçersiz tarih!...");
16 | return;
17 | }
18 |
19 | System.out.println(getDateStrTR(day, month, year));
20 | }
21 |
22 | public static void printDateEN(int day, int month, int year)
23 | {
24 | if (!isValidDate(day, month, year)) {
25 | System.out.println("Invalid date!...");
26 | return;
27 | }
28 |
29 | System.out.println(getDateStrEN(day, month, year));
30 | }
31 |
32 | public static String getDateStrTR(int day, int month, int year)
33 | {
34 | return "%d %s %d %s".formatted(day, MONTHS_TR[month], year, DAYS_OF_WEEK_TR[getDayOfWeek(day, month, year)]);
35 | }
36 |
37 | public static String getDateStrEN(int day, int month, int year)
38 | {
39 | return "%d%s %s %d %s".formatted(day, getDaySuffix(day), MONTHS_EN[month], year,
40 | DAYS_OF_WEEK_EN[getDayOfWeek(day, month, year)]);
41 | }
42 |
43 | public static String getDaySuffix(int day)
44 | {
45 | return switch (day) {
46 | case 1, 21, 31 -> "st";
47 | case 2, 22 -> "nd";
48 | case 3, 23 -> "rd";
49 | default -> "th";
50 | };
51 | }
52 |
53 | public static int getDayOfWeek(int day, int month, int year)
54 | {
55 | int totalDays = getDayOfYear(day, month, year);
56 |
57 | for (int y = 1900; y < year; ++y) {
58 | totalDays += 365;
59 | if (isLeapYear(y))
60 | ++totalDays;
61 | }
62 |
63 | return totalDays % 7;
64 | }
65 |
66 |
67 | public static int getDayOfYear(int day, int month, int year)
68 | {
69 | int dayOfYear = day;
70 |
71 | for (int m = month - 1; m >= 1; --m)
72 | dayOfYear += DAYS_OF_MONTHS[m];
73 |
74 | if (month > 2 && isLeapYear(year))
75 | ++dayOfYear;
76 |
77 | return dayOfYear;
78 | }
79 |
80 | public static boolean isValidDate(int day, int month, int year)
81 | {
82 | return 1 <= day && day <= 31 && 1 <= month && month <= 12 && day <= getDays(month, year);
83 | }
84 |
85 | public static int getDays(int month, int year)
86 | {
87 | return month == 2 && isLeapYear(year) ? 29 : DAYS_OF_MONTHS[month];
88 | }
89 |
90 | public static boolean isLeapYear(int year)
91 | {
92 | return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/datetime/DemoDateApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.datetime;
2 |
3 | import java.util.Scanner;
4 |
5 | class DemoDateApp {
6 | public static void run()
7 | {
8 | Scanner kb = new Scanner(System.in);
9 |
10 | while (true) {
11 | System.out.print("Gün, ay ve yıl bilgilerini giriniz:");
12 | int day = kb.nextInt();
13 | int month = kb.nextInt();
14 | int year = kb.nextInt();
15 |
16 | DateUtil.printDateTR(day, month, year);
17 | DateUtil.printDateEN(day, month, year);
18 |
19 | if (day == 0 && month == 0 && year == 0)
20 | break;
21 | }
22 |
23 | System.out.println("Tekrar yapıyor musunuz?");
24 | }
25 |
26 | public static void main(String[] args)
27 | {
28 | run();
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/generator/DemoObjectArrayGeneratorApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.generator;
2 |
3 | import org.csystem.generator.object.ObjectArrayGenerator;
4 | import org.csystem.math.Complex;
5 | import org.csystem.math.geometry.Circle;
6 | import org.csystem.math.geometry.Point;
7 | import org.csystem.wrapper.primitive.IntValue;
8 |
9 | import java.util.Scanner;
10 |
11 | public class DemoObjectArrayGeneratorApp {
12 | public static void run()
13 | {
14 | Scanner kb = new Scanner(System.in);
15 | System.out.print("Input a number:");
16 | int count = kb.nextInt();
17 | ObjectArrayGenerator generator = new ObjectArrayGenerator();
18 |
19 | for (Object o : generator.createObjects(count)) {
20 | System.out.println("-------------------------------------------------------------------------------------");
21 | System.out.printf("Dynamic type:%s%n", o.getClass().getName());
22 |
23 | if (o instanceof String s) {
24 | String upper = s.toUpperCase();
25 |
26 | System.out.printf("Text:%s, Upper:%s%n", s, upper);
27 | }
28 | else if (o instanceof Integer) {
29 | int val = (int)o;
30 |
31 | System.out.printf("%d * %d = %d%n", val, val, val * val);
32 | }
33 | else if (o instanceof Character) {
34 | char ch = (char)o;
35 |
36 | System.out.printf("ch = %c%n", ch);
37 | }
38 | else if (o instanceof Boolean) {
39 | boolean flag = (boolean)o;
40 |
41 | System.out.printf("flag = %b%n", flag);
42 | }
43 | else if (o instanceof Point p)
44 | System.out.printf("Distance to origin:%f%n", p.euclideanDistance());
45 | else if (o instanceof Circle c)
46 | System.out.printf("Radius:%f, Area:%f, Circumference:%f%n", c.getRadius(), c.getArea(), c.getCircumference());
47 | else if (o instanceof Complex c)
48 | System.out.printf("||%s|| = %f%n", c.toString(), c.getLength());
49 |
50 | System.out.println("-------------------------------------------------------------------------------------");
51 | }
52 | }
53 |
54 | public static void main(String[] args)
55 | {
56 | run();
57 | }
58 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/generator/DemoPointListGeneratorApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.generator;
2 |
3 | import org.csystem.generator.random.point.RandomPointGenerator;
4 | import org.csystem.util.console.Console;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Random;
8 |
9 | public class DemoPointListGeneratorApp {
10 | public static void run()
11 | {
12 | RandomPointGenerator generator = new RandomPointGenerator(new Random(), -1000, 1000);
13 | int count = Console.readInt("Input number of points:");
14 |
15 | ArrayList points = new ArrayList<>();
16 |
17 | generator.addPoints(points, count);
18 |
19 | for (Object o : points)
20 | Console.write("%s ", o);
21 |
22 | Console.writeLine();
23 |
24 | Console.writeLine(points);
25 | }
26 |
27 | public static void main(String[] args)
28 | {
29 | run();
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/io/concat/ConcatFilesApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.io.concat;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.FileOutputStream;
7 | import java.io.IOException;
8 |
9 | import static org.csystem.util.console.CommandLineArgsUtil.checkLengthGreater;
10 |
11 | public class ConcatFilesApp {
12 | public static void appendFile(FileOutputStream fos, String srcPath) throws IOException
13 | {
14 | try (FileInputStream fis = new FileInputStream(srcPath)) {
15 | fos.write(fis.readAllBytes());
16 | }
17 | }
18 |
19 | public static void concatFiles(FileOutputStream fos, String [] args) throws IOException
20 | {
21 | try (fos) {
22 | for (int i = 0; i < args.length - 1; ++i) {
23 | appendFile(fos, args[i]);
24 | }
25 | }
26 | catch (FileNotFoundException ex) {
27 | new File(args[args.length - 1]).delete();
28 | }
29 | }
30 |
31 | public static void run(String[] args)
32 | {
33 | checkLengthGreater(2, args.length, "wrong number of arguments");
34 |
35 | try {
36 | FileOutputStream fos = new FileOutputStream(args[args.length - 1]);
37 |
38 | concatFiles(fos, args);
39 | }
40 | catch (IOException ex) {
41 | System.err.printf("IO Exception occurred:%s%n", ex.getMessage());
42 | }
43 | }
44 |
45 | public static void main(String[] args)
46 | {
47 | run(args);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/io/input/ReadLinesViaScannerApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.io.input;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Path;
5 | import java.util.NoSuchElementException;
6 | import java.util.Scanner;
7 |
8 | import static org.csystem.util.console.CommandLineArgsUtil.checkLengthEquals;
9 |
10 | public class ReadLinesViaScannerApp {
11 | private static void readLines(Scanner s)
12 | {
13 | try (s) {
14 | while (true) {
15 | String line = s.nextLine();
16 |
17 | System.out.println(line);
18 | }
19 | }
20 | catch (NoSuchElementException ex) {
21 | System.out.println("All lines read successfully");
22 | }
23 | }
24 |
25 | public static void run(String[] args)
26 | {
27 | checkLengthEquals(1, args.length, "wrong number of arguments");
28 |
29 | try {
30 | Scanner s = new Scanner(Path.of(args[0]));
31 |
32 | readLines(s);
33 | }
34 | catch (IOException ex) {
35 | System.err.printf("Exception occurred:%s%n", ex.getMessage());
36 | }
37 | }
38 | public static void main(String[] args)
39 | {
40 | run(args);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/lottery/numeric/NumericLottery.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.lottery.numeric;
2 |
3 | import java.util.random.RandomGenerator;
4 |
5 | public class NumericLottery {
6 | private final RandomGenerator m_randomGenerator;
7 |
8 | private boolean [] getFlags()
9 | {
10 | boolean [] flags = new boolean[50];
11 |
12 | for (int i = 0; i < 6; ++i) {
13 | int val;
14 |
15 | do
16 | val = m_randomGenerator.nextInt(1, 50);
17 | while (flags[val]);
18 |
19 | flags[val] = true;
20 | }
21 |
22 | return flags;
23 | }
24 |
25 | private int [] getNumbers(boolean [] flags)
26 | {
27 | int [] a = new int[6];
28 | int idx = 0;
29 |
30 | for (int i = 1; i < flags.length; ++i)
31 | if (flags[i])
32 | a[idx++] = i;
33 |
34 | return a;
35 | }
36 |
37 | public NumericLottery(RandomGenerator randomGenerator)
38 | {
39 | if (randomGenerator == null)
40 | throw new IllegalArgumentException("Argument can not be null");
41 |
42 | m_randomGenerator = randomGenerator;
43 | }
44 |
45 | public int [] getNumbers()
46 | {
47 | return getNumbers(getFlags());
48 | }
49 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/lottery/numeric/NumericLotteryApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.lottery.numeric;
2 |
3 | import org.csystem.util.array.ArrayUtil;
4 |
5 | import java.util.Random;
6 | import java.util.Scanner;
7 |
8 | public class NumericLotteryApp {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | NumericLottery numericLottery = new NumericLottery(new Random());
13 |
14 | while (true) {
15 | System.out.print("Kaç tane kupon oynamak istersiniz?");
16 | int n = Integer.parseInt(kb.nextLine());
17 |
18 | if (n <= 0) {
19 | System.out.println("Lütfen pozitif bir sayı giriniz");
20 | continue;
21 | }
22 |
23 | while (n-- > 0)
24 | ArrayUtil.print(numericLottery.getNumbers(), 2);
25 | }
26 | }
27 |
28 | public static void main(String[] args)
29 | {
30 | run();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/school/GradeInfo.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.school;
2 |
3 | public class GradeInfo {
4 | public String number;
5 | public String name;
6 | public String birthDate;
7 | public String lectureName;
8 | public int midtermGrade;
9 | public int finalGrade;
10 |
11 | //...
12 | public double getGrade()
13 | {
14 | return 0.4 * midtermGrade + 0.6 * finalGrade;
15 | }
16 | //...
17 | }
18 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/school/GradeInfoApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.school;
2 |
3 | import java.util.Scanner;
4 |
5 | public class GradeInfoApp {
6 | public static void run()
7 | {
8 | Scanner kb = new Scanner(System.in);
9 |
10 | while (true) {
11 | System.out.print("Input text:");
12 | String s = kb.nextLine();
13 |
14 | if ("quit".equals(s))
15 | break;
16 |
17 | GradeInfo gradeInfo = GradeInfoHelper.parse(s);
18 |
19 | GradeInfoHelper.printReport(gradeInfo);
20 | }
21 | }
22 |
23 | public static void main(String[] args)
24 | {
25 | run();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/school/GradeInfoHelper.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.school;
2 |
3 | import static java.lang.Integer.parseInt;
4 | import static org.csystem.app.datetime.DateUtil.getDateStrTR;
5 |
6 | public class GradeInfoHelper {
7 | public static GradeInfo parse(String s)
8 | {
9 | String [] info = s.split("[:]+");
10 |
11 | //...
12 |
13 | String [] birthDateInfo = info[2].split("[/]+");
14 | GradeInfo gradeInfo = new GradeInfo();
15 |
16 | gradeInfo.number = info[0];
17 | gradeInfo.name = info[1];
18 | gradeInfo.birthDate = getDateStrTR(parseInt(birthDateInfo[0]), parseInt(birthDateInfo[1]), parseInt(birthDateInfo[2]));
19 | gradeInfo.lectureName = info[3];
20 | gradeInfo.midtermGrade = parseInt(info[4]);
21 | gradeInfo.finalGrade = parseInt(info[5]);
22 |
23 | return gradeInfo;
24 | }
25 |
26 | public static void printReport(GradeInfo gradeInfo)
27 | {
28 | double grade = gradeInfo.getGrade();
29 |
30 | System.out.printf("Student Number:%s%n", gradeInfo.number);
31 | System.out.printf("Fullname:%s%n", gradeInfo.name);
32 | System.out.printf("Birth Date:%s%n", gradeInfo.birthDate);
33 | System.out.printf("Lecture Name:%s%n", gradeInfo.lectureName);
34 | System.out.printf("Midterm grade:%d%n", gradeInfo.midtermGrade);
35 | System.out.printf("Final grade:%d%n", gradeInfo.finalGrade);
36 | System.out.printf("Grade:%.1f%n", grade);
37 | System.out.printf("Status:%s%n", grade > 50 ? "Success" : "Fail");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/simulation/grades/Classroom.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.simulation.grades;
2 |
3 | public class Classroom {
4 | private final GradeInfo [] m_grades;
5 |
6 | //...
7 |
8 | public Classroom(int nStudents)
9 | {
10 | m_grades = new GradeInfo[nStudents];
11 | }
12 |
13 | public void setGrade(int i, GradeInfo gradeInfo)
14 | {
15 | m_grades[i] = gradeInfo;
16 | }
17 |
18 | public GradeInfo getGradeInfo(int i)
19 | {
20 | return m_grades[i];
21 | }
22 |
23 | public int getNumberOfStudents()
24 | {
25 | return m_grades.length;
26 | }
27 |
28 | public int [] getHistogramData(int maxGrade)
29 | {
30 | int [] data = new int[maxGrade + 1];
31 |
32 | for (GradeInfo gradeInfo : m_grades)
33 | ++data[gradeInfo.getGrade()];
34 |
35 | return data;
36 | }
37 |
38 | public String toString()
39 | {
40 | StringBuilder sb = new StringBuilder("[");
41 | String delimiter = ", ";
42 |
43 | for (GradeInfo gi : m_grades)
44 | sb.append(gi.toString()).append(delimiter);
45 |
46 | return sb.substring(0, sb.length() - delimiter.length()) + "]";
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/simulation/grades/Exam.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.simulation.grades;
2 |
3 | public class Exam {
4 | private String m_lectureName;
5 | private final Classroom [] m_classrooms;
6 | private final double [] m_averages;
7 | private double m_average;
8 | private final int m_maxGrade;
9 |
10 | public Exam(String lectureName, int nClasses)
11 | {
12 | m_lectureName = lectureName;
13 | m_classrooms = new Classroom[nClasses];
14 | m_averages = new double[nClasses];
15 | m_maxGrade = 10;
16 | }
17 |
18 | public Exam(String lectureName, int nClasses, int maxGrade)
19 | {
20 | m_lectureName = lectureName;
21 | m_classrooms = new Classroom[nClasses];
22 | m_averages = new double[nClasses];
23 | m_maxGrade = maxGrade;
24 | }
25 |
26 | public String getLectureName()
27 | {
28 | return m_lectureName;
29 | }
30 |
31 | public void setLectureName(String lectureName)
32 | {
33 | m_lectureName = lectureName;
34 | }
35 |
36 | public Classroom getClassroom(int i)
37 | {
38 | return m_classrooms[i];
39 | }
40 |
41 | public double getGrade(int i, int k)
42 | {
43 | return getGradeInfo(i, k).getGrade();
44 | }
45 |
46 | public GradeInfo getGradeInfo(int i, int k)
47 | {
48 | return m_classrooms[i].getGradeInfo(k);
49 | }
50 |
51 | public int getNumberOfClassrooms()
52 | {
53 | return m_classrooms.length;
54 | }
55 |
56 | public int getNumberOfStudents(int i)
57 | {
58 | return m_classrooms[i].getNumberOfStudents();
59 | }
60 |
61 | public void setClassroom(int i, Classroom classroom)
62 | {
63 | m_classrooms[i] = classroom;
64 | }
65 |
66 | public void setGrade(int i, int k, GradeInfo gradeInfo)
67 | {
68 | m_classrooms[i].setGrade(k, gradeInfo);
69 | }
70 |
71 | public double getAverage(int i)
72 | {
73 | return m_averages[i];
74 | }
75 |
76 | public double getAverage()
77 | {
78 | return m_average;
79 | }
80 |
81 | public int getMaxGrade()
82 | {
83 | return m_maxGrade;
84 | }
85 |
86 | public int [] getHistogramData()
87 | {
88 | int [] data = new int[m_maxGrade + 1];
89 |
90 | for (Classroom classroom : m_classrooms) {
91 | int nStudents = classroom.getNumberOfStudents();
92 |
93 | for (int i = 0; i < nStudents; ++i)
94 | ++data[classroom.getGradeInfo(i).getGrade()];
95 | }
96 |
97 | return data;
98 | }
99 | //...
100 |
101 | public void calculate()
102 | {
103 | int totalNumberOfStudents = 0;
104 | int totalGrades = 0;
105 |
106 | for (int i = 0; i < m_classrooms.length; ++i) {
107 | int totalClassNumberOfStudents = m_classrooms[i].getNumberOfStudents();
108 | int totalClassroomGrades = 0;
109 |
110 | for (int k = 0; k < totalClassNumberOfStudents; ++k) {
111 | GradeInfo gradeInfo = m_classrooms[i].getGradeInfo(k);
112 |
113 | totalClassroomGrades += gradeInfo.getGrade();
114 | }
115 |
116 | m_averages[i] = (double) totalClassroomGrades / totalClassNumberOfStudents;
117 | totalGrades += totalClassroomGrades;
118 | totalNumberOfStudents += totalClassNumberOfStudents;
119 | }
120 |
121 | m_average = (double) totalGrades / totalNumberOfStudents;
122 | }
123 | //...
124 | }
125 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/simulation/grades/ExamSimulation.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.simulation.grades;
2 |
3 | import org.csystem.util.array.ArrayUtil;
4 | import org.csystem.util.string.StringUtil;
5 |
6 | import java.util.Random;
7 | import java.util.Scanner;
8 |
9 | public class ExamSimulation {
10 | private final String m_lectureName;
11 | private Exam m_exam;
12 |
13 | private static void drawHistogram(Classroom classroom, int maxGrade)
14 | {
15 | int [] data = classroom.getHistogramData(maxGrade);
16 | ArrayUtil.print(data);
17 | ArrayUtil.drawHistogram(data, 20, '-');
18 | }
19 |
20 | private static void setGrades(Classroom classroom)
21 | {
22 | Random random = new Random();
23 | int n = classroom.getNumberOfStudents();
24 |
25 | for (int i = 0; i < n; ++i) {
26 | String firstName = StringUtil.generateRandomTextEN(random, random.nextInt(5, 11));
27 | String lastName = StringUtil.generateRandomTextEN(random, random.nextInt(5, 11));
28 |
29 | classroom.setGrade(i, new GradeInfo("%s %s".formatted(firstName, lastName), random.nextInt(11)));
30 | }
31 | }
32 |
33 | private static Exam createExam(String lectureName, int nClasses, Scanner kb)
34 | {
35 | Exam exam = new Exam(lectureName, nClasses);
36 |
37 | for (int i = 0; i < nClasses; ++i) {
38 | System.out.printf("Input number of students of classroom %d:", i + 1);
39 | Classroom classroom = new Classroom(Integer.parseInt(kb.nextLine()));
40 |
41 | setGrades(classroom);
42 | exam.setClassroom(i, classroom);
43 | }
44 |
45 | return exam;
46 | }
47 |
48 | private void printReport()
49 | {
50 | int nClasses = m_exam.getNumberOfClassrooms();
51 | System.out.printf("Grades of lecture %s:%n", m_exam.getLectureName());
52 |
53 | for (int i = 0; i < nClasses; ++i) {
54 | int nStudents = m_exam.getNumberOfStudents(i);
55 | System.out.printf("Classroom %d -> ", i + 1);
56 | for (int k = 0; k < nStudents; ++k)
57 | System.out.printf("%s ", m_exam.getGradeInfo(i, k).toString());
58 |
59 | System.out.printf("Average:%f%n", m_exam.getAverage(i));
60 | }
61 |
62 | System.out.printf("School Average:%f%n", m_exam.getAverage());
63 | }
64 |
65 | private void drawHistogram()
66 | {
67 | int nClasses = m_exam.getNumberOfClassrooms();
68 |
69 | for (int i = 0; i < nClasses; ++i) {
70 | System.out.printf("Data of classroom %d%n", i + 1);
71 | drawHistogram(m_exam.getClassroom(i), m_exam.getMaxGrade());
72 | }
73 |
74 | System.out.printf("Histogram of %s lecture:%n", m_exam.getLectureName());
75 | int [] data = m_exam.getHistogramData();
76 |
77 | ArrayUtil.print(data);
78 | ArrayUtil.drawHistogram(data, 20, '-');
79 | }
80 |
81 | public ExamSimulation(String lectureName)
82 | {
83 | m_lectureName = lectureName;
84 | }
85 |
86 | public void run()
87 | {
88 | Scanner kb = new Scanner(System.in);
89 |
90 | System.out.print("Input number of classrooms:");
91 | int n = Integer.parseInt(kb.nextLine());
92 |
93 | m_exam = createExam(m_lectureName, n, kb);
94 | m_exam.calculate();
95 | printReport();
96 | System.out.println("Histogram:");
97 | drawHistogram();
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/simulation/grades/ExamSimulationApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.simulation.grades;
2 |
3 | import org.csystem.util.console.CommandLineArgsUtil;
4 |
5 | public class ExamSimulationApp {
6 | public static void run(String [] args)
7 | {
8 | CommandLineArgsUtil.checkLengthEquals(1, args.length, "wrong number of arguments");
9 | ExamSimulation examSimulation = new ExamSimulation(args[0]);
10 |
11 | examSimulation.run();
12 | }
13 |
14 | public static void main(String[] args)
15 | {
16 | run(args);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/simulation/grades/GradeInfo.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.simulation.grades;
2 |
3 | public class GradeInfo {
4 | private String m_studentName;
5 | private int m_grade;
6 |
7 | public GradeInfo(String studentName, int grade)
8 | {
9 | //...
10 | m_studentName = studentName;
11 | m_grade = grade;
12 | }
13 |
14 | public String getStudentName()
15 | {
16 | return m_studentName;
17 | }
18 |
19 | public void setName(String studentName)
20 | {
21 | m_studentName = studentName;
22 | }
23 |
24 | public int getGrade()
25 | {
26 | return m_grade;
27 | }
28 |
29 | public void setGrade(int grade)
30 | {
31 | //...
32 | m_grade = grade;
33 | }
34 |
35 | public String toString()
36 | {
37 | return "%s, %d".formatted(m_studentName, m_grade);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/app/string/join/JoinWithTwoHyphenApp.java:
--------------------------------------------------------------------------------
1 | package org.csystem.app.string.join;
2 |
3 | import org.csystem.util.console.Console;
4 | import org.csystem.util.string.StringUtil;
5 |
6 | import java.util.ArrayList;
7 |
8 | public class JoinWithTwoHyphenApp {
9 | public static void run()
10 | {
11 | ArrayList texts = new ArrayList<>();
12 | String s;
13 |
14 | while (!(s = Console.readString("Input a text:")).equals("exit"))
15 | texts.add(s);
16 |
17 | String str = StringUtil.join(texts, "--");
18 |
19 | Console.writeLine("(%s)", str);
20 | }
21 | public static void main(String[] args)
22 | {
23 | run();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/datetime/Date.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------------------------------------------------------------
2 | Aşağıda bildirilen Date sınıfını açıklamalara göre yazınız
3 | Açıklamalar:
4 | - Sınıf bir tarihi temsil edecektir (gün, ay ve yıl)
5 |
6 | - JavaSE'nin veya başka bir kütüphanenin tarih zaman işlemlerine ilişkin sınıfları ve metotları kullanılmayacaktır
7 |
8 | - Sınıfın public bölümünü değiştirmeden istediğiniz eklemeyi/çıkarmayı yapabilirsiniz
9 |
10 | - Sınıf geçersiz tarih durumunu kontrol edecektir. Geçersizlik durumunda uygun mesaj ile birlikte, yazılmış olan
11 | DateTimeException fırlatılacaktır
12 |
13 | - Sınıf DayOfWeek ve Month enum class'larını kullanmaktadır. enum class'ların sabitlerini değiştirmeden istediğiniz
14 | eklemeyi yapabilirsiniz. Bu anlamda sabitlere değer iliştirebilirsiniz
15 |
16 | - Daha önce yazılmış olan DateUtil sınıfı içerisindeki metotlardan yararlanabilirsiniz. Ancak sınıf, DateUtil
17 | sınıfını kullanmayacaktır.
18 |
19 | - Ay bilgisini değer olarak alan veya değer olarak geri döndüren metotlar için değer [1, 12] aralığında olacaktır
20 |
21 | - Sınıfa ilişkin test kodlarını da yazınız
22 | -----------------------------------------------------------------------------------------------------------------------*/
23 |
24 | /**
25 | * Date class that represents a date
26 | * Last Update: 20th May 2025
27 | * @author Java-Jan-2024 Group
28 | */
29 |
30 | package org.csystem.datetime;
31 |
32 | public class Date {
33 | private static final int [] DAYS_OF_MONTHS;
34 | private static final String [] DAY_OF_WEEKS_TR;
35 | private static final String [] DAY_OF_WEEKS_EN;
36 | private static final String [] MONTHS_TR;
37 | private static final String [] MONTHS_EN;
38 |
39 | static {
40 | DAYS_OF_MONTHS = new int[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
41 | DAY_OF_WEEKS_TR = new String[]{"Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi"};
42 | DAY_OF_WEEKS_EN = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
43 | MONTHS_TR = new String[]{"", "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos",
44 | "Eylül", "Ekim", "Kasım", "Aralık"};
45 | MONTHS_EN = new String[]{"", "January", "February", "March", "April", "May", "June", "July", "August",
46 | "September", "October", "November", "December"};
47 | }
48 |
49 | public Date(int day, int monthValue, int year)
50 | {
51 | throw new UnsupportedOperationException("TODO:");
52 | }
53 |
54 | public Date(int day, Month month, int year)
55 | {
56 | throw new UnsupportedOperationException("TODO:");
57 | }
58 |
59 | public int getDay()
60 | {
61 | throw new UnsupportedOperationException("TODO:");
62 | }
63 |
64 | public void setDay(int day)
65 | {
66 | throw new UnsupportedOperationException("TODO:");
67 | }
68 |
69 | public int getMonthValue()
70 | {
71 | throw new UnsupportedOperationException("TODO:");
72 | }
73 |
74 | public void setMonthValue(int monthValue)
75 | {
76 | throw new UnsupportedOperationException("TODO:");
77 | }
78 |
79 | public Month getMonth()
80 | {
81 | throw new UnsupportedOperationException("TODO:");
82 | }
83 |
84 | public void setMonth(Month month)
85 | {
86 | throw new UnsupportedOperationException("TODO:");
87 | }
88 |
89 | public int getYear()
90 | {
91 | throw new UnsupportedOperationException("TODO:");
92 | }
93 |
94 | public void setYear(int year)
95 | {
96 | throw new UnsupportedOperationException("TODO:");
97 | }
98 |
99 | public DayOfWeek getDayOfWeek()
100 | {
101 | throw new UnsupportedOperationException("TODO:");
102 | }
103 |
104 | public String getDayOfWeekEN()
105 | {
106 | throw new UnsupportedOperationException("TODO:");
107 | }
108 |
109 | public String getDayOfWeekTR()
110 | {
111 | throw new UnsupportedOperationException("TODO:");
112 | }
113 |
114 | public boolean isLeapYear()
115 | {
116 | throw new UnsupportedOperationException("TODO:");
117 | }
118 |
119 | public boolean isWeekday()
120 | {
121 | throw new UnsupportedOperationException("TODO:");
122 | }
123 |
124 | public boolean isWeekend()
125 | {
126 | throw new UnsupportedOperationException("TODO:");
127 | }
128 |
129 | public String toString()
130 | {
131 | throw new UnsupportedOperationException("TODO -> 01/04/2023");
132 | }
133 |
134 | public String toString(char delimiter)
135 | {
136 | throw new UnsupportedOperationException("TODO -> if delimiter is . then 01.04.2023");
137 | }
138 |
139 | public boolean equals(Object other)
140 | {
141 | throw new UnsupportedOperationException("TODO:");
142 | }
143 |
144 | public String toLongDateStringTR()
145 | {
146 | throw new UnsupportedOperationException("TODO -> 1 Nisan 2023 Cumartesi");
147 | }
148 |
149 | public String toLongDateStringEN()
150 | {
151 | throw new UnsupportedOperationException("TODO -> 1st April 2023 Saturday ");
152 | }
153 |
154 | public String toShortDateStringTR()
155 | {
156 | throw new UnsupportedOperationException("TODO -> 1 Nisan 2023");
157 | }
158 |
159 | public String toShortDateStringEN()
160 | {
161 | throw new UnsupportedOperationException("TODO -> 1st April 2023");
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/datetime/DateTime.java:
--------------------------------------------------------------------------------
1 | /**
2 | * DateTime class that represents a date and time
3 | * Last Update: 20th May 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.datetime;
7 |
8 | public class DateTime {
9 | private Date m_date;
10 | private Time m_time;
11 |
12 | //...
13 | }
14 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/datetime/DateTimeException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Exception class for date/time operations
3 | * Last Update: 20th May 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.datetime;
7 |
8 | public class DateTimeException extends RuntimeException {
9 | public DateTimeException(String message)
10 | {
11 | super(message);
12 | }
13 |
14 | public String getMessage()
15 | {
16 | return String.format("Invalid date and/or time values:%s", super.getMessage());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/datetime/DayOfWeek.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Day of weeks
3 | * Last Update: 20th May 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.datetime;
7 |
8 | public enum DayOfWeek {
9 | SUN, MON, TUE, WED, THU, FRI, SAT
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/datetime/Month.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Months
3 | * Last Update: 20th May 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.datetime;
7 |
8 | public enum Month {
9 | JAN(31), FEB(28), MAR(31), APR(30), MAY(31), JUN(30), JUL(31), AUG(31), SEP(30), OCT(31), NOV(30), DEC(31);
10 | private final int m_days;
11 |
12 | Month(int days)
13 | {
14 | m_days = days;
15 | }
16 |
17 | static boolean isLeapYear(int year)
18 | {
19 | return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
20 | }
21 |
22 | public int getDays(int year)
23 | {
24 | return ordinal() == 1 && isLeapYear(year) ? 29 : m_days;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/datetime/Time.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------------------------------------------------------------
2 | Aşağıda bildirilen Time sınıfını açıklamalara göre yazınız
3 | Açıklamalar:
4 | - Sınıf bir zamanı temsil edecektir (saat, dakika, saniye, milisaniye)
5 |
6 | - JavaSE'nin veya başka bir kütüphanenin tarih zaman işlemlerine ilişkin sınıfları ve metotları kullanılmayacaktır
7 |
8 | - Sınıfın public bölümünü değiştirmeden istediğiniz eklemeyi yapabilirsiniz
9 |
10 | - Sınıf geçersiz zaman durumunu kontrol edecektir. Geçersizlik durumunda uygun mesaj ile birlikte, yazılmış olan
11 | DateTimeException fırlatılacaktır
12 |
13 | - Zamana ilişkin sınırlar şu şekildedir:
14 | saat -> `[0, 23]`
15 | dakika -> `[0, 59]`
16 | saniye -> `[0, 59]`
17 | mili saniye -> `[0, 999]`
18 |
19 | - Sınıfa ilişkin test kodlarını da yazınız
20 | -----------------------------------------------------------------------------------------------------------------------*/
21 | /**
22 | * Time class that represents a time
23 | * Last Update: 20th May 2025
24 | * @author Java-Jan-2024 Group
25 | */
26 | package org.csystem.datetime;
27 |
28 | public class Time {
29 | public Time(int hour, int minute)
30 | {
31 | throw new UnsupportedOperationException("TODO:");
32 | }
33 |
34 | public Time(int hour, int minute, int second)
35 | {
36 | throw new UnsupportedOperationException("TODO:");
37 | }
38 |
39 | public Time(int hour, int minute, int second, int millisecond)
40 | {
41 | throw new UnsupportedOperationException("TODO:");
42 | }
43 |
44 | public int getHour()
45 | {
46 | throw new UnsupportedOperationException("TODO:");
47 | }
48 |
49 | public void setHour(int value)
50 | {
51 | throw new UnsupportedOperationException("TODO:");
52 | }
53 |
54 | public int getMinute()
55 | {
56 | throw new UnsupportedOperationException("TODO:");
57 | }
58 |
59 | public void setMinute(int value)
60 | {
61 | throw new UnsupportedOperationException("TODO:");
62 | }
63 |
64 | public int getSecond()
65 | {
66 | throw new UnsupportedOperationException("TODO:");
67 | }
68 |
69 | public void setSecond(int value)
70 | {
71 | throw new UnsupportedOperationException("TODO:");
72 | }
73 |
74 | public int getMillisecond()
75 | {
76 | throw new UnsupportedOperationException("TODO:");
77 | }
78 |
79 | public void setMillisecond(int value)
80 | {
81 | throw new UnsupportedOperationException("TODO:");
82 | }
83 |
84 | public String toString()
85 | {
86 | throw new UnsupportedOperationException("TODO -> 17:01:08");
87 | }
88 |
89 | public boolean equals(Object other)
90 | {
91 | throw new UnsupportedOperationException("TODO:");
92 | }
93 |
94 | public String toLongTimeString()
95 | {
96 | throw new UnsupportedOperationException("TODO -> 17:01:08.123");
97 | }
98 |
99 | public String toShortTimeString()
100 | {
101 | throw new UnsupportedOperationException("TODO -> 17:01");
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/game/card/Card.java:
--------------------------------------------------------------------------------
1 | package org.csystem.game.card;
2 |
3 | import java.util.random.RandomGenerator;
4 |
5 | public class Card {
6 | private static final int DEFAULT_SHUFFLE_COUNT = 100;
7 | private static final int CARD_COUNT_OF_DECK = 52;
8 | private CardType m_cardType;
9 | private CardValue m_cardValue;
10 |
11 | private static void swap(Card [] cards, int i, int k)
12 | {
13 | Card temp;
14 |
15 | temp = cards[i];
16 | cards[i] = cards[k];
17 | cards[k] = temp;
18 | }
19 |
20 | public static Card [] newDeck()
21 | {
22 | Card [] deck = new Card[CARD_COUNT_OF_DECK];
23 | int idx = 0;
24 |
25 | for (CardType cardType : CardType.values())
26 | for (CardValue cardValue : CardValue.values())
27 | deck[idx++] = new Card(cardType, cardValue);
28 |
29 | return deck;
30 | }
31 |
32 | public static Card [] newShuffledDeck(RandomGenerator randomGenerator)
33 | {
34 | return newShuffledDeck(randomGenerator, DEFAULT_SHUFFLE_COUNT);
35 | }
36 |
37 | public static Card [] newShuffledDeck(RandomGenerator randomGenerator, int count)
38 | {
39 | Card [] deck = newDeck();
40 |
41 | for (int i = 0; i < count; ++i)
42 | swap(deck, randomGenerator.nextInt(deck.length), randomGenerator.nextInt(deck.length));
43 |
44 | return deck;
45 | }
46 |
47 | public Card(CardType cardType, CardValue cardValue)
48 | {
49 | m_cardType = cardType;
50 | m_cardValue = cardValue;
51 | }
52 |
53 | public CardType getCardType()
54 | {
55 | return m_cardType;
56 | }
57 |
58 | public void setCardType(CardType cardType)
59 | {
60 | m_cardType = cardType;
61 | }
62 |
63 | public CardValue getCardValue()
64 | {
65 | return m_cardValue;
66 | }
67 |
68 | public void setCardValue(CardValue cardValue)
69 | {
70 | m_cardValue = cardValue;
71 | }
72 |
73 | public String toString()
74 | {
75 | return "%s-%s".formatted(m_cardType.toString(), m_cardValue.toString());
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.RandomGenerator;
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 RandomGenerator m_randomGenerator;
9 |
10 | public RandomCardGenerator(RandomGenerator randomGenerator)
11 | {
12 | m_randomGenerator = randomGenerator;
13 | }
14 |
15 | public Card create()
16 | {
17 | return new Card(CARD_TYPES[m_randomGenerator.nextInt(CARD_TYPES.length)], CARD_VALUES[m_randomGenerator.nextInt(CARD_VALUES.length)]);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/generator/object/ObjectArrayGenerator.java:
--------------------------------------------------------------------------------
1 | package org.csystem.generator.object;
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.util.string.StringUtil;
7 |
8 | import java.util.Random;
9 |
10 | public class ObjectArrayGenerator {
11 | private final Random m_random = new Random();
12 |
13 | //StringEN, Integer, Character, Boolean, Point, Circle, Complex
14 | private Object createObject()
15 | {
16 | return switch (m_random.nextInt(7)) {
17 | case 0 -> StringUtil.generateRandomTextEN(m_random, m_random.nextInt(5, 11));
18 | case 1 -> m_random.nextInt(-128, 128);
19 | case 2 -> (char)((m_random.nextBoolean() ? 'A' : 'a') + m_random.nextInt(26));
20 | case 3 -> m_random.nextBoolean();
21 | case 4 -> Point.createCartesian(m_random.nextDouble(-100, 100), m_random.nextDouble(-100, 100));
22 | case 5 -> new Circle(m_random.nextDouble(-10, 10));
23 | default -> new Complex(m_random.nextDouble(-20, 20), m_random.nextDouble(-20, 20));
24 | };
25 | }
26 |
27 | public Object [] createObjects(int count)
28 | {
29 | Object [] objects = new Object[count];
30 |
31 | for (int i = 0; i < count; ++i)
32 | objects[i] = createObject();
33 |
34 | return objects;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/generator/random/point/RandomPointGenerator.java:
--------------------------------------------------------------------------------
1 | package org.csystem.generator.random.point;
2 |
3 | import org.csystem.math.geometry.Point;
4 |
5 | import java.util.ArrayList;
6 | import java.util.random.RandomGenerator;
7 |
8 | public class RandomPointGenerator {
9 | private final RandomGenerator m_randomGenerator;
10 | private final double m_origin, m_bound;
11 |
12 | private Point createRandomPoint()
13 | {
14 | return Point.createCartesian(m_randomGenerator.nextDouble(m_origin, m_bound), m_randomGenerator.nextDouble(m_origin, m_bound));
15 | }
16 |
17 | public RandomPointGenerator(RandomGenerator randomCardGenerator, double origin, double bound)
18 | {
19 | m_randomGenerator = randomCardGenerator;
20 | m_origin = origin;
21 | m_bound = bound;
22 | }
23 |
24 |
25 | public void addPoints(ArrayList points, int count)
26 | {
27 | for (int i = 0; i < count; i++)
28 | points.add(createRandomPoint());
29 | }
30 |
31 | public Point[] createPointArray(int count)
32 | {
33 | Point [] points = new Point[count];
34 |
35 | for (int i = 0; i < count; i++)
36 | points[i] = createRandomPoint();
37 |
38 | return points;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/generator/random/string/RandomStringArrayGeneratorTR.java:
--------------------------------------------------------------------------------
1 | package org.csystem.generator.random.string;
2 |
3 | import org.csystem.util.string.StringUtil;
4 |
5 | import java.util.random.RandomGenerator;
6 |
7 | public class RandomStringArrayGeneratorTR {
8 | private final String [] m_texts;
9 |
10 | public RandomStringArrayGeneratorTR(RandomGenerator randomGenerator, int count, int origin, int bound)
11 | {
12 | m_texts = StringUtil.generateRandomTextsTR(randomGenerator, count, origin, bound);
13 | }
14 |
15 | public int size()
16 | {
17 | return m_texts.length;
18 | }
19 |
20 | public String get(int index)
21 | {
22 | return m_texts[index];
23 | }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/Complex.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Complex class that represents a complex number in math
3 | * Last Update: 6th March 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.math;
7 |
8 | import static java.lang.Math.sqrt;
9 |
10 | public class Complex {
11 | private static final double DELTA = 0.00001;
12 | private final double m_real;
13 | private final double m_imag;
14 |
15 | private static Complex add(double re1, double im1, double re2, double im2)
16 | {
17 | return new Complex(re1 + re2, im1 + im2);
18 | }
19 |
20 | private static Complex subtract(double re1, double im1, double re2, double im2)
21 | {
22 | return add(re1, im1, -re2, -im2);
23 | }
24 |
25 | public Complex()
26 | {
27 | m_real = m_imag = 0;
28 | }
29 |
30 | public Complex(double real)
31 | {
32 | m_real = real;
33 | m_imag = 0;
34 | }
35 |
36 | public Complex(double real, double imag)
37 | {
38 | m_real = real;
39 | m_imag = imag;
40 | }
41 |
42 | public static Complex add(double val, Complex z)
43 | {
44 | return add(val, 0, z.m_real, z.m_imag);
45 | }
46 |
47 | public Complex add(Complex other)
48 | {
49 | return add(m_real, m_imag, other.m_real, other.m_imag);
50 | }
51 |
52 | public Complex add(double val)
53 | {
54 | return add(m_real, m_imag, val, 0);
55 | }
56 |
57 | public static Complex subtract(double val, Complex z)
58 | {
59 | return subtract(val, 0, z.m_real, z.m_imag);
60 | }
61 |
62 | public Complex subtract(Complex other)
63 | {
64 | return subtract(m_real, m_imag, other.m_real, other.m_imag);
65 | }
66 |
67 | public Complex subtract(double val)
68 | {
69 | return subtract(m_real, m_imag, val, 0);
70 | }
71 |
72 | public Complex getConjugate()
73 | {
74 | return new Complex(m_real, -m_imag);
75 | }
76 |
77 | public double getNorm()
78 | {
79 | return sqrt(m_real * m_real + m_imag * m_imag);
80 | }
81 |
82 | public double getLength()
83 | {
84 | return getNorm();
85 | }
86 |
87 | public boolean equals(Object other)
88 | {
89 | return other instanceof Complex z && Math.abs(m_real - z.m_real) < DELTA && Math.abs(m_imag - z.m_imag) < DELTA;
90 | }
91 |
92 | public String toString()
93 | {
94 | return "(%.2f, %.2f)".formatted(m_real, m_imag);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/Fraction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Fraction class that represents fraction
3 | * Last Update: 24th April 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 |
7 | package org.csystem.math;
8 |
9 | public class Fraction {
10 | private int m_a;
11 | private int m_b;
12 |
13 | private static Fraction add(int a1, int b1, int a2, int b2)
14 | {
15 | return new Fraction(a1 * b2 + a2 * b1, b1 * b2);
16 | }
17 |
18 | private static Fraction subtract(int a1, int b1, int a2, int b2)
19 | {
20 | return add(a1, b1, -a2, b2);
21 | }
22 |
23 | private static Fraction multiply(int a1, int b1, int a2, int b2)
24 | {
25 | return new Fraction(a1 * a2, b1 * b2);
26 | }
27 |
28 | private static Fraction divide(int a1, int b1, int a2, int b2)
29 | {
30 | return multiply(a1, b1, b2, a2);
31 | }
32 |
33 | private static void check(int a, int b)
34 | {
35 | if (b == 0)
36 | throw new IllegalArgumentException(a == 0 ? "Indeterminate" : "Undefined");
37 | }
38 |
39 | private void setSign()
40 | {
41 | if (m_b < 0) {
42 | m_a = -m_a;
43 | m_b = -m_b;
44 | }
45 | }
46 |
47 | private void simplify()
48 | {
49 | int min = Math.min(Math.abs(m_a), m_b);
50 |
51 | for (int i = min; i >= 2; --i)
52 | if (m_a % i == 0 && m_b % i == 0) {
53 | m_a /= i;
54 | m_b /= i;
55 | break;
56 | }
57 | }
58 |
59 | private void setFields(int a, int b)
60 | {
61 | m_a = a;
62 | m_b = b;
63 | }
64 |
65 | private void set(int a, int b)
66 | {
67 | if (a == 0) {
68 | setFields(0, 1);
69 | return;
70 | }
71 |
72 | setFields(a, b);
73 | setSign();
74 | simplify();
75 | }
76 |
77 | public Fraction()
78 | {
79 | this(0);
80 | }
81 |
82 | public Fraction(int a)
83 | {
84 | m_a = a;
85 | m_b = 1;
86 | }
87 |
88 | public Fraction(int a, int b)
89 | {
90 | check(a, b);
91 | set(a, b);
92 | }
93 |
94 | public int getNumerator()
95 | {
96 | return m_a;
97 | }
98 |
99 | public void setNumerator(int val)
100 | {
101 | set(val, m_b);
102 | }
103 |
104 | public int getDenominator()
105 | {
106 | return m_b;
107 | }
108 |
109 | public void setDenominator(int val)
110 | {
111 | check(m_a, val);
112 | set(m_a, val);
113 | }
114 |
115 | public double getRealValue()
116 | {
117 | return (double) m_a / m_b;
118 | }
119 |
120 | public Fraction add(Fraction other)
121 | {
122 | return add(m_a, m_b, other.m_a, other.m_b);
123 | }
124 |
125 | public Fraction add(int val)
126 | {
127 | return add(m_a, m_b, val, 1);
128 | }
129 |
130 | public Fraction subtract(Fraction other)
131 | {
132 | return subtract(m_a, m_b, other.m_a, other.m_b);
133 | }
134 |
135 | public Fraction subtract(int val)
136 | {
137 | return subtract(m_a, m_b, val, 1);
138 | }
139 |
140 | public Fraction multiply(Fraction other)
141 | {
142 | return multiply(m_a, m_b, other.m_a, other.m_b);
143 | }
144 |
145 | public Fraction multiply(int val)
146 | {
147 | return multiply(m_a, m_b, val, 1);
148 | }
149 |
150 | public Fraction divide(Fraction other)
151 | {
152 | return divide(m_a, m_b, other.m_a, other.m_b);
153 | }
154 |
155 | public Fraction divide(int val)
156 | {
157 | return divide(m_a, m_b, val, 1);
158 | }
159 |
160 | public void inc()
161 | {
162 | m_a += m_b;
163 | }
164 |
165 | public void dec()
166 | {
167 | m_a -= m_b;
168 | }
169 |
170 | public int compareTo(Fraction other)
171 | {
172 | return m_a * other.m_b - other.m_a * m_b;
173 | }
174 |
175 | public boolean equals(Object other)
176 | {
177 | return other instanceof Fraction f && compareTo(f) == 0;
178 | }
179 |
180 | public String toString()
181 | {
182 | return "%d%s".formatted(m_a, m_b != 1 ? " / %d = %.6f".formatted(m_b, getRealValue()) : "");
183 | }
184 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/MutableComplex.java:
--------------------------------------------------------------------------------
1 | /**
2 | * MutableComplex class that represents a complex number in math
3 | * Last Update: 31st October 2024
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.math;
7 |
8 | import static java.lang.Math.sqrt;
9 |
10 | public class MutableComplex {
11 | private static final double DELTA = 0.00001;
12 | private double m_real;
13 | private double m_imag;
14 |
15 | private static MutableComplex add(double re1, double im1, double re2, double im2)
16 | {
17 | return new MutableComplex(re1 + re2, im1 + im2);
18 | }
19 |
20 | private static MutableComplex subtract(double re1, double im1, double re2, double im2)
21 | {
22 | return add(re1, im1, -re2, -im2);
23 | }
24 |
25 | public MutableComplex()
26 | {
27 | }
28 |
29 | public MutableComplex(double real)
30 | {
31 | m_real = real;
32 | }
33 |
34 | public MutableComplex(double real, double imag)
35 | {
36 | m_real = real;
37 | m_imag = imag;
38 | }
39 |
40 | public static MutableComplex add(double val, MutableComplex z)
41 | {
42 | return add(val, 0, z.m_real, z.m_imag);
43 | }
44 |
45 | public MutableComplex add(MutableComplex other)
46 | {
47 | return add(m_real, m_imag, other.m_real, other.m_imag);
48 | }
49 |
50 | public MutableComplex add(double val)
51 | {
52 | return add(m_real, m_imag, val, 0);
53 | }
54 |
55 | public static MutableComplex subtract(double val, MutableComplex z)
56 | {
57 | return subtract(val, 0, z.m_real, z.m_imag);
58 | }
59 |
60 | public MutableComplex subtract(MutableComplex other)
61 | {
62 | return subtract(m_real, m_imag, other.m_real, other.m_imag);
63 | }
64 |
65 | public MutableComplex subtract(double val)
66 | {
67 | return subtract(m_real, m_imag, val, 0);
68 | }
69 |
70 | public void inc(double val)
71 | {
72 | m_real += val;
73 | }
74 |
75 | public void inc()
76 | {
77 | inc(1);
78 | }
79 |
80 | public void dec(double val)
81 | {
82 | inc(-val);
83 | }
84 |
85 | public void dec()
86 | {
87 | dec(1);
88 | }
89 |
90 | public MutableComplex getConjugate()
91 | {
92 | return new MutableComplex(m_real, -m_imag);
93 | }
94 |
95 | public double getNorm()
96 | {
97 | return sqrt(m_real * m_real + m_imag * m_imag);
98 | }
99 |
100 | public double getLength()
101 | {
102 | return getNorm();
103 | }
104 |
105 | public boolean equals(Object other)
106 | {
107 | return other instanceof MutableComplex z && Math.abs(m_real - z.m_real) < DELTA && Math.abs(m_imag - z.m_imag) < DELTA;
108 | }
109 |
110 | public String toString()
111 | {
112 | return "(%.2f, %.2f)".formatted(m_real, m_imag);
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/AnalyticalCircle.java:
--------------------------------------------------------------------------------
1 | /**
2 | * AnalyticalCircle class that represents a circle in Cartesian System
3 | * Last Update: 6th March 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.math.geometry;
7 |
8 | public class AnalyticalCircle extends Circle {
9 | private static final double DELTA = 0.0000001;
10 | private final MutablePoint m_center;
11 |
12 | public AnalyticalCircle()
13 | {
14 | this(0, 0);
15 | }
16 |
17 | public AnalyticalCircle(double radius)
18 | {
19 | this(radius, 0, 0);
20 | }
21 |
22 | public AnalyticalCircle(double x, double y)
23 | {
24 | this(0, x, y);
25 | }
26 |
27 | public AnalyticalCircle(double radius, double x, double y)
28 | {
29 | super(radius);
30 | m_center = MutablePoint.createCartesian(x, y);
31 | }
32 |
33 | public double getX()
34 | {
35 | return m_center.getX();
36 | }
37 |
38 | public void setX(double x)
39 | {
40 | m_center.setX(x);
41 | }
42 |
43 | public double getY()
44 | {
45 | return m_center.getY();
46 | }
47 |
48 | public void setY(double y)
49 | {
50 | m_center.setY(y);
51 | }
52 |
53 | public void setCenter(double x, double y)
54 | {
55 | setX(x);
56 | setY(y);
57 | }
58 |
59 | public void offset(double dx, double dy)
60 | {
61 | m_center.offset(dx, dy);
62 | }
63 |
64 | public void offset(double dxy)
65 | {
66 | offset(dxy, dxy);
67 | }
68 |
69 | public boolean isTangent(AnalyticalCircle other)
70 | {
71 | return Math.abs(centersDistance(other) - getRadius() - other.getRadius()) < DELTA;
72 | }
73 |
74 | public double centersDistance(AnalyticalCircle other)
75 | {
76 | return m_center.euclideanDistance(other.m_center);
77 | }
78 |
79 | public boolean equals(Object other)
80 | {
81 | return other instanceof AnalyticalCircle ac && super.equals(other) && m_center.equals(ac.m_center);
82 | }
83 |
84 | public String toString()
85 | {
86 | return "%s, Center:%s".formatted(super.toString(), m_center);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/Circle.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Circle class that represents a circle in geometry
3 | * Last Update: 22nd April 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.math.geometry;
7 |
8 | import static java.lang.Math.PI;
9 |
10 | public class Circle {
11 | protected static final double DELTA = 0.000001;
12 | private double m_r;
13 |
14 | public Circle()
15 | {
16 | }
17 |
18 | public Circle(double radius)
19 | {
20 | setRadius(radius);
21 | }
22 |
23 | public void setRadius(double radius)
24 | {
25 | if (radius < 0)
26 | throw new IllegalArgumentException("Radius can not be negative:%f".formatted(radius));
27 |
28 | m_r = radius;
29 | }
30 |
31 | public double getRadius()
32 | {
33 | return m_r;
34 | }
35 |
36 | public double getArea()
37 | {
38 | return PI * m_r * m_r;
39 | }
40 |
41 | public double getCircumference()
42 | {
43 | return 2 * PI * m_r;
44 | }
45 |
46 | public boolean equals(Object other)
47 | {
48 | return other instanceof Circle c &&Math.abs(m_r - c.m_r) < DELTA;
49 | }
50 |
51 | public String toString()
52 | {
53 | return "Radius = %f, Area = %f, Circumference = %f".formatted(m_r, getArea(), getCircumference());
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/MutablePoint.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mutable Point class that represents a point in geometry
3 | * Last Update: 6th March 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.math.geometry;
7 |
8 | import static java.lang.Math.*;
9 |
10 | public class MutablePoint {
11 | private double m_x;
12 | private double m_y;
13 |
14 | private static MutablePoint create(double a, double b)
15 | {
16 | return new MutablePoint(a, b);
17 | }
18 |
19 | private MutablePoint(double x, double y)
20 | {
21 | m_x = x;
22 | m_y = y;
23 | }
24 |
25 | public static MutablePoint createCartesian(double x, double y)
26 | {
27 | return create(x, y);
28 | }
29 |
30 | public static MutablePoint createPolar(double r, double theta)
31 | {
32 | return create(r * cos(theta), r * sin(theta));
33 | }
34 |
35 | public double getX()
36 | {
37 | return m_x;
38 | }
39 |
40 | public void setX(double x)
41 | {
42 | m_x = x;
43 | }
44 |
45 | public double getY()
46 | {
47 | return m_y;
48 | }
49 |
50 | public void setY(double y)
51 | {
52 | m_y = y;
53 | }
54 |
55 | public double euclideanDistance()
56 | {
57 | return euclideanDistance(0, 0);
58 | }
59 |
60 | public double euclideanDistance(MutablePoint other)
61 | {
62 | return euclideanDistance(other.m_x, other.m_y);
63 | }
64 |
65 | public double euclideanDistance(double x, double y)
66 | {
67 | return PointCommon.euclideanDistance(m_x, m_y, x, y);
68 | }
69 |
70 | public void offset(double dxy)
71 | {
72 | offset(dxy, dxy);
73 | }
74 |
75 | public void offset(double dx, double dy)
76 | {
77 | m_x += dx;
78 | m_y += dy;
79 | }
80 |
81 | public boolean equals(Object other)
82 | {
83 | return other instanceof MutablePoint p && PointCommon.equals(m_x, m_y, p.m_x, p.m_y);
84 | }
85 |
86 | public String toString()
87 | {
88 | return PointCommon.toString(m_x, m_y);
89 | }
90 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/Point.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Immutable Point class that represents a point in geometry
3 | * Last Update: 6th March 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.math.geometry;
7 |
8 | import static java.lang.Math.*;
9 |
10 | public class Point {
11 | private final double m_x;
12 | private final double m_y;
13 |
14 | private static Point create(double a, double b)
15 | {
16 | return new Point(a, b);
17 | }
18 |
19 | private Point(double x, double y)
20 | {
21 | m_x = x;
22 | m_y = y;
23 | }
24 |
25 | public static Point createCartesian(double x, double y)
26 | {
27 | return create(x, y);
28 | }
29 |
30 | public static Point createPolar(double r, double theta)
31 | {
32 | return create(r * cos(theta), r * sin(theta));
33 | }
34 |
35 | public double getX()
36 | {
37 | return m_x;
38 | }
39 |
40 | public double getY()
41 | {
42 | return m_y;
43 | }
44 |
45 | public double euclideanDistance()
46 | {
47 | return euclideanDistance(0, 0);
48 | }
49 |
50 | public double euclideanDistance(Point other)
51 | {
52 | return euclideanDistance(other.m_x, other.m_y);
53 | }
54 |
55 | public double euclideanDistance(double x, double y)
56 | {
57 | return PointCommon.euclideanDistance(m_x, m_y, x, y);
58 | }
59 |
60 | public boolean equals(Object other)
61 | {
62 | return other instanceof Point p && PointCommon.equals(m_x, m_y, p.m_x, p.m_y);
63 | }
64 |
65 | public String toString()
66 | {
67 | return PointCommon.toString(m_x, m_y);
68 | }
69 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/PointCommon.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility friendly class for common point operations
3 | * Last Update: 6th March 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.math.geometry;
7 |
8 | import static java.lang.Math.pow;
9 | import static java.lang.Math.sqrt;
10 |
11 | class PointCommon {
12 | static final double DELTA = 0.000001;
13 | static String toString(double x, double y)
14 | {
15 | return "(%f, %f)".formatted(x, y);
16 | }
17 |
18 | static boolean equals(double x1, double y1, double x2, double y2)
19 | {
20 | return Math.abs(x1 - x2) < DELTA && Math.abs(y1 - y2) < DELTA;
21 | }
22 |
23 | static double euclideanDistance(double x1, double y1, double x2, double y2)
24 | {
25 | return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleDefaultCtorTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.geometry.AnalyticalCircle;
4 |
5 | import java.util.Random;
6 | import java.util.Scanner;
7 |
8 | public class AnalyticalCircleDefaultCtorTest {
9 | private static void run()
10 | {
11 | AnalyticalCircle ac = new AnalyticalCircle();
12 |
13 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
14 | }
15 |
16 | public static void main(String[] args)
17 | {
18 | run();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleOffsetTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.geometry.AnalyticalCircle;
4 |
5 | import java.util.Random;
6 | import java.util.Scanner;
7 |
8 | public class AnalyticalCircleOffsetTest {
9 | private 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 | while (count-- > 0) {
18 | System.out.println("----------------------------------------");
19 | double r = random.nextDouble(-10, 11);
20 | double y = random.nextDouble(-100, 101);
21 | double x = random.nextDouble(-100, 101);
22 | AnalyticalCircle ac = new AnalyticalCircle(r, x, y);
23 |
24 | System.out.printf("Generated Values -> r = %f, x = %f, y = %f%n", r, x, y);
25 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
26 | double dx = random.nextDouble(-100, 101);
27 | double dy = random.nextDouble(-100, 101);
28 |
29 | ac.offset(dx, dy);
30 | System.out.printf("Generated Values -> dx = %f, dy = %f%n", dx, dy);
31 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
32 | System.out.println("----------------------------------------");
33 | }
34 | }
35 |
36 | public static void main(String[] args)
37 | {
38 | run();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.geometry.AnalyticalCircle;
4 | import org.csystem.math.geometry.Circle;
5 |
6 | import java.util.Random;
7 | import java.util.Scanner;
8 |
9 | public class AnalyticalCircleTest {
10 | private static void run()
11 | {
12 | Scanner kb = new Scanner(System.in);
13 | Random random = new Random();
14 |
15 | System.out.print("Input count:");
16 | int count = kb.nextInt();
17 |
18 | while (count-- > 0) {
19 | System.out.println("----------------------------------------");
20 | double r = random.nextDouble(-10, 11);
21 | double y = random.nextDouble(-100, 101);
22 | double x = random.nextDouble(-100, 101);
23 | AnalyticalCircle ac = new AnalyticalCircle(r, x, y);
24 |
25 | System.out.printf("Generated Values -> r = %f, x = %f, y = %f%n", r, x, y);
26 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
27 | y = random.nextDouble(-100, 101);
28 | x = random.nextDouble(-100, 101);
29 | ac.setX(x);
30 | ac.setY(y);
31 | System.out.printf("Generated Values -> x = %f, y = %f%n", x, y);
32 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
33 | System.out.println("----------------------------------------");
34 | }
35 | }
36 |
37 | public static void main(String[] args)
38 | {
39 | run();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleZeroCenterCtorTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.geometry.AnalyticalCircle;
4 |
5 | import java.util.Random;
6 | import java.util.Scanner;
7 |
8 | public class AnalyticalCircleZeroCenterCtorTest {
9 | private 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 | while (count-- > 0) {
18 | System.out.println("----------------------------------------");
19 | double r = random.nextDouble(-10, 11);
20 |
21 | AnalyticalCircle ac = new AnalyticalCircle(r);
22 |
23 | System.out.printf("Generated Values -> r = %f%n", r);
24 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
25 | System.out.println("----------------------------------------");
26 | }
27 | }
28 |
29 | public static void main(String[] args)
30 | {
31 | run();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/AnalyticalCircleZeroRadiusCtorTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.geometry.AnalyticalCircle;
4 |
5 | import java.util.Random;
6 | import java.util.Scanner;
7 |
8 | public class AnalyticalCircleZeroRadiusCtorTest {
9 | private 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 | while (count-- > 0) {
18 | System.out.println("----------------------------------------");
19 | double y = random.nextDouble(-100, 101);
20 | double x = random.nextDouble(-100, 101);
21 | AnalyticalCircle ac = new AnalyticalCircle(x, y);
22 |
23 | System.out.printf("Generated Values -> x = %f, y = %f%n", x, y);
24 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
25 | y = random.nextDouble(-100, 101);
26 | x = random.nextDouble(-100, 101);
27 | ac.setX(x);
28 | ac.setY(y);
29 | System.out.printf("Generated Values -> x = %f, y = %f%n", x, y);
30 | System.out.printf("Radius:%f, Area:%f, Circumference:%f, Center:(%f, %f)%n", ac.getRadius(), ac.getArea(), ac.getCircumference(), ac.getX(), ac.getY());
31 | System.out.println("----------------------------------------");
32 | }
33 | }
34 |
35 | public static void main(String[] args)
36 | {
37 | run();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/CircleTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.geometry.Circle;
4 |
5 | import java.util.Random;
6 | import java.util.Scanner;
7 |
8 | public class CircleTest {
9 | private 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 | while (count-- > 0) {
18 | System.out.println("----------------------------------------");
19 | double r = random.nextDouble(-10, 11);
20 | Circle c = new Circle(r);
21 |
22 | System.out.printf("Generated Value:%f%n", r);
23 | System.out.printf("Radius:%f, Area:%f, Circumference:%f%n", c.getRadius(), c.getArea(), c.getCircumference());
24 | r = random.nextDouble(-10, 11);
25 | c.setRadius(r);
26 | System.out.printf("Generated Value:%f%n", r);
27 | System.out.printf("Radius:%f, Area:%f, Circumference:%f%n", c.getRadius(), c.getArea(), c.getCircumference());
28 | System.out.println("----------------------------------------");
29 | }
30 | }
31 |
32 | public static void main(String[] args)
33 | {
34 | run();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/FractionArithmeticOperationsTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.Fraction;
4 | import org.csystem.util.console.Console;
5 |
6 | /**
7 | * Fraction test class
8 | * Last Update: 24th April 2025
9 | * @author Onur Meşe
10 | */
11 | public class FractionArithmeticOperationsTest {
12 | public static void run()
13 | {
14 | try {
15 | Fraction f1 = new Fraction(1,2);
16 | Fraction f2 = new Fraction(1, -4);
17 |
18 | Console.writeLine(f1.add(f2).equals(new Fraction(1, 4)));
19 | Console.writeLine(f1.subtract(f2).equals(new Fraction(3, 4)));
20 | Console.writeLine(f1.multiply(f2).equals(new Fraction(1, -8)));
21 | Console.writeLine(f1.divide(f2).equals(new Fraction(-2)));
22 | Console.writeLine(f1.divide(new Fraction()));
23 | }
24 | catch (IllegalArgumentException ex) {
25 | Console.writeLine("Exception Message:%s", ex.getMessage());
26 | }
27 | }
28 | public static void main(String[] args)
29 | {
30 | run();
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/FractionComparisonTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.Fraction;
4 | import org.csystem.util.console.Console;
5 |
6 | /**
7 | * Fraction test class
8 | * Last Update: 24th April 2025
9 | * @author Onur Meşe
10 | */
11 |
12 | public class FractionComparisonTest {
13 | public static void run()
14 | {
15 | Fraction f1 = new Fraction(1,2);
16 | Fraction f2 = new Fraction(-10, 20);
17 | Fraction f3 = new Fraction(1, -4);
18 | Fraction f4 = new Fraction(3, 4);
19 | Fraction f5 = new Fraction();
20 | Fraction f6 = new Fraction(2, 4);
21 | Fraction f7 = new Fraction(-120, -160);
22 |
23 | Console.writeLine(f1.compareTo(f3) > 0);
24 | Console.writeLine(f2.compareTo(f1) < 0);
25 | Console.writeLine(f4.compareTo(f7) == 0);
26 | Console.writeLine(f5.compareTo(f6) < 0);
27 | Console.writeLine(f6.compareTo(f3) > 0);
28 | }
29 | public static void main(String[] args)
30 | {
31 | run();
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/FractionCtorsTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.Fraction;
4 | import org.csystem.util.console.Console;
5 |
6 | import java.util.Random;
7 |
8 | public class FractionCtorsTest {
9 | public static void run()
10 | {
11 | try {
12 | Random r = new Random();
13 | Fraction f1 = new Fraction();
14 | Fraction f2 = new Fraction(3);
15 | Fraction f3 = new Fraction(3, 4);
16 | Fraction f4 = new Fraction(3, -4);
17 | Fraction f5 = new Fraction(-3, -4);
18 | Fraction f6 = new Fraction(120, 160);
19 | Fraction f7 = new Fraction(120, -160);
20 | Fraction f8 = new Fraction(-120, -160);
21 |
22 | Console.writeLine("f1 -> %s", f1);
23 | Console.writeLine("f2 -> %s", f2);
24 | Console.writeLine("f3 -> %s", f3);
25 | Console.writeLine("f4 -> %s", f4);
26 | Console.writeLine("f5 -> %s", f5);
27 | Console.writeLine("f6 -> %s", f6);
28 | Console.writeLine("f7 -> %s", f7);
29 | Console.writeLine("f8 -> %s", f8);
30 |
31 | int a = r.nextInt(3);
32 |
33 | Console.writeLine("a = %d", a);
34 | Fraction f9 = new Fraction(a, 0);
35 | }
36 | catch (IllegalArgumentException ex) {
37 | Console.writeLine(ex.getMessage());
38 | }
39 | }
40 |
41 | public static void main(String[] args)
42 | {
43 | run();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/FractionEqualityTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.Fraction;
4 | import org.csystem.util.console.Console;
5 |
6 |
7 | /**
8 | * Fraction test class
9 | * Last Update: 24th April 2025
10 | * @author Onur Meşe
11 | */
12 | public class FractionEqualityTest {
13 | public static void run(){
14 |
15 | Fraction f1 = new Fraction(1, 2);
16 | Fraction f2 = new Fraction(-10, 20);
17 | Fraction f3 = new Fraction(1, -4);
18 | Fraction f4 = new Fraction(3, 4);
19 | Fraction f5 = new Fraction(0, 10);
20 | Fraction f6 = new Fraction();
21 | Fraction f7 = new Fraction(2, 4);
22 | Fraction f8 = new Fraction(-120, -160);
23 |
24 | Console.writeLine(f1.equals(f3));
25 | Console.writeLine(f2.equals(f1));
26 | Console.writeLine(f4.equals(f8));
27 | Console.writeLine(f6.equals(f5));
28 | Console.writeLine(f7.equals(f3));
29 |
30 | }
31 | public static void main(String[] args)
32 | {
33 | run();
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/math/geometry/test/FractionSettersTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.math.geometry.test;
2 |
3 | import org.csystem.math.Fraction;
4 | import org.csystem.util.console.Console;
5 |
6 | import java.util.Random;
7 |
8 | public class FractionSettersTest {
9 | public static void run()
10 | {
11 | try {
12 | Random r = new Random();
13 | Fraction f1 = new Fraction(12, 16);
14 |
15 | Console.writeLine("f1 -> %s", f1);
16 |
17 | f1.setNumerator(0);
18 |
19 | Console.writeLine("f1 -> %s", f1);
20 |
21 | f1.setNumerator(6);
22 | Console.writeLine("f1 -> %s", f1);
23 | f1.setDenominator(36);
24 | Console.writeLine("f1 -> %s", f1);
25 |
26 | int a = r.nextInt(3);
27 |
28 | Console.writeLine("a = %d", a);
29 | f1.setNumerator(a);
30 | f1.setDenominator(0);
31 | }
32 | catch (IllegalArgumentException ex) {
33 | Console.writeLine(ex.getMessage());
34 | }
35 | }
36 |
37 | public static void main(String[] args)
38 | {
39 | run();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/string/CSDStringBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mutable class for some string operations
3 | * Last Update: 15th May 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.string;
7 |
8 | import java.util.Arrays;
9 |
10 | public class CSDStringBuilder implements CharSequence {
11 | private static final int DEFAULT_CAPACITY_IF_CURRENT_ZERO = 1;
12 | private static final int CAPACITY_INCREMENT_FACTOR = 2;
13 | private static final int DEFAULT_CAPACITY = 16;
14 | private char [] m_chars;
15 | private int m_index;
16 |
17 | private boolean checkCapacity(String str)
18 | {
19 | return m_index + str.length() <= m_chars.length;
20 | }
21 |
22 | private int calculateNewCapacity(char [] str)
23 | {
24 | int result = m_chars.length == 0 ? DEFAULT_CAPACITY_IF_CURRENT_ZERO : m_chars.length;
25 |
26 | while ((result = result * CAPACITY_INCREMENT_FACTOR) < m_index + str.length)
27 | ;
28 |
29 | return result;
30 | }
31 |
32 | private void enlargeCapacity(int newCapacity)
33 | {
34 | m_chars = Arrays.copyOf(m_chars, newCapacity);
35 | }
36 |
37 | public CSDStringBuilder()
38 | {
39 | this(DEFAULT_CAPACITY);
40 | }
41 |
42 | public CSDStringBuilder(int capacity)
43 | {
44 | m_chars = new char[capacity];
45 | }
46 |
47 | public CSDStringBuilder(String str)
48 | {
49 | m_chars = str.toCharArray();
50 | m_index += str.length();
51 | }
52 |
53 | public CSDStringBuilder append(String str)
54 | {
55 | return append(str.toCharArray());
56 | }
57 |
58 | public CSDStringBuilder append(char ch)
59 | {
60 | return append(String.valueOf(ch));
61 | }
62 |
63 | public CSDStringBuilder append(int a)
64 | {
65 | return append(String.valueOf(a));
66 | }
67 |
68 | public CSDStringBuilder append(long a)
69 | {
70 | return append(String.valueOf(a));
71 | }
72 |
73 | public CSDStringBuilder append(double a)
74 | {
75 | return append(String.valueOf(a));
76 | }
77 |
78 | public CSDStringBuilder append(char [] str)
79 | {
80 | if (!checkCapacity(String.valueOf(str)))
81 | enlargeCapacity(calculateNewCapacity(str));
82 |
83 | System.arraycopy(str, 0, m_chars, m_index, str.length);
84 | m_index += str.length;
85 |
86 | return this;
87 | }
88 |
89 | public int capacity()
90 | {
91 | return m_chars.length;
92 | }
93 |
94 | public char charAt(int index)
95 | {
96 | return m_chars[index];
97 | }
98 |
99 | public CSDStringBuilder deleteCharAt(int index)
100 | {
101 | throw new UnsupportedOperationException("TODO");
102 | }
103 |
104 | public CSDStringBuilder delete(int start, int end)
105 | {
106 | throw new UnsupportedOperationException("TODO");
107 | }
108 |
109 | public void ensureCapacity(int minCapacity)
110 | {
111 | if (minCapacity > m_chars.length)
112 | enlargeCapacity(Math.max(minCapacity, m_chars.length * CAPACITY_INCREMENT_FACTOR));
113 | }
114 |
115 | public int indexOf(String str)
116 | {
117 | throw new UnsupportedOperationException("TODO");
118 | }
119 |
120 | public int indexOf(String str, int startIndex)
121 | {
122 | throw new UnsupportedOperationException("TODO");
123 | }
124 |
125 | public CSDStringBuilder insert(int index, String str)
126 | {
127 | throw new UnsupportedOperationException("TODO:");
128 | }
129 |
130 | public CSDStringBuilder insert(int index, char ch)
131 | {
132 | throw new UnsupportedOperationException("TODO");
133 | }
134 |
135 | public CSDStringBuilder insert(int index, int a)
136 | {
137 | throw new UnsupportedOperationException("TODO");
138 | }
139 |
140 | public CSDStringBuilder insert(int index, long a)
141 | {
142 | throw new UnsupportedOperationException("TODO");
143 | }
144 |
145 | public CSDStringBuilder insert(int index, double a)
146 | {
147 | throw new UnsupportedOperationException("TODO");
148 | }
149 |
150 | public CSDStringBuilder insert(int index, char [] str)
151 | {
152 | throw new UnsupportedOperationException("TODO");
153 | }
154 |
155 | //...
156 |
157 | public CharSequence subSequence(int start, int end)
158 | {
159 | return String.valueOf(m_chars, start, end - start); //ankara
160 | }
161 |
162 | public int length()
163 | {
164 | return m_index;
165 | }
166 |
167 | public void trimToSize()
168 | {
169 | enlargeCapacity(m_index);
170 | }
171 |
172 | public boolean equals(Object other)
173 | {
174 | throw new UnsupportedOperationException("TODO");
175 | }
176 |
177 | public String toString()
178 | {
179 | return String.valueOf(m_chars, 0, m_index);
180 | }
181 |
182 | //...
183 | }
184 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/string/test/CSDStringBuilderCapacityIncrementTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.string.test;
2 |
3 | import org.csystem.string.CSDStringBuilder;
4 | import org.csystem.util.console.Console;
5 |
6 | public class CSDStringBuilderCapacityIncrementTest {
7 | public static void run()
8 | {
9 | String str = "Bugün hava çok karlı değil mi?";
10 | CSDStringBuilder sb = new CSDStringBuilder(5);
11 |
12 | sb.append("ali");
13 |
14 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
15 | sb.append(str);
16 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
17 | }
18 |
19 | public static void main(String[] args)
20 | {
21 | run();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/string/test/CSDStringBuilderInitialCapacityZeroTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.string.test;
2 |
3 | import org.csystem.string.CSDStringBuilder;
4 | import org.csystem.util.console.Console;
5 |
6 | public class CSDStringBuilderInitialCapacityZeroTest {
7 | public static void run()
8 | {
9 | CSDStringBuilder sb = new CSDStringBuilder(0);
10 |
11 | sb.append("ali");
12 |
13 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
14 | }
15 |
16 | public static void main(String[] args)
17 | {
18 | run();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/string/test/CSDStringBuilderInitialEnsureCapacityTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.string.test;
2 |
3 | import org.csystem.string.CSDStringBuilder;
4 | import org.csystem.util.console.Console;
5 |
6 | public class CSDStringBuilderInitialEnsureCapacityTest {
7 | public static void run()
8 | {
9 | CSDStringBuilder sb = new CSDStringBuilder(5);
10 |
11 | sb.append("ali");
12 | sb.ensureCapacity(4);
13 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
14 | sb.ensureCapacity(7);
15 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
16 | sb.ensureCapacity(21);
17 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
18 | }
19 |
20 | public static void main(String[] args)
21 | {
22 | run();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/string/test/CSDStringBuilderInitialToStringTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.string.test;
2 |
3 | import org.csystem.string.CSDStringBuilder;
4 | import org.csystem.util.console.Console;
5 |
6 | public class CSDStringBuilderInitialToStringTest {
7 | public static void run()
8 | {
9 | String str = "bugün hava çok karlı değil mi?";
10 | CSDStringBuilder sb = new CSDStringBuilder(5);
11 |
12 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
13 | Console.writeLine("(%s)", sb.toString());
14 | sb.append("ali");
15 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
16 | Console.writeLine("(%s)", sb.toString());
17 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
18 | sb.append(' ').append(str);
19 |
20 | Console.writeLine("(%s)", sb.toString());
21 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
22 | }
23 |
24 | public static void main(String[] args)
25 | {
26 | run();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/string/test/CSDStringBuilderStringParameterCtorTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.string.test;
2 |
3 | import org.csystem.string.CSDStringBuilder;
4 | import org.csystem.util.console.Console;
5 |
6 | public class CSDStringBuilderStringParameterCtorTest {
7 | public static void run()
8 | {
9 | CSDStringBuilder sb = new CSDStringBuilder("ali");
10 |
11 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
12 | }
13 |
14 | public static void main(String[] args)
15 | {
16 | run();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/string/test/CSDStringBuilderTrimToSizeTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.string.test;
2 |
3 | import org.csystem.string.CSDStringBuilder;
4 | import org.csystem.util.console.Console;
5 |
6 | public class CSDStringBuilderTrimToSizeTest {
7 | public static void run()
8 | {
9 | CSDStringBuilder sb = new CSDStringBuilder(5);
10 |
11 | sb.append("ali");
12 |
13 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
14 | sb.trimToSize();
15 | Console.writeLine("Capacity:%d, Length:%d", sb.capacity(), sb.length());
16 | }
17 |
18 | public static void main(String[] args)
19 | {
20 | run();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/ArrayUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for array operations
3 | * Last Update: 15th May 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.array;
7 |
8 |
9 | import java.util.random.RandomGenerator;
10 |
11 | public final class ArrayUtil {
12 | private ArrayUtil()
13 | {
14 | }
15 |
16 | private static void bubbleSortAscending(int [] a)
17 | {
18 | for (int i = 0; i < a.length - 1; ++i)
19 | for (int k = 0; k < a.length - 1 - i; ++k)
20 | if (a[k + 1] < a[k])
21 | swap(a, k, k + 1);
22 | }
23 |
24 | private static void bubbleSortDescending(int [] a)
25 | {
26 | for (int i = 0; i < a.length - 1; ++i)
27 | for (int k = 0; k < a.length -1 - i; ++k)
28 | if (a[k] < a[k + 1])
29 | swap(a, k, k + 1);
30 | }
31 |
32 | private static void selectionSortAscending(int [] a)
33 | {
34 | int min, minIndex;
35 |
36 | for (int i = 0; i < a.length - 1; ++i) {
37 | min = a[i];
38 | minIndex = i;
39 |
40 | for (int k = i + 1; k < a.length; ++k)
41 | if (a[k] < min) {
42 | min = a[k];
43 | minIndex = k;
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 | a[maxIndex] = a[i];
64 | a[i] = max;
65 | }
66 | }
67 |
68 | public static double average(int [] a)
69 | {
70 | return sum(a) / (double)a.length;
71 | }
72 |
73 | public static void bubbleSort(int [] a)
74 | {
75 | bubbleSort(a, false);
76 | }
77 |
78 | public static void bubbleSort(int [] a, boolean descending)
79 | {
80 | if (descending)
81 | bubbleSortDescending(a);
82 | else
83 | bubbleSortAscending(a);
84 | }
85 |
86 | public static void drawHistogram(int [] data, int n, char ch)
87 | {
88 | int maxValue = ArrayUtil.max(data);
89 |
90 | for (int grade : data) {
91 | int count = (int)Math.floor(grade * n / (double)maxValue);
92 |
93 | while (count-- > 0)
94 | System.out.print(ch);
95 |
96 | System.out.println();
97 | }
98 | }
99 |
100 | public static int [] generateRandomArray(RandomGenerator randomGenerator, int count, int origin, int bound)
101 | {
102 | int [] a = new int[count];
103 |
104 | for (int i = 0; i < count; ++i)
105 | a[i] = randomGenerator.nextInt(origin, bound);
106 |
107 | return a;
108 | }
109 |
110 | public static double [] generateRandomArray(RandomGenerator randomGenerator, int count, double origin, double bound)
111 | {
112 | double [] a = new double[count];
113 |
114 | for (int i = 0; i < count; ++i)
115 | a[i] = randomGenerator.nextDouble(origin, bound);
116 |
117 | return a;
118 | }
119 |
120 | public static boolean [] generateRandomArray(RandomGenerator randomGenerator, int count)
121 | {
122 | boolean [] a = new boolean[count];
123 |
124 | for (int i = 0; i < count; ++i)
125 | a[i] = randomGenerator.nextBoolean();
126 |
127 | return a;
128 | }
129 |
130 | public static int [] histogramData(int [] a, int n)
131 | {
132 | int [] data = new int[n + 1];
133 |
134 | for (int val : a)
135 | ++data[val];
136 |
137 | return data;
138 | }
139 |
140 | public static int max(int [] a)
141 | {
142 | return max(a, 0);
143 | }
144 |
145 | public static int max(int [] a, int startIndex)
146 | {
147 | int result = a[startIndex];
148 |
149 | for (int i = startIndex + 1; i < a.length; ++i)
150 | result = Math.max(result, a[i]);
151 |
152 | return result;
153 | }
154 |
155 | public static int max(int [][] a)
156 | {
157 | int result = Integer.MIN_VALUE;
158 |
159 | for (int [] array : a)
160 | result = Math.max(result, max(array));
161 |
162 | return result;
163 | }
164 |
165 | public static int min(int [] a)
166 | {
167 | return min(a, 0);
168 | }
169 |
170 | public static int min(int [] a, int startIndex)
171 | {
172 | int result = a[startIndex];
173 |
174 | for (int i = startIndex + 1; i < a.length; ++i)
175 | result = Math.min(result, a[i]);
176 |
177 | return result;
178 | }
179 |
180 | public static int min(int [][] a)
181 | {
182 | int result = Integer.MAX_VALUE;
183 |
184 | for (int [] array : a)
185 | result = Math.min(result, min(array));
186 |
187 | return result;
188 | }
189 |
190 | public static void multiplyBy(int [] a, int value)
191 | {
192 | for (int i = 0; i < a.length; ++i)
193 | a[i] *= value;
194 | }
195 |
196 | public static void multiplyBy(int [][] a, int value)
197 | {
198 | for (int [] array : a)
199 | multiplyBy(array, value);
200 | }
201 |
202 | public static int partition(int [] a, int threshold)
203 | {
204 | int partitionPoint = 0;
205 |
206 | while (partitionPoint != a.length && a[partitionPoint] < threshold)
207 | ++partitionPoint;
208 |
209 | if (partitionPoint == a.length)
210 | return partitionPoint;
211 |
212 | for (int i = partitionPoint + 1; i < a.length; ++i)
213 | if (a[i] < threshold)
214 | swap(a, i, partitionPoint++);
215 |
216 | return partitionPoint;
217 | }
218 |
219 | public static int partitionByEven(int [] a)
220 | {
221 | int partitionPoint = 0;
222 |
223 | while (partitionPoint != a.length && a[partitionPoint] % 2 == 0)
224 | ++partitionPoint;
225 |
226 | if (partitionPoint == a.length)
227 | return partitionPoint;
228 |
229 | for (int i = partitionPoint + 1; i < a.length; ++i)
230 | if (a[i] % 2 == 0)
231 | swap(a, i, partitionPoint++);
232 |
233 | return partitionPoint;
234 | }
235 |
236 | public static void print(int [] a)
237 | {
238 | print(a, ' ', '\n');
239 | }
240 |
241 | public static void print(int [] a, char sep, char end)
242 | {
243 | print(a, 1, sep, end);
244 | }
245 |
246 | public static void print(int [] a, int n)
247 | {
248 | print(a, n, ' ', '\n');
249 | }
250 |
251 | public static void print(int [] a, int n, char sep, char end)
252 | {
253 | String fmt = String.format("%%0%dd%c", n, sep);
254 |
255 | for (int val : a)
256 | System.out.printf(fmt, val, sep);
257 |
258 | System.out.print(end);
259 | }
260 |
261 | public static void print(int [][] a)
262 | {
263 | print(a, 1);
264 | }
265 |
266 | public static void print(int [][] a, int n)
267 | {
268 | for (int [] array : a)
269 | print(array, n, ' ', '\n');
270 | }
271 |
272 | public static void print(double [] a)
273 | {
274 | print(a, '\n', '\n');
275 | }
276 |
277 | public static void print(double [] a, char sep, char end)
278 | {
279 | for (double val : a)
280 | System.out.printf("%f%c", val, sep);
281 |
282 | System.out.print(end);
283 | }
284 |
285 | public static void reverse(int [] a)
286 | {
287 | int left = 0, right = a.length - 1;
288 |
289 | while (left < right)
290 | swap(a, left++, right--);
291 | }
292 |
293 | public static void reverse(char [] a)
294 | {
295 | int left = 0, right = a.length - 1;
296 |
297 | while (left < right)
298 | swap(a, left++, right--);
299 | }
300 |
301 | public static void selectionSort(int [] a)
302 | {
303 | selectionSort(a, false);
304 | }
305 |
306 | public static void selectionSort(int [] a, boolean descending)
307 | {
308 | if (descending)
309 | selectionSortDescending(a);
310 | else
311 | selectionSortAscending(a);
312 | }
313 | public static long sum(int [] a)
314 | {
315 | long total = 0;
316 |
317 | for (int val : a)
318 | total += val;
319 |
320 | return total;
321 | }
322 |
323 | public static void swap(int [] a, int i, int k)
324 | {
325 | int temp = a[i];
326 |
327 | a[i] = a[k];
328 | a[k] = temp;
329 | }
330 |
331 | public static void swap(char [] a, int i, int k)
332 | {
333 | char temp = a[i];
334 |
335 | a[i] = a[k];
336 | a[k] = temp;
337 | }
338 |
339 | //...
340 | }
341 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilBubbleSortTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.*;
7 |
8 | public class ArrayUtilBubbleSortTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Bir sayı giriniz:");
16 | int count = Integer.parseInt(kb.nextLine());
17 |
18 | if (count <= 0)
19 | break;
20 |
21 | int [] a = generateRandomArray(r, count, 0, 100);
22 |
23 | print(a, 2);
24 | boolean descending = r.nextBoolean();
25 | System.out.printf("Dizi %s olarak sıralanıyor%n", descending ? "azalan sırada" : "artan sırada");
26 | bubbleSort(a, descending);
27 | print(a, 2);
28 | }
29 | }
30 |
31 | public static void main(String[] args)
32 | {
33 | run();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilHistogramDataTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.*;
7 |
8 | public class ArrayUtilHistogramDataTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Bir sayı giriniz:");
16 | int count = Integer.parseInt(kb.nextLine());
17 |
18 | if (count <= 0)
19 | break;
20 |
21 | int [] a = generateRandomArray(r, count, 0, 11);
22 |
23 | System.out.print("Dizi:");
24 | print(a, 2);
25 | int [] hist = histogramData(a, 10);
26 | System.out.print("Sayı dizisi:");
27 | print(hist, 2);
28 | }
29 | }
30 |
31 | public static void main(String[] args)
32 | {
33 | run();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilMinMaxTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.*;
7 |
8 | public class ArrayUtilMinMaxTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Bir sayı giriniz:");
16 | int count = Integer.parseInt(kb.nextLine());
17 |
18 | if (count <= 0)
19 | break;
20 |
21 | int [] a = generateRandomArray(r, count, 0, 100);
22 |
23 | print(a, 2);
24 | System.out.printf("En büyük eleman:%d%nEn küçük eleman:%d%n", max(a), min(a));
25 | }
26 | }
27 |
28 | public static void main(String[] args)
29 | {
30 | run();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilPartitionTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.*;
7 |
8 | public class ArrayUtilPartitionTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Input count:");
16 | int count = Integer.parseInt(kb.nextLine());
17 |
18 | if (count <= 0)
19 | break;
20 |
21 | int [] a = generateRandomArray(r, count, 0, 100);
22 |
23 | print(a, 2);
24 |
25 | System.out.print("Input threshold:");
26 | int threshold = Integer.parseInt(kb.nextLine());
27 |
28 | System.out.printf("Threshold:%d%n", threshold);
29 | int partitionPoint = partition(a, threshold);
30 |
31 | print(a);
32 | System.out.printf("Partition Point:%d%n", partitionPoint);
33 | }
34 | }
35 |
36 | public static void main(String[] args)
37 | {
38 | run();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilReverseCharArrayTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.reverse;
7 |
8 | public class ArrayUtilReverseCharArrayTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Bir yazı giriniz:");
16 | String text = kb.nextLine();
17 |
18 | if ("elma".equals(text))
19 | break;
20 |
21 | char [] chars = text.toCharArray();
22 |
23 | System.out.println(text);
24 | reverse(chars);
25 | for (char c : chars)
26 | System.out.printf("%c", c);
27 |
28 | System.out.println();
29 | }
30 | }
31 |
32 | public static void main(String[] args)
33 | {
34 | run();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilReverseIntArrayTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.*;
7 |
8 | public class ArrayUtilReverseIntArrayTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Bir sayı giriniz:");
16 | int count = Integer.parseInt(kb.nextLine());
17 |
18 | if (count <= 0)
19 | break;
20 |
21 | int [] a = generateRandomArray(r, count, 0, 100);
22 |
23 | print(a, 2);
24 | reverse(a);
25 | print(a, 2);
26 | }
27 | }
28 |
29 | public static void main(String[] args)
30 | {
31 | run();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilSelectionSortTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.*;
7 |
8 | public class ArrayUtilSelectionSortTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Bir sayı giriniz:");
16 | int count = Integer.parseInt(kb.nextLine());
17 |
18 | if (count <= 0)
19 | break;
20 |
21 | int [] a = generateRandomArray(r, count, 0, 100);
22 |
23 | print(a, 2);
24 | boolean descending = r.nextBoolean();
25 | System.out.printf("Dizi %s olarak sıralanıyor%n", descending ? "azalan sırada" : "artan sırada");
26 | selectionSort(a, descending);
27 | print(a, 2);
28 | }
29 | }
30 |
31 | public static void main(String[] args)
32 | {
33 | run();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/array/test/ArrayUtilSumTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.array.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.*;
7 |
8 | public class ArrayUtilSumTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Bir sayı giriniz:");
16 | int count = Integer.parseInt(kb.nextLine());
17 |
18 | if (count <= 0)
19 | break;
20 |
21 | int [] a = generateRandomArray(r, count, 0, 100);
22 |
23 | print(a, 2);
24 | System.out.printf("Total:%d%n", sum(a));
25 | }
26 | }
27 |
28 | public static void main(String[] args)
29 | {
30 | run();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/collection/CollectionUtil.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.collection;
2 |
3 | import org.csystem.util.string.StringUtil;
4 |
5 | import java.util.ArrayList;
6 | import java.util.random.RandomGenerator;
7 |
8 | /**
9 | * Utility class for collection operations
10 | * Last Update: 15th May 2025
11 | * @author Java-Sep-2024 Group
12 | */
13 |
14 | public final class CollectionUtil {
15 | private CollectionUtil()
16 | {
17 | }
18 |
19 | public static ArrayList randomStringListTR(RandomGenerator randomGenerator, int count, int min, int bound)
20 | {
21 | ArrayList list = new ArrayList<>();
22 |
23 | for (int i = 0; i < count; ++i)
24 | list.add(StringUtil.generateRandomTextTR(randomGenerator, randomGenerator.nextInt(min, bound)));
25 |
26 | return list;
27 | }
28 |
29 | public static ArrayList randomStringListTR(RandomGenerator randomGenerator, int min, int bound)
30 | {
31 | return randomStringListTR(randomGenerator, randomGenerator.nextInt(min, bound), min, bound);
32 | }
33 |
34 | //...
35 | }
36 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/console/CommandLineArgsUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for command line operations
3 | * Last Update: 10th December 2024
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.console;
7 |
8 | public final class CommandLineArgsUtil {
9 | private CommandLineArgsUtil()
10 | {
11 | }
12 |
13 | public static void checkLengthEquals(int len, int argsLen, String message)
14 | {
15 | checkLengthEquals(len, argsLen, message, 1);
16 | }
17 |
18 | public static void checkLengthEquals(int len, int argsLen, String message, int exitCode)
19 | {
20 | if (len != argsLen) {
21 | System.err.println(message);
22 | System.exit(exitCode);
23 | }
24 | }
25 |
26 | public static void checkLengthGreater(int len, int argsLen, String message)
27 | {
28 | checkLengthGreater(len, argsLen, message, 1);
29 | }
30 |
31 | public static void checkLengthGreater(int len, int argsLen, String message, int exitCode)
32 | {
33 | if (argsLen <= len) {
34 | System.err.println(message);
35 | System.exit(exitCode);
36 | }
37 | }
38 |
39 | //...
40 | }
41 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/console/Console.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for console operations
3 | * Last Update: 10th April 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.console;
7 |
8 | import java.util.Scanner;
9 |
10 | public class Console {
11 | private Console()
12 | {
13 | }
14 |
15 | private static final Scanner KB;
16 |
17 | static {
18 | KB = new Scanner(System.in);
19 | }
20 |
21 | public static int readInt()
22 | {
23 | return readInt("");
24 | }
25 |
26 | public static int readInt(String prompt)
27 | {
28 | return readInt(prompt, "");
29 | }
30 |
31 | public static int readInt(String prompt, String errorPrompt)
32 | {
33 | while (true) {
34 | try {
35 | System.out.print(prompt);
36 |
37 | return Integer.parseInt(KB.nextLine());
38 | }
39 | catch (NumberFormatException ignore) {
40 | System.out.print(errorPrompt);
41 | }
42 | }
43 | }
44 |
45 | public static long readLong()
46 | {
47 | return readLong("");
48 | }
49 |
50 | public static long readLong(String prompt)
51 | {
52 | return readLong(prompt, "");
53 | }
54 |
55 | public static long readLong(String prompt, String errorPrompt)
56 | {
57 | while (true) {
58 | try {
59 | System.out.print(prompt);
60 |
61 | return Long.parseLong(KB.nextLine());
62 | }
63 | catch (NumberFormatException ignore) {
64 | System.out.print(errorPrompt);
65 | }
66 | }
67 | }
68 |
69 | public static double readDouble()
70 | {
71 | return readDouble("");
72 | }
73 |
74 | public static double readDouble(String prompt)
75 | {
76 | return readDouble(prompt, "");
77 | }
78 |
79 | public static double readDouble(String prompt, String errorPrompt)
80 | {
81 | while (true) {
82 | try {
83 | System.out.print(prompt);
84 |
85 | return Double.parseDouble(KB.nextLine());
86 | }
87 | catch (NumberFormatException ignore) {
88 | System.out.print(errorPrompt);
89 | }
90 | }
91 | }
92 |
93 | //...
94 |
95 | public static String readString(String prompt)
96 | {
97 | System.out.print(prompt);
98 |
99 | return KB.nextLine();
100 | }
101 |
102 | public static void write(String fmt, Object...objects)
103 | {
104 | System.out.printf(fmt, objects);
105 | }
106 |
107 | public static void writeLine(String fmt, Object...objects)
108 | {
109 | write(fmt + '\n', objects);
110 | }
111 |
112 | public static void writeLine()
113 | {
114 | System.out.println();
115 | }
116 |
117 | public static void write(Object object)
118 | {
119 | System.out.print(object);
120 | }
121 |
122 | public static void writeLine(Object object)
123 | {
124 | System.out.println(object);
125 | }
126 |
127 | //...
128 | }
129 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/math/MathUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for math operations
3 | * Last Update:10th December 2024
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.math;
7 |
8 | public final class MathUtil {
9 | private MathUtil()
10 | {
11 | }
12 |
13 | public static double log(double a, double b)
14 | {
15 | return Math.log(b) / Math.log(a);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/MatrixUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for array operations
3 | * Last Update: 15th May 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.matrix;
7 |
8 | import org.csystem.util.array.ArrayUtil;
9 |
10 | import java.util.random.RandomGenerator;
11 |
12 | public final class MatrixUtil {
13 | private MatrixUtil()
14 | {
15 | }
16 |
17 | public static int [][] add(int [][] a, int [][] b)
18 | {
19 | int m = a.length;
20 | int n = a[0].length;
21 | int [][] r = new int[m][n];
22 |
23 | for (int i = 0; i < m; ++i)
24 | for (int j = 0; j < n; ++j)
25 | r[i][j] = a[i][j] + b[i][j];
26 |
27 | return r;
28 | }
29 |
30 | public static double [][] add(double [][] a, double [][] b)
31 | {
32 | int m = a.length;
33 | int n = a[0].length;
34 | double [][] r = new double[m][n];
35 |
36 | for (int i = 0; i < m; ++i)
37 | for (int j = 0; j < n; ++j)
38 | r[i][j] = a[i][j] + b[i][j];
39 |
40 | return r;
41 | }
42 |
43 | public static int [][] generateRandomMatrix(RandomGenerator randomGenerator, int m, int n, int origin, int bound)
44 | {
45 | int [][] result = new int[m][];
46 |
47 | for (int i = 0; i < m; ++i)
48 | result[i] = ArrayUtil.generateRandomArray(randomGenerator, n, origin, bound);
49 |
50 | return result;
51 | }
52 |
53 | public static int [][] generateRandomSquareMatrix(RandomGenerator randomGenerator, int n, int origin, int bound)
54 | {
55 | return generateRandomMatrix(randomGenerator, n, n, origin, bound);
56 | }
57 |
58 | public static boolean isMatrix(int [][] a)
59 | {
60 | for (int i = 1; i < a.length; ++i)
61 | if (a[i].length != a[0].length)
62 | return false;
63 |
64 | return true;
65 | }
66 |
67 | public static boolean isSquareMatrix(int [][] a)
68 | {
69 | return isMatrix(a) && a.length == a[0].length;
70 | }
71 |
72 | public static int max(int [][] a)
73 | {
74 | return ArrayUtil.max(a);
75 | }
76 |
77 | public static int min(int [][] a)
78 | {
79 | return ArrayUtil.min(a);
80 | }
81 |
82 | public static int [][] multiply(int [][] a, int [][] b)
83 | {
84 | int m = a.length;
85 | int n = a[0].length;
86 | int p = b[0].length;
87 | int [][] r = new int[m][p];
88 |
89 | for (int i = 0; i < m; ++i)
90 | for (int j = 0; j < n; ++j)
91 | for (int k = 0; k < p; ++k)
92 | r[i][k] += a[i][j] * b[j][k];
93 |
94 | return r;
95 | }
96 |
97 | public static void multiplyBy(int [][] a, int value)
98 | {
99 | ArrayUtil.multiplyBy(a, value);
100 | }
101 |
102 | public static void print(int [][] a)
103 | {
104 | print(a, 1);
105 | }
106 |
107 | public static void print(int [][] a, int n)
108 | {
109 | ArrayUtil.print(a, n);
110 | }
111 |
112 | public static int [][] subtract(int [][] a, int [][] b)
113 | {
114 | int m = a.length;
115 | int n = a[0].length;
116 | int [][] r = new int[m][n];
117 |
118 | for (int i = 0; i < m; ++i)
119 | for (int j = 0; j < n; ++j)
120 | r[i][j] = a[i][j] - b[i][j];
121 |
122 | return r;
123 | }
124 |
125 | public static long sum(int [][] a)
126 | {
127 | long total = 0;
128 |
129 | for (int [] array : a)
130 | total += ArrayUtil.sum(array);
131 |
132 | return total;
133 | }
134 |
135 | public static long sumDiagonal(int [][] a)
136 | {
137 | long total = 0;
138 |
139 | for (int i = 0; i < a.length; ++i)
140 | total += a[i][i];
141 |
142 | return total;
143 | }
144 |
145 | public static int [][] transpose(int [][] a)
146 | {
147 | int m = a.length;
148 | int n = a[0].length;
149 | int [][] r = new int[n][m];
150 |
151 | for (int i = 0; i < n; ++i)
152 | for (int j = 0; j < m; ++j)
153 | r[i][j] = a[j][i];
154 |
155 | return r;
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilAddTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.matrix.MatrixUtil.*;
7 |
8 | public class MatrixUtilAddTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Satır sayısını giriniz:");
16 | int m = Integer.parseInt(kb.nextLine());
17 |
18 | System.out.print("Sütun sayısını giriniz:");
19 | int n = Integer.parseInt(kb.nextLine());
20 |
21 | if (m <= 0 || n <= 0)
22 | break;
23 |
24 | int [][] a = generateRandomMatrix(r, m, n, 0, 100);
25 | int [][] b = generateRandomMatrix(r, m, n, 0, 100);
26 |
27 | print(a, 2);
28 | System.out.println("---------------------------------------------");
29 | print(b, 2);
30 | System.out.println("---------------------------------------------");
31 |
32 | int [][] c = add(a, b);
33 |
34 | print(c, 3);
35 | }
36 | }
37 |
38 | public static void main(String[] args)
39 | {
40 | run();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilIsMatrixTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import org.csystem.util.array.ArrayUtil;
4 | import org.csystem.util.matrix.MatrixUtil;
5 |
6 | public class MatrixUtilIsMatrixTest {
7 | public static void run()
8 | {
9 | int [][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
10 | int [][] b = {{1, 2, 3}, {4, 5, 6, 3}, {7, 8, 9}};
11 |
12 | ArrayUtil.print(a);
13 | System.out.println("--------------------------------");
14 | ArrayUtil.print(b);
15 |
16 | System.out.println(MatrixUtil.isMatrix(a) ? "Matris" : "Matris değil");
17 | System.out.println(MatrixUtil.isMatrix(b) ? "Matris" : "Matris değil");
18 | }
19 |
20 | public static void main(String[] args)
21 | {
22 | run();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilIsSquareMatrixTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import org.csystem.util.array.ArrayUtil;
4 | import org.csystem.util.matrix.MatrixUtil;
5 |
6 | public class MatrixUtilIsSquareMatrixTest {
7 | public static void run()
8 | {
9 | int [][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
10 | int [][] b = {{1, 2, 3}, {4, 5, 6, 3}, {7, 8, 9}};
11 | int [][] c = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {1, 2, 3}};
12 |
13 | ArrayUtil.print(a);
14 | System.out.println("--------------------------------");
15 | ArrayUtil.print(b);
16 | System.out.println("--------------------------------");
17 | ArrayUtil.print(c);
18 |
19 | System.out.println(MatrixUtil.isSquareMatrix(a) ? "Kare matris" : "Kare matris değil");
20 | System.out.println(MatrixUtil.isSquareMatrix(b) ? "Kare matris" : "Kare matris değil");
21 | System.out.println(MatrixUtil.isSquareMatrix(c) ? "Kare matris" : "Kare matris değil");
22 | }
23 |
24 | public static void main(String[] args)
25 | {
26 | run();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilMinMaxTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.matrix.MatrixUtil.*;
7 |
8 | public class MatrixUtilMinMaxTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Satır sayısını giriniz:");
16 | int m = Integer.parseInt(kb.nextLine());
17 |
18 | System.out.print("Sütun sayısını giriniz:");
19 | int n = Integer.parseInt(kb.nextLine());
20 |
21 | if (m <= 0 || n <= 0)
22 | break;
23 |
24 | int [][] a = generateRandomMatrix(r, m, n, 0, 100);
25 |
26 | print(a, 2);
27 | System.out.printf("En büyük eleman:%d%nEn küçük eleman:%d%n", max(a), min(a));
28 | }
29 | }
30 |
31 | public static void main(String[] args)
32 | {
33 | run();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilMultiplyByTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.matrix.MatrixUtil.*;
7 |
8 | public class MatrixUtilMultiplyByTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Satır sayısını giriniz:");
16 | int m = Integer.parseInt(kb.nextLine());
17 |
18 | System.out.print("Sütun sayısını giriniz:");
19 | int n = Integer.parseInt(kb.nextLine());
20 |
21 | if (m <= 0 || n <= 0)
22 | break;
23 |
24 | System.out.print("Bir sayı giriniz:");
25 | int value = Integer.parseInt(kb.nextLine());
26 |
27 | int [][] a = generateRandomMatrix(r, m, n, 0, 100);
28 |
29 |
30 | print(a, 2);
31 | System.out.println();
32 | multiplyBy(a, value);
33 | print(a, 3);
34 | }
35 | }
36 |
37 | public static void main(String[] args)
38 | {
39 | run();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilMultiplyTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.matrix.MatrixUtil.*;
7 |
8 | public class MatrixUtilMultiplyTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Satır sayısını giriniz:");
16 | int m = Integer.parseInt(kb.nextLine());
17 |
18 | System.out.print("Sütun sayısını giriniz:");
19 | int n = Integer.parseInt(kb.nextLine());
20 |
21 | System.out.print("İkinci matrisin sütun sayısını giriniz:");
22 | int k = Integer.parseInt(kb.nextLine());
23 |
24 | if (m <= 0 || n <= 0 || k <= 0)
25 | break;
26 |
27 | int [][] a = generateRandomMatrix(r, m, n, 0, 10);
28 | int [][] b = generateRandomMatrix(r, n, k, 0, 10);
29 |
30 | print(a, 2);
31 | System.out.println("---------------------------------------------");
32 | print(b, 2);
33 | System.out.println("---------------------------------------------");
34 |
35 | int [][] c = multiply(a, b);
36 |
37 | print(c, 3);
38 | }
39 | }
40 |
41 | public static void main(String[] args)
42 | {
43 | run();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilSubtractTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.matrix.MatrixUtil.*;
7 |
8 | public class MatrixUtilSubtractTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Satır sayısını giriniz:");
16 | int m = Integer.parseInt(kb.nextLine());
17 |
18 | System.out.print("Sütun sayısını giriniz:");
19 | int n = Integer.parseInt(kb.nextLine());
20 |
21 | if (m <= 0 || n <= 0)
22 | break;
23 |
24 | int [][] a = generateRandomMatrix(r, m, n, 0, 100);
25 | int [][] b = generateRandomMatrix(r, m, n, 0, 100);
26 |
27 | print(a, 2);
28 | System.out.println("---------------------------------------------");
29 | print(b, 2);
30 | System.out.println("---------------------------------------------");
31 |
32 | int [][] c = subtract(a, b);
33 |
34 | print(c, 3);
35 | }
36 | }
37 |
38 | public static void main(String[] args)
39 | {
40 | run();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/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 | import java.util.Random;
6 | import java.util.Scanner;
7 |
8 | public class MatrixUtilSumDiagonalTest {
9 | public static void run()
10 | {
11 | Random random = new Random();
12 | Scanner kb = new Scanner(System.in);
13 |
14 |
15 | while (true) {
16 | System.out.print("Bir sayı giriniz:");
17 | int n = Integer.parseInt(kb.nextLine());
18 |
19 | if (n <= 0)
20 | break;
21 |
22 | int [][] a = MatrixUtil.generateRandomSquareMatrix(random, n, 0, 100);
23 |
24 | MatrixUtil.print(a, 2);
25 |
26 | System.out.printf("Esas köşegen toplamı:%d%n", MatrixUtil.sumDiagonal(a));
27 | }
28 | }
29 |
30 | public static void main(String[] args)
31 | {
32 | run();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/matrix/test/MatrixUtilTransposeTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.matrix.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.matrix.MatrixUtil.*;
7 |
8 | public class MatrixUtilTransposeTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | while (true) {
15 | System.out.print("Satır sayısını giriniz:");
16 | int m = Integer.parseInt(kb.nextLine());
17 |
18 | System.out.print("Sütun sayısını giriniz:");
19 | int n = Integer.parseInt(kb.nextLine());
20 |
21 | if (m <= 0 || n <= 0)
22 | break;
23 |
24 | int [][] a = generateRandomMatrix(r, m, n, 0, 100);
25 |
26 | print(a, 2);
27 | System.out.println();
28 | print(transpose(a), 2);
29 | }
30 | }
31 |
32 | public static void main(String[] args)
33 | {
34 | run();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/numeric/NumberUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for numeric operations
3 | * Last Update: 28th March 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.numeric;
7 |
8 | public final class NumberUtil {
9 | private NumberUtil()
10 | {
11 | }
12 |
13 | private static final String ZERO_TR;
14 | private static final String MINUS_TR;
15 | private static final String [] ONES_TR;
16 | private static final String [] TENS_TR;
17 | private static final String [] NUMBER_UNITS_TR;
18 |
19 | private static final String ZERO_EN;
20 | private static final String MINUS_EN;
21 | private static final String [] ONES_EN;
22 | private static final String [] TENS_EN;
23 | private static final String [] NUMBER_UNITS_EN;
24 |
25 | static {
26 | ZERO_TR = "sıfır";
27 | MINUS_TR = "eksi";
28 | ONES_TR = new String[]{"", "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz"};
29 | TENS_TR = new String[]{"", "on", "yirmi", "otuz", "kırk", "elli", "altmış", "yetmiş", "seksen", "doksan"};
30 | NUMBER_UNITS_TR = new String[]{"kentilyon", "katrilyon", "trilyon", "milyar", "milyon", "bin", ""};
31 |
32 | ZERO_EN = "zero";
33 | MINUS_EN= "minus";
34 | ONES_EN = new String[]{"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
35 | TENS_EN = new String[] {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
36 | NUMBER_UNITS_EN = new String[] {"quintillion", "quadrillion", "trillion", "billion", "million", "thousand", ""};
37 | }
38 |
39 | private static int [] getDigits(long a, int n)
40 | {
41 | int divider = (int)Math.pow(10, n);
42 | a = Math.abs(a);
43 | int [] digits = new int[a == 0 ? 1 : (int)(Math.log10(a) / n) + 1];
44 |
45 | for (int i = digits.length - 1; i >= 0; digits[i--] = (int)(a % divider), a /= divider)
46 | ;
47 |
48 | return digits;
49 | }
50 |
51 | private static String numToStr3DigitsTR(int val)
52 | {
53 | StringBuilder sb = new StringBuilder();
54 |
55 | int a = val / 100;
56 | int b = val / 10 % 10;
57 | int c = val % 10;
58 |
59 | if (a != 0) {
60 | if (a != 1)
61 | sb.append(ONES_TR[a]).append(" ");
62 | sb.append("yüz ");
63 | }
64 |
65 | if (b != 0)
66 | sb.append(TENS_TR[b]).append(" ");
67 |
68 | if (c != 0)
69 | sb.append(ONES_TR[c]).append(" ");
70 |
71 | return sb.isEmpty() ? "" : sb.substring(0, sb.length() - 1);
72 | }
73 |
74 | private static String numToStr3DigitsEN(int val)
75 | {
76 | StringBuilder sb = new StringBuilder();
77 |
78 | int a = val / 100;
79 | int b = val / 10 % 10;
80 | int c = val % 10;
81 |
82 | if (a != 0)
83 | sb.append(ONES_EN[a]).append(" ").append("hundred ");
84 |
85 | if (b != 0)
86 | sb.append(TENS_EN[b]).append(" ");
87 |
88 | if (c != 0)
89 | sb.append(ONES_EN[c]).append(" ");
90 |
91 | return sb.isEmpty() ? "" : sb.substring(0, sb.length() - 1);
92 | }
93 |
94 | public static int countDigits(long a)
95 | {
96 | return a != 0 ? (int)Math.log10(Math.abs(a)) + 1 : 1;
97 | }
98 |
99 | public static long factorial(int n)
100 | {
101 | long result = 1;
102 |
103 | for (long i = 2; i <= n; ++i)
104 | result *= i;
105 |
106 | return result;
107 | }
108 |
109 | public static int fibonacciNumber(int n)
110 | {
111 | if (n <= 2)
112 | return n - 1;
113 |
114 | int prev1 = 1, prev2 = 0, result = prev1 + prev2;
115 |
116 | for (int i = 3; i < n; ++i) {
117 | prev2 = prev1;
118 | prev1 = result;
119 | result = prev1 + prev2;
120 | }
121 |
122 | return result;
123 | }
124 |
125 | public static int [] getDigits(long a)
126 | {
127 | return getDigits(a, 1);
128 | }
129 |
130 | public static int [] getDigitsInThrees(long a)
131 | {
132 | return getDigits(a, 3);
133 | }
134 |
135 | public static int [] getDigitsInTwos(long a)
136 | {
137 | return getDigits(a, 2);
138 | }
139 |
140 | public static int getDigitsPowSum(int a)
141 | {
142 | int result = 0;
143 | int n = countDigits(a);
144 |
145 | while (a != 0) {
146 | result += (int)Math.pow(a % 10, n);
147 | a /= 10;
148 | }
149 |
150 | return result;
151 | }
152 |
153 | public static boolean isArmstrong(int a)
154 | {
155 | return a >= 0 && getDigitsPowSum(a) == a;
156 | }
157 |
158 | public static boolean isEven(int a)
159 | {
160 | return a % 2 == 0;
161 | }
162 |
163 | public static boolean isOdd(int a)
164 | {
165 | return !isEven(a);
166 | }
167 |
168 | public static boolean isPrime(long a)
169 | {
170 | if (a <= 1)
171 | return false;
172 |
173 | if (a % 2 == 0)
174 | return a == 2;
175 |
176 | if (a % 3 == 0)
177 | return a == 3;
178 |
179 | if (a % 5 == 0)
180 | return a == 5;
181 |
182 | if (a % 7 == 0)
183 | return a == 7;
184 |
185 | for (long i = 11; i * i <= a; i += 2)
186 | if (a % i == 0)
187 | return false;
188 |
189 | return true;
190 | }
191 |
192 | public static long nextClosestPrime(long a)
193 | {
194 | if (a < 2)
195 | return 2;
196 |
197 | while (!isPrime(++a))
198 | ;
199 |
200 | return a;
201 | }
202 |
203 | public static int nextFibonacciNumber(int val)
204 | {
205 | if (val < 0)
206 | return 0;
207 |
208 | int prev1 = 1, prev2 = 0, next = prev1 + prev2;
209 |
210 | while (next <= val) {
211 | prev2 = prev1;
212 | prev1 = next;
213 | next = prev1 + prev2;
214 | }
215 |
216 | return next;
217 | }
218 |
219 | public static long nthPrime(int n)
220 | {
221 | long result = 2;
222 | int count = 0;
223 |
224 | for (long i = 2; count < n; ++i)
225 | if (isPrime(i)) {
226 | ++count;
227 | result = i;
228 | }
229 | return result;
230 | }
231 |
232 | public static String numToStrTR(long a)
233 | {
234 | if (a == 0)
235 | return ZERO_TR;
236 |
237 | int [] threes = getDigitsInThrees(a);
238 | StringBuilder sb = new StringBuilder();
239 | int idx = NUMBER_UNITS_TR.length - 1;
240 |
241 | for (int i = threes.length - 1; i >= 0; --i) {
242 | if (threes[i] != 0)
243 | sb.insert(0, "%s%s ".formatted(idx == NUMBER_UNITS_TR.length - 2 && threes[i] == 1 ? "" : numToStr3DigitsTR(threes[i]) + " ", NUMBER_UNITS_TR[idx]));
244 |
245 | --idx;
246 | }
247 |
248 | return "%s%s".formatted(a < 0 ? MINUS_TR + " " : "", sb.substring(0, sb.length() - 2));
249 | }
250 |
251 | public static String numToStrEN(long a)
252 | {
253 | if (a == 0)
254 | return ZERO_EN;
255 |
256 | int [] threes = getDigitsInThrees(a);
257 | StringBuilder sb = new StringBuilder();
258 | int idx = NUMBER_UNITS_EN.length - 1;
259 |
260 | for (int i = threes.length - 1; i >= 0; --i) {
261 | if (threes[i] != 0)
262 | sb.insert(0, "%s %s ".formatted(numToStr3DigitsEN(threes[i]), NUMBER_UNITS_EN[idx]));
263 |
264 | --idx;
265 | }
266 |
267 | return "%s%s".formatted(a < 0 ? MINUS_EN + " " : "", sb.substring(0, sb.length() - 2));
268 | }
269 |
270 | public static int reverse(int val)
271 | {
272 | int result = 0;
273 |
274 | while (val != 0) {
275 | result = result * 10 + val % 10;
276 | val /= 10;
277 | }
278 |
279 | return result;
280 | }
281 |
282 | public static int sumDigits(int val)
283 | {
284 | int total = 0;
285 |
286 | while (val != 0) {
287 | total += val % 10;
288 | val /= 10;
289 | }
290 |
291 | return Math.abs(total);
292 | }
293 | }
294 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/numeric/test/NumberUtilGetDigitsTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.numeric.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.array.ArrayUtil.print;
7 | import static org.csystem.util.numeric.NumberUtil.*;
8 |
9 | public class NumberUtilGetDigitsTest {
10 | public static void run()
11 | {
12 | Scanner kb = new Scanner(System.in);
13 | Random r = new Random();
14 |
15 | System.out.print("Bir sayı giriniz:");
16 | int n = kb.nextInt();
17 |
18 | for (int i = 0; i < n; ++i) {
19 | long val = r.nextLong();
20 |
21 | System.out.printf("%d -> ", val);
22 | print(getDigits(val));
23 | System.out.printf("%d -> ", val);
24 | print(getDigitsInTwos(val));
25 | System.out.printf("%d -> ", val);
26 | print(getDigitsInThrees(val));
27 | System.out.println("------------------------------------------------------------");
28 | }
29 |
30 | System.out.print("0 -> ");
31 | print(getDigits(0));
32 | System.out.print("0 -> ");
33 | print(getDigitsInTwos(0));
34 | System.out.print("0 -> ");
35 | print(getDigitsInThrees(0));
36 |
37 | }
38 |
39 | public static void main(String[] args)
40 | {
41 | run();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/numeric/test/NumberUtilNumToStrENTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.numeric.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.numeric.NumberUtil.numToStrEN;
7 |
8 | public class NumberUtilNumToStrENTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | System.out.print("Input a number:");
15 | int n = kb.nextInt();
16 |
17 | for (int i = 0; i < n; ++i) {
18 | long val = r.nextLong();
19 |
20 | System.out.printf("%d -> ", val);
21 | System.out.printf("(%s)%n", numToStrEN(val));
22 | }
23 | long a = 0;
24 | System.out.printf("%d -> ", 0);
25 | System.out.printf("(%s)%n", numToStrEN(0));
26 |
27 | a = -109;
28 | System.out.printf("%d -> ", a);
29 | System.out.printf("(%s)%n", numToStrEN(a));
30 |
31 | a = 1923;
32 | System.out.printf("%d -> ", a);
33 | System.out.printf("(%s)%n", numToStrEN(a));
34 | a = 3923;
35 | System.out.printf("%d -> ", a);
36 | System.out.printf("(%s)%n", numToStrEN(a));
37 |
38 | a = -1;
39 | System.out.printf("%d -> ", a);
40 | System.out.printf("(%s)%n", numToStrEN(a));
41 |
42 | a = 1_000_001;
43 | System.out.printf("%d -> ", a);
44 | System.out.printf("(%s)%n", numToStrEN(a));
45 |
46 | a = 1_001;
47 | System.out.printf("%d -> ", a);
48 | System.out.printf("(%s)%n", numToStrEN(a));
49 |
50 | a = 1_000_000_000_001L;
51 | System.out.printf("%d -> ", a);
52 | System.out.printf("(%s)%n", numToStrEN(a));
53 | }
54 |
55 | public static void main(String[] args)
56 | {
57 | run();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/numeric/test/NumberUtilNumToStrTRTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.numeric.test;
2 |
3 | import java.util.Random;
4 | import java.util.Scanner;
5 |
6 | import static org.csystem.util.numeric.NumberUtil.numToStrTR;
7 |
8 | public class NumberUtilNumToStrTRTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random r = new Random();
13 |
14 | System.out.print("Bir sayı giriniz:");
15 | int n = kb.nextInt();
16 |
17 | for (int i = 0; i < n; ++i) {
18 | long val = r.nextLong();
19 |
20 | System.out.printf("%d -> ", val);
21 | System.out.printf("(%s)%n", numToStrTR(val));
22 | }
23 | long a = 0;
24 | System.out.printf("%d -> ", 0);
25 | System.out.printf("(%s)%n", numToStrTR(0));
26 |
27 | a = -109;
28 | System.out.printf("%d -> ", a);
29 | System.out.printf("(%s)%n", numToStrTR(a));
30 |
31 | a = 1923;
32 | System.out.printf("%d -> ", a);
33 | System.out.printf("(%s)%n", numToStrTR(a));
34 | a = 3923;
35 | System.out.printf("%d -> ", a);
36 | System.out.printf("(%s)%n", numToStrTR(a));
37 |
38 | a = -1;
39 | System.out.printf("%d -> ", a);
40 | System.out.printf("(%s)%n", numToStrTR(a));
41 |
42 | a = 1_000_001;
43 | System.out.printf("%d -> ", a);
44 | System.out.printf("(%s)%n", numToStrTR(a));
45 |
46 | a = 1_001;
47 | System.out.printf("%d -> ", a);
48 | System.out.printf("(%s)%n", numToStrTR(a));
49 |
50 | a = 1_000_000_000_001L;
51 | System.out.printf("%d -> ", a);
52 | System.out.printf("(%s)%n", numToStrTR(a));
53 | }
54 |
55 | public static void main(String[] args)
56 | {
57 | run();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/random/IRandomGeneratorFactory.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.random;
2 |
3 | import java.util.random.RandomGenerator;
4 |
5 | /**
6 | * RIRandomGeneratorFactory interface
7 | * Last Update: 20th May 2025
8 | * @author Java-Jan-2024 Group
9 | */
10 | public interface IRandomGeneratorFactory {
11 | RandomGenerator create();
12 | }
13 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/random/RandomGeneratorAlgorithm.java:
--------------------------------------------------------------------------------
1 | package org.csystem.util.random;
2 |
3 | import java.security.SecureRandom;
4 | import java.util.concurrent.ThreadLocalRandom;
5 | import java.util.random.RandomGenerator;
6 |
7 | /**
8 | * RandomGeneratorAlgorithm enum class
9 | * Last Update: 20th May 2025
10 | * @author Java-Jan-2024 Group
11 | */
12 | public enum RandomGeneratorAlgorithm implements IRandomGeneratorFactory {
13 | L128X1024_MIX_RANDOM("L128X1024MixRandom"), L128X128_MIX_RANDOM("L128X128MixRandom"), L128X256_MIX_RANDOM("L128X256MixRandom"),
14 | L32X64_MIX_RANDOM("L32X64MixRandom"), L64X1024MIX_RANDOM("L64X1024MixRandom"), L64X128_MIX_RANDOM("L64X128MixRandom"),
15 | L64X128_STAR_STAR_RANDOM("L64X128StarStarRandom"), L64X256_MIX_RANDOM("L64X256MixRandom"), RANDOM("Random"),
16 | XOROSHIRO128_PLUS_PLUS("Xoroshiro128PlusPlus"), XOROSHIRO256_PLUS_PLUS("Xoshiro256PlusPlus"),
17 | SPLITTABLE_RANDOM("SplittableRandom"), THREAD_LOCAL_RANDOM("ThreadLocalRandom") {
18 | public RandomGenerator create()
19 | {
20 | return ThreadLocalRandom.current();
21 | }
22 | },
23 | SECURE_RANDOM("SecureRandom") {
24 | public RandomGenerator create()
25 | {
26 | return new SecureRandom();
27 | }
28 | };
29 |
30 | private final String m_name;
31 |
32 | RandomGeneratorAlgorithm(String name)
33 | {
34 | m_name = name;
35 | }
36 |
37 | public String getName()
38 | {
39 | return m_name;
40 | }
41 |
42 | public RandomGenerator create()
43 | {
44 | return RandomGenerator.of(m_name);
45 | }
46 |
47 | //...
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/string/StringUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for string operations
3 | * Last Update: 3rd June 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.string;
7 |
8 | import java.util.ArrayList;
9 | import java.util.random.RandomGenerator;
10 |
11 | public final class StringUtil {
12 | private StringUtil()
13 | {
14 | }
15 |
16 | private static final String LETTERS_EN;
17 | private static final String LETTERS_TR;
18 | private static final String CAPITAL_LETTERS_EN;
19 | private static final String CAPITAL_LETTERS_TR;
20 | private static final String ALL_LETTERS_EN;
21 | private static final String ALL_LETTERS_TR;
22 |
23 | static {
24 | LETTERS_EN = "abcdefghijklmnopqrstuvwxyz";
25 | LETTERS_TR = "abcçdefgğhıijklmnoöprsştuüvyz";
26 | CAPITAL_LETTERS_EN = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
27 | CAPITAL_LETTERS_TR = "ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ";
28 | ALL_LETTERS_EN = LETTERS_EN + CAPITAL_LETTERS_EN;
29 | ALL_LETTERS_TR = LETTERS_TR + CAPITAL_LETTERS_TR;
30 | }
31 |
32 | public static String capitalize(String s)
33 | {
34 | return s.isEmpty() ? s : Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase();
35 | }
36 |
37 | public static CharSequence changeCase(CharSequence charSequence)
38 | {
39 | StringBuilder sb = new StringBuilder(charSequence);
40 |
41 | for (int i = 0; i < charSequence.length(); ++i) {
42 | char c = charSequence.charAt(i);
43 |
44 | sb.setCharAt(i, Character.isLowerCase(c) ? Character.toUpperCase(c) : Character.toLowerCase(c));
45 | }
46 |
47 | return sb.toString();
48 | }
49 |
50 |
51 | public static int countString(String s1, String s2)
52 | {
53 | int count = 0;
54 |
55 | for (int i = 0; (i = s1.indexOf(s2, i)) != -1; ++i, ++count)
56 | ;
57 |
58 | return count;
59 | }
60 |
61 | public static String generateRandomText(RandomGenerator randomGenerator, int count, CharSequence charSequence)
62 | {
63 | char [] c = new char[count];
64 |
65 | for (int i = 0; i < count; ++i)
66 | c[i] = charSequence.charAt(randomGenerator.nextInt(charSequence.length()));
67 |
68 | return String.valueOf(c);
69 | }
70 |
71 | public static String generateRandomTextEN(RandomGenerator randomGenerator, int count)
72 | {
73 | return generateRandomText(randomGenerator, count, ALL_LETTERS_EN);
74 | }
75 |
76 | public static String generateRandomTextTR(RandomGenerator randomGenerator, int count)
77 | {
78 | return generateRandomText(randomGenerator, count, ALL_LETTERS_TR);
79 | }
80 |
81 | public static String [] generateRandomTexts(RandomGenerator randomGenerator, int count, int origin, int bound, CharSequence charSequence)
82 | {
83 | String [] str = new String[count];
84 |
85 | for (int i = 0; i < count; ++i)
86 | str[i] = generateRandomText(randomGenerator, randomGenerator.nextInt(origin, bound), charSequence);
87 |
88 | return str;
89 | }
90 |
91 | public static String [] generateRandomTextsEN(RandomGenerator randomGenerator, int count, int origin, int bound)
92 | {
93 | return generateRandomTexts(randomGenerator, count, origin, bound, ALL_LETTERS_EN);
94 | }
95 |
96 | public static String [] generateRandomTextsTR(RandomGenerator randomGenerator, int count, int origin, int bound)
97 | {
98 | return generateRandomTexts(randomGenerator, count, origin, bound, ALL_LETTERS_TR);
99 | }
100 |
101 | public static boolean isPalindrome(CharSequence charSequence)
102 | {
103 | int left = 0;
104 | int right = charSequence.length() - 1;
105 |
106 | while (left < right) {
107 | char cLeft = charSequence.charAt(left);
108 |
109 | if (!Character.isLetter(cLeft)) {
110 | ++left;
111 | continue;
112 | }
113 |
114 | char cRight = charSequence.charAt(right);
115 |
116 | if (!Character.isLetter(cRight)) {
117 | --right;
118 | continue;
119 | }
120 |
121 | if (Character.toLowerCase(cLeft) != Character.toLowerCase(cRight))
122 | return false;
123 |
124 | ++left;
125 | --right;
126 | }
127 |
128 | return true;
129 | }
130 |
131 |
132 | public static boolean isPangram(String s, String alphabet)
133 | {
134 | for (int i = 0; i < alphabet.length(); ++i)
135 | if (s.indexOf(alphabet.charAt(i)) == -1)
136 | return false;
137 |
138 | return true;
139 | }
140 |
141 |
142 | public static boolean isPangramEN(String s)
143 | {
144 | return isPangram(s.toLowerCase(), LETTERS_EN);
145 | }
146 |
147 | public static boolean isPangramTR(String s)
148 | {
149 | return isPangram(s.toLowerCase(), LETTERS_TR);
150 | }
151 |
152 |
153 | public static String join(ArrayList texts, CharSequence delimiter)
154 | {
155 | StringBuilder sb = new StringBuilder();
156 |
157 | for (String s : texts)
158 | sb.append(s).append(delimiter);
159 |
160 | return sb.substring(0, sb.length() - delimiter.length());
161 | }
162 |
163 | public static String join(ArrayList texts, char delimiter)
164 | {
165 | return join(texts, String.valueOf(delimiter));
166 | }
167 |
168 | public static String join(String [] s, CharSequence delimiter)
169 | {
170 | StringBuilder sb = new StringBuilder();
171 |
172 | for (String str : s)
173 | sb.append(str).append(delimiter);
174 |
175 | return sb.substring(0, sb.length() - delimiter.length());
176 | }
177 |
178 | public static String join(String [] s, char delimiter)
179 | {
180 | return join(s, String.valueOf(delimiter));
181 | }
182 |
183 | public static String padLeading(String s, int n, char ch)
184 | {
185 | int len = s.length();
186 |
187 | return len < n ? String.valueOf(ch).repeat(n - len) + s : s;
188 | }
189 |
190 | public static String padLeading(String s, int n)
191 | {
192 | return padLeading(s, n, ' ');
193 | }
194 |
195 | public static String padTrailing(String s, int n, char ch)
196 | {
197 | int len = s.length();
198 |
199 | return len < n ? s + String.valueOf(ch).repeat(n - len) : s;
200 | }
201 |
202 | public static String padTrailing(String s, int n)
203 | {
204 | return padTrailing(s, n, ' ');
205 | }
206 |
207 | public static String reverse(String s)
208 | {
209 | return new StringBuilder(s).reverse().toString();
210 | }
211 |
212 | public static String [] split(String s, CharSequence delimiters)
213 | {
214 | return split(s, delimiters, true);
215 | }
216 |
217 | public static String [] split(String s, CharSequence delimiters, boolean removeEmptyEntries)
218 | {
219 | StringBuilder pattern = new StringBuilder("[");
220 |
221 | for (int i = 0; i < delimiters.length(); ++i) {
222 | char c = delimiters.charAt(i);
223 |
224 | if (c == '[' || c == ']')
225 | pattern.append('\\');
226 |
227 | pattern.append(c);
228 | }
229 |
230 | pattern.append(']');
231 |
232 | if (removeEmptyEntries)
233 | pattern.append("+");
234 |
235 | return s.split(pattern.toString());
236 | }
237 | }
238 |
--------------------------------------------------------------------------------
/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 | java.util.Scanner kb = new java.util.Scanner(System.in);
9 |
10 | while (true) {
11 | System.out.print("Input string:");
12 | String s = kb.nextLine();
13 |
14 | System.out.printf("%s%n", StringUtil.changeCase(s));
15 |
16 | if ("exit".equals(s))
17 | break;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/string/test/StringUtilJoinTest.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 StringUtilJoinTest {
9 | public static void run()
10 | {
11 | Scanner kb = new Scanner(System.in);
12 | Random random = new Random();
13 |
14 | System.out.print("Bir sayı giriniz:");
15 | String [] s = StringUtil.generateRandomTextsTR(random, kb.nextInt(), 5, 16);
16 |
17 | System.out.printf("(%s)", StringUtil.join(s, "--"));
18 | }
19 |
20 | public static void main(String[] args)
21 | {
22 | run();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/util/thread/ThreadUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility class for thread operations
3 | * Last Update:10th December 2024
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.util.thread;
7 |
8 | import java.util.concurrent.TimeUnit;
9 |
10 | public final class ThreadUtil {
11 | private ThreadUtil()
12 | {
13 | }
14 |
15 | public static void sleep(long milliseconds)
16 | {
17 | try {
18 | TimeUnit.MILLISECONDS.sleep(milliseconds);
19 | }
20 | catch (InterruptedException ignore) {
21 |
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/wrapper/primitive/IntValue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Immutable class that wraps an int value
3 | * Last Update: 6th March 2025
4 | * @author Java-Jan-2024 Group
5 | */
6 | package org.csystem.wrapper.primitive;
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_DIFFERENCE = 128;
12 |
13 | private static final IntValue [] CACHE = new IntValue[CACHE_MAX - CACHE_MIN + 1];
14 | private final int m_value;
15 |
16 | private IntValue(int value)
17 | {
18 | m_value = value;
19 | }
20 |
21 | public static IntValue of(int value)
22 | {
23 | if (value < CACHE_MIN || value > CACHE_MAX)
24 | return new IntValue(value);
25 |
26 | if (CACHE[value + INDEX_DIFFERENCE] == null)
27 | CACHE[value + INDEX_DIFFERENCE] = new IntValue(value);
28 |
29 | return CACHE[value + INDEX_DIFFERENCE];
30 | }
31 |
32 | public int getValue()
33 | {
34 | return m_value;
35 | }
36 |
37 | public boolean equals(Object other)
38 | {
39 | return other instanceof IntValue i && i.m_value == m_value;
40 | }
41 |
42 | public String toString()
43 | {
44 | return String.valueOf(m_value);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/wrapper/primitive/test/IntValueInCacheTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.wrapper.primitive.test;
2 |
3 | import org.csystem.wrapper.primitive.IntValue;
4 |
5 | public class IntValueInCacheTest {
6 | public static void run()
7 | {
8 | int value = -128;
9 | IntValue intValue1 = IntValue.of(value);
10 | IntValue intValue2 = IntValue.of(value);
11 |
12 | System.out.println(intValue1 == intValue2 ? "Aynı nesne" : "Farklı nesneler");
13 | }
14 |
15 | public static void main(String[] args)
16 | {
17 | run();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Sample/src/org/csystem/wrapper/primitive/test/IntValueNotInCacheTest.java:
--------------------------------------------------------------------------------
1 | package org.csystem.wrapper.primitive.test;
2 |
3 | import org.csystem.wrapper.primitive.IntValue;
4 |
5 | public class IntValueNotInCacheTest {
6 | public static void run()
7 | {
8 | int value = -129;
9 | IntValue intValue1 = IntValue.of(value);
10 | IntValue intValue2 = IntValue.of(value);
11 |
12 | System.out.println(intValue1 == intValue2 ? "Aynı nesne" : "Farklı nesneler");
13 | }
14 |
15 | public static void main(String[] args)
16 | {
17 | run();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/src-console/arman/Sample.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/src/src-console/arman/Sample.class
--------------------------------------------------------------------------------
/src/src-console/arman/Sample.java:
--------------------------------------------------------------------------------
1 | package arman;
2 |
3 | class Sample {
4 | public static void main(String [] args)
5 | {
6 | System.out.println("Hello I am Arman!");
7 | }
8 | }
--------------------------------------------------------------------------------
/src/src-console/csd/App.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/src/src-console/csd/App.class
--------------------------------------------------------------------------------
/src/src-console/csd/App.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------------------------------------------------------------
2 |
3 | ----------------------------------------------------------------------------------------------------------------------*/
4 | package csd;
5 |
6 | class App {
7 | public static void main(String [] args)
8 | {
9 | System.out.println("Hello I am Tolga!");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/src-console/onur/Mample.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/src/src-console/onur/Mample.class
--------------------------------------------------------------------------------
/src/src-console/onur/Mample.java:
--------------------------------------------------------------------------------
1 | package onur;
2 |
3 | public class Mample {
4 | public static void main(String [] args)
5 | {
6 | System.out.println("Hello I am Onur!");
7 | }
8 | }
9 |
10 | public class Test {
11 | //...
12 | }
--------------------------------------------------------------------------------
/src/src-console/onur/Test.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oguzkaran/Java-Jan-2024/c834368fc1bd8c31e6acd3023576eadaa4a37d80/src/src-console/onur/Test.class
--------------------------------------------------------------------------------