-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkrs.java
More file actions
224 lines (194 loc) · 7.83 KB
/
Copy pathkrs.java
File metadata and controls
224 lines (194 loc) · 7.83 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import java.util.Scanner;
public class krs {
static String[][] KRS = new String[0][5]; // Array kosong untuk memulai
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println();
System.out.println("===Sistem Pemantauan KRS Mahasiswa===");
System.out.println("1. Tambah Data KRS");
System.out.println("2. Tampil Daftar KRS Mahasiswa");
System.out.println("3. Analisis Data KRS");
System.out.println("4. Keluar");
System.out.print("Pilih menu: ");
int pilih = sc.nextInt();
sc.nextLine(); // Menghilangkan newline setelah input angka
switch (pilih) {
case 1:
System.out.println();
System.out.println("--- Tambah Data KRS ---");
tambah(sc);
break;
case 2:
System.out.println();
System.out.println("--- Tampilkan Daftar KRS Mahasiswa ---");
System.out.print("Masukkan NIM yang dicari: ");
int nim = sc.nextInt();
print(nim);
break;
case 3:
System.out.println();
System.out.println("--- Analisis Data KRS ---");
System.out.println("Jumlah mahasiswa yang mengambil SKS kurang dari 20: " + analisis());
break;
case 4:
System.out.println("Terima Kasih!");
return; // Keluar dari program
default:
System.out.println("Pilihan tidak valid!");
break;
}
}
}
public static void tambah(Scanner sc) {
System.out.print("Nama mahasiswa: ");
String nama = sc.nextLine();
System.out.print("NIM: ");
int nim = sc.nextInt();
sc.nextLine();
char next;
int currentTotalSKS = totalSKS(nim); // Menghitung total SKS awal
do {
if (currentTotalSKS >= 24) {
System.out.println("Jumlah SKS sudah mencapai batas maksimum 24.");
break;
}
pindah();
KRS[KRS.length - 1][0] = nama;
String nimHuruf = String.valueOf(nim);
KRS[KRS.length - 1][1] = nimHuruf;
System.out.print("Kode matkul: ");
String kodeMK = sc.nextLine();
KRS[KRS.length - 1][2] = kodeMK;
System.out.print("Nama matkul: ");
String namaMK = sc.nextLine();
KRS[KRS.length - 1][3] = namaMK;
while (true) {
System.out.print("Jumlah SKS (1-3): ");
int input = sc.nextInt();
int sks = input;
if (sks < 1 || sks > 3) {
System.out.println("Jumlah SKS harus antara 1 dan 3. Silakan input kembali.");
continue;
}
if (totalSKSPerMatkul(nim, kodeMK, sks) > 3) {
System.out.println("Jumlah SKS matkul ini sudah > 3. Input tidak valid.");
KRS = hapusDataTerakhir();
break;
}
if (currentTotalSKS + sks > 24) {
System.out.println("Jumlah SKS total melebihi 24. Input tidak valid.");
KRS = hapusDataTerakhir();
break;
}
KRS[KRS.length - 1][4] = String.valueOf(input); // Simpan SKS jika valid
System.out.println("Data mata kuliah berhasil ditambahkan.");
currentTotalSKS += sks; // Tambahkan ke total SKS
break;
}
if (currentTotalSKS >= 24) {
System.out.println("Jumlah SKS sudah mencapai batas maksimum 24.");
break;
}
System.out.print("Tambah matkul lain? (y/n): ");
next = sc.next().charAt(0);
sc.nextLine();
} while (next == 'y' || next == 'Y');
System.out.println("total SKS yang diambil: " + totalSKS(nim));
}
public static String[][] hapusDataTerakhir() {
String[][] temp = new String[KRS.length - 1][5];
for (int i = 0; i < KRS.length - 1; i++) {
temp[i] = KRS[i];
}
return KRS = temp;
}
public static void pindah() {
// Salin isi array KRS lama ke array temp
String[][] temp = new String[KRS.length][5];
for (int i = 0; i < KRS.length; i++) {
for (int j = 0; j < KRS[0].length; j++) {
temp[i][j] = KRS[i][j]; // Menyalin data dari KRS lama ke temp
}
}
// Perbesar ukuran array KRS
KRS = new String[temp.length + 1][5];
// Salin kembali isi array temp ke array KRS yang baru
for (int i = 0; i < temp.length; i++) {
for (int j = 0; j < temp[i].length; j++) {
KRS[i][j] = temp[i][j]; // Menyalin kembali data ke KRS yang baru
}
}
}
public static int totalSKS(int nim) {
int totalSKS = 0;
String nimHuruf = String.valueOf(nim);
for (int i = 0; i < KRS.length; i++) {
if (KRS[i][1].equalsIgnoreCase(nimHuruf)) {
totalSKS += Integer.parseInt(KRS[i][4]);
}
}
return totalSKS;
}
public static int totalSKSPerMatkul(int nim, String kodeMK, int sks) {
int totalSKS = 0;
String nimHuruf = String.valueOf(nim);
for (int i = 0; i < KRS.length; i++) {
if (KRS[i][1].equalsIgnoreCase(nimHuruf) && KRS[i][2].equalsIgnoreCase(kodeMK)) {
if (KRS[i][4] == null) {
totalSKS += sks;
} else {
totalSKS += Integer.parseInt(KRS[i][4]);
}
}
}
return totalSKS;
}
public static void print(int nim) {
String nimHuruf = String.valueOf(nim);
if (KRS.length == 0) {
System.out.println("Data KRS kosong.");
return;
}
System.out.println("Daftar KRS: ");
System.out.print("NIM \t\t" + "nama \t" + "\t\t" + "kode MK \t" + "nama matkul \t\t" + "SKS \t");
System.out.println();
for (int i = 0; i < KRS.length; i++) {
if (KRS[i][1].equalsIgnoreCase(nimHuruf)) {
for (int j = 1; j >= 0; j--) {
System.out.print(KRS[i][j] + "\t");
}
System.out.print("\t\t");
for (int j = 2; j < KRS[0].length; j++) {
if (j == 2) {
System.out.print(KRS[i][j] + "\t\t");
} else {
System.out.print(KRS[i][j] + "\t");
}
}
System.out.println();
}
}
System.out.println("total SKS: " + totalSKS(nim));
}
public static int analisis() {
int jumlahMhs = 0;
boolean sudahDiperiksa; // Variabel untuk menandakan apakah NIM sudah diperiksa
for (int i = 0; i < KRS.length; i++) {
String currentNIM = KRS[i][1];
sudahDiperiksa = false;
for (int j = 0; j < i; j++) {
if (KRS[j][1].equals(currentNIM)) {
sudahDiperiksa = true;
break;
}
}
if (!sudahDiperiksa) {
if (totalSKS(Integer.parseInt(currentNIM)) < 20) {
jumlahMhs++;
}
}
}
return jumlahMhs;
}
}