Skip to content

Commit b56ee67

Browse files
Add files via upload
1 parent 945965c commit b56ee67

22 files changed

+2046
-0
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*----------------------------------------------------------------------------------------------------------------------
2+
Time sınıfı ve test kodu
3+
----------------------------------------------------------------------------------------------------------------------*/
4+
package org.csystem.app;
5+
6+
import org.csystem.util.datetime.Time;
7+
8+
import java.util.Random;
9+
10+
class App {
11+
public static void main(String [] args)
12+
{
13+
Random r = new Random();
14+
15+
for (int i = 0; i < 10; ++i) {
16+
Time time = Time.randomTime(r);
17+
18+
System.out.println(time.toLongTimeString());
19+
}
20+
}
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package org.csystem.app.samples.commandpromptapp;
2+
3+
import org.csystem.util.StringUtil;
4+
5+
import java.util.Scanner;
6+
7+
public class CommandPrompt {
8+
private static final String [] COMMAND_STRINGS = {"length", "reverse", "upper", "lower", "change", "clear"};
9+
private String m_prompt;
10+
private final Scanner m_kb;
11+
12+
private static String getCommandByText(String text)
13+
{
14+
if (text.length() < 3)
15+
return "";
16+
17+
for (String s : COMMAND_STRINGS)
18+
if (s.startsWith(text))
19+
return s;
20+
21+
return "";
22+
}
23+
24+
private void lengthProc(String [] commandsStr)
25+
{
26+
if (commandsStr.length != 2) {
27+
System.out.println("length bir tane argüman almalıdır");
28+
return;
29+
}
30+
31+
System.out.println(commandsStr[1].length());
32+
}
33+
34+
private void reverseProc(String [] commandsStr)
35+
{
36+
if (commandsStr.length != 2) {
37+
System.out.println("revere bir tane argüman almalıdır");
38+
return;
39+
}
40+
41+
System.out.println(StringUtil.reverse(commandsStr[1]));
42+
}
43+
44+
private void upperProc(String [] commandsStr)
45+
{
46+
if (commandsStr.length != 2) {
47+
System.out.println("upper bir tane argüman almalıdır");
48+
return;
49+
}
50+
System.out.println(commandsStr[1].toUpperCase());
51+
}
52+
53+
private void lowerProc(String [] commandsStr)
54+
{
55+
if (commandsStr.length != 2) {
56+
System.out.println("lower bir tane argüman almalıdır");
57+
return;
58+
}
59+
System.out.println(commandsStr[1].toLowerCase());
60+
}
61+
62+
private void changeProc(String [] commandsStr)
63+
{
64+
if (commandsStr.length != 2) {
65+
System.out.println("change bir tane argüman almalıdır");
66+
return;
67+
}
68+
m_prompt = commandsStr[1];
69+
}
70+
71+
private void clearProc(String [] commandsStr)
72+
{
73+
for (int i = 0; i < 30; ++i)
74+
System.out.println();
75+
}
76+
77+
private void doWorkForCommand(String [] commandInfoStr)
78+
{
79+
switch (commandInfoStr[0]) {
80+
case "length":
81+
lengthProc(commandInfoStr);
82+
break;
83+
case "reverse":
84+
reverseProc(commandInfoStr);
85+
break;
86+
case "upper":
87+
upperProc(commandInfoStr);
88+
break;
89+
case "lower":
90+
lowerProc(commandInfoStr);
91+
break;
92+
case "change":
93+
changeProc(commandInfoStr);
94+
break;
95+
case "clear":
96+
clearProc(commandInfoStr);
97+
break;
98+
}
99+
}
100+
101+
private void parseCommand(String [] commandInfoStr)
102+
{
103+
String cmd = getCommandByText(commandInfoStr[0]);
104+
105+
if (!cmd.isEmpty()) {
106+
commandInfoStr[0] = cmd;
107+
doWorkForCommand(commandInfoStr);
108+
}
109+
else
110+
System.out.println("Geçersiz komut");
111+
}
112+
113+
public CommandPrompt(String p)
114+
{
115+
m_prompt = p;
116+
m_kb = new Scanner(System.in);
117+
}
118+
119+
public void run()
120+
{
121+
System.out.println("C ve Sistem Programcıları Derneği");
122+
System.out.println("Homework-013 sorusuna ilişkin bir iskelet");
123+
124+
for (;;) {
125+
System.out.print(m_prompt + ">");
126+
String cmd = m_kb.nextLine().trim();
127+
128+
if (cmd.equals("quit"))
129+
break;
130+
131+
parseCommand(cmd.split("[ \t]+"));
132+
}
133+
134+
System.out.println("C ve Sistem Programcıları Derneği");
135+
System.out.println("Tekrar yapıyor musunuz?");
136+
}
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.csystem.app.samples.commandpromptapp;
2+
3+
public class CommandPromptApp {
4+
private CommandPromptApp()
5+
{
6+
}
7+
8+
public static void run()
9+
{
10+
CommandPrompt commandPrompt = new CommandPrompt("CSD");
11+
12+
commandPrompt.run();
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.csystem.app.samples.dateapp;
2+
3+
public class DateUtil {
4+
public static int [] daysOfMonths = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
5+
6+
public static int getDayOfWeek(int day, int month, int year)
7+
{
8+
int dayOfYear;
9+
10+
dayOfYear = getDayOfYear(day, month, year);
11+
12+
if (dayOfYear == -1 || year < 1900)
13+
return -1;
14+
15+
for (int y = 1900; y < year; ++y)
16+
dayOfYear += isLeapYear(y) ? 366 : 365;
17+
18+
return dayOfYear % 7;
19+
}
20+
21+
public static int getDayOfYear(int day, int month, int year)
22+
{
23+
if (!isValidDate(day, month, year))
24+
return -1;
25+
26+
int dayOfYear = day;
27+
28+
for (int m = month - 1; m >= 1; --m)
29+
dayOfYear += daysOfMonths[m];
30+
31+
if (month > 2 && isLeapYear(year))
32+
++dayOfYear;
33+
34+
return dayOfYear;
35+
}
36+
37+
public static boolean isValidDate(int day, int month, int year)
38+
{
39+
if (day < 1 || day > 31 || month < 1 || month > 12)
40+
return false;
41+
42+
int days = month == 2 && isLeapYear(year) ? 29 : daysOfMonths[month];
43+
44+
return day <= days;
45+
}
46+
47+
public static boolean isLeapYear(int year)
48+
{
49+
return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*----------------------------------------------------------------------------------------------------------------------
2+
Sınıf çalışması: Parametresi ile aldığı int türden gün, ay ve yıl bilgilerine ilişkin tarihin aşağıdaki
3+
açıklamalara göre haftanın hangi gününe geldiğini döndüren getDayOfWeek metodunu yazınız.
4+
Açıklamalar:
5+
- Metot geçersiz bir tarih için -1 değerini döndürecektir.
6+
- Haftanın günü 1.1.1900 ile verilen tarih arasındaki gün sayısının 7 değerine modu alınarak bulunabilir
7+
- 7 değerine mod alındıktan sonra sıfır Pazar, 1 pazartesi, .., 6 cumartesi günü için
8+
elde edilecek değerdir
9+
- 1.1.1900' den önceki tarihler geçersiz kabul edilecektir
10+
----------------------------------------------------------------------------------------------------------------------*/
11+
package org.csystem.app.samples.dateapp;
12+
13+
public class DateUtilApp {
14+
public static String [] daysOfWeek = {"Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi"};
15+
public static String [] monthsTR = {"", "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran",
16+
"Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"};
17+
18+
public static String [] monthsEN = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
19+
20+
public static void displayTR(int day, int month, int year)
21+
{
22+
int dayOfWeek = DateUtil.getDayOfWeek(day, month, year);
23+
24+
if (dayOfWeek == -1) {
25+
System.out.println("Geçersiz tarih");
26+
return;
27+
}
28+
29+
System.out.printf("%02d %s %04d %s%n", day, monthsTR[month], year, daysOfWeek[dayOfWeek]);
30+
31+
if (dayOfWeek == 0 || dayOfWeek == 6)
32+
System.out.println("Bugün kurs var. Tekrar yaptınız mı?");
33+
else
34+
System.out.println("Kurs günü yaklaşıyor. Tekrar yapınız!!!!");
35+
}
36+
37+
public static void run()
38+
{
39+
java.util.Scanner kb = new java.util.Scanner(System.in);
40+
41+
for (;;) {
42+
System.out.print("Gün bilgisini giriniz:");
43+
int day = Integer.parseInt(kb.nextLine());
44+
45+
if (day == 0)
46+
break;
47+
48+
System.out.print("Ay bilgisini giriniz:");
49+
int month = Integer.parseInt(kb.nextLine());
50+
51+
System.out.print("Yıl bilgisini giriniz:");
52+
int year = Integer.parseInt(kb.nextLine());
53+
54+
displayTR(day, month, year);
55+
}
56+
}
57+
}
58+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package org.csystem.app.samples.examsimulationapp;
2+
3+
import org.csystem.util.ArrayUtil;
4+
5+
import java.util.Random;
6+
import java.util.Scanner;
7+
8+
public class ExamSimulation {
9+
private final String m_lectureName;
10+
private int [][] m_grades;
11+
private double [] m_averages;
12+
private double m_average;
13+
14+
private void findAverages()
15+
{
16+
int totalNumberOfStudents = 0;
17+
int totalGrades = 0;
18+
19+
for (int i = 0; i < m_grades.length; ++i) {
20+
int total = ArrayUtil.sum(m_grades[i]);
21+
22+
m_averages[i] = (double)total / m_grades[i].length;
23+
totalGrades += total;
24+
totalNumberOfStudents += m_grades[i].length;
25+
}
26+
27+
m_average = (double)totalGrades / totalNumberOfStudents;
28+
}
29+
30+
private void fillGrades()
31+
{
32+
Random r = new Random();
33+
Scanner kb = new Scanner(System.in);
34+
System.out.print("Şube sayısını giriniz:");
35+
m_grades = new int[Integer.parseInt(kb.nextLine())][];
36+
m_averages = new double[m_grades.length];
37+
38+
for (int i = 0; i < m_grades.length; ++i) {
39+
System.out.printf("%d. şube öğrenci sayısını giriniz:", i + 1);
40+
int count = Integer.parseInt(kb.nextLine());
41+
42+
m_grades[i] = ArrayUtil.getRandomArray(r, count, 0, 101);
43+
}
44+
}
45+
46+
public ExamSimulation(String name)
47+
{
48+
m_lectureName = name;
49+
}
50+
51+
public String getLectureName()
52+
{
53+
return m_lectureName;
54+
}
55+
56+
public int getGrade(int i, int k)
57+
{
58+
return m_grades[i][k];
59+
}
60+
61+
public double getAverage(int i)
62+
{
63+
return m_averages[i];
64+
}
65+
66+
public int getNumberOfClasses()
67+
{
68+
return m_averages.length;
69+
}
70+
71+
public int getNumberOfStudents(int i)
72+
{
73+
return m_grades[i].length;
74+
}
75+
76+
public double getAverage()
77+
{
78+
return m_average;
79+
}
80+
81+
public void run()
82+
{
83+
fillGrades();
84+
findAverages();
85+
}
86+
87+
public void displayGrades()
88+
{
89+
System.out.printf("%s dersi sınav notları:%n", m_lectureName);
90+
System.out.println("*************************************************************");
91+
for (int i = 0; i < m_grades.length; ++i) {
92+
System.out.printf("%d. şube notları:", i + 1);
93+
ArrayUtil.display(3, m_grades[i]);
94+
}
95+
System.out.println("*************************************************************");
96+
}
97+
98+
public void displayStatus()
99+
{
100+
displayGrades();
101+
102+
System.out.printf("%s dersi için ortalamalar%n", m_lectureName);
103+
System.out.println("*************************************************************");
104+
for (int i = 0; i < m_averages.length; ++i)
105+
System.out.printf("%d.şube not ortalaması:%f%n", i + 1, m_averages[i]);
106+
107+
System.out.printf("Okul ortalaması:%f%n", m_average);
108+
System.out.println("*************************************************************");
109+
}
110+
}

0 commit comments

Comments
 (0)