This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.java
209 lines (206 loc) · 5.86 KB
/
Main.java
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
package ASD;
import java.util.*;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
// 1. Al'Ravie Mutiar Mahesa/205150200111041
// 2. Arundaon Ramadhani Yudistira/205150200111031
// 3. Gabrielle Evan Farrel/205150201111033
// 4. Miftahul Ihsan/205150201111034
class masuk{
static QueueArray tunggu;
static QueueLinkedList antri;
static int ukuran;
String nama;
int usia, tensi;
masuk(){
tunggu = new QueueArray();
}
public void initUkuran(int ukuran) {
antri=new QueueLinkedList(ukuran);
}
public void baru(String nama, int usia, int tensi) {
this.nama=nama;
this.usia=usia;
this.tensi=tensi;
//buat cek masuk ke baris mana
if (!checkIsBolehVaksin()){
System.out.println(tolakPasien());
}else if (antri.learn.size!=antri.maxLength){
antri.enqueue(this.nama,this.usia,this.tensi);
System.out.println(antrePasien()); //45 42 | 60
antri.checkPriority();
}else if (this.usia>=60){
antri.lansiaDarurat(this.nama,this.usia,this.tensi,tunggu);
}else{
tunggu.enqueue(this.nama,this.usia,this.tensi);
System.out.println(tungguPasien());
}
}
public void selesai(int N) throws Exception {
if (!antri.isEmpty()) {
for (int i = 0; i < N; i++) {
if (antri.index!=0){
System.out.print(" "+antri.learn.head.data);
antri.dequeue();
}else {
System.out.print(" "+ tunggu.dequeue());
}
}
System.out.println();
while (antri.checkBangkuKosong()&&tunggu.itemCount!=0){
antri.bangkuKosong();
}
}
}
//buat STRING_NAMA
public void selesai(String x) throws Exception {
if (!antri.isEmpty()) {
antri.selesaiByNama(x);
if (antri.checkBangkuKosong()&&tunggu.itemCount!=0){
antri.bangkuKosong();
}
System.out.println("SELESAI_VAKSIN"+" "+x);//print klo dah keluar
}else{
System.out.println("ANTRE KOSONG");
}
}
public void status() {
// CONTOH RETURN
//DAFTAR_ANTRE Ana^BUKAN_LANSIA^110 Caca^BUKAN_LANSIA^140
// DAFTAR_TUNGGU Dodo^BUKAN_LANSIA^120
// KASUS KOSONG
// Jika Queue (Ruang Antre atau Daftar Tunggu) kosong, cukup
// cetak "-" . Contoh:
// DAFTAR_ ANTRE <spasi> -
// DAFTAR_TUNGGU <spasi> -
String daftarAntre = "DAFTAR_ANTRE ";
if(masuk.antri.isEmpty()){
daftarAntre+="-";
}
else{
for(int i = 0; i<antri.index;i++){
daftarAntre+=antri.learn.getNamaByIndex(i)+"^"+(antri.usia[i]>=60?"LANSIA":"BUKAN_LANSIA")+"^"+antri.tensi[i]+" ";
}
}
String daftarTunggu = "DAFTAR_TUNGGU ";
if(masuk.tunggu.isEmpty()){
daftarTunggu+="-";
}
else{
for(int i =0;i<masuk.tunggu.itemCount;i++){
daftarTunggu+=tunggu.learn[i]+"^"+(tunggu.umur[i]>=60?"LANSIA":"BUKAN_LANSIA")+"^"+tunggu.tensi[i]+" ";
}
}
System.out.println(daftarAntre+"\n"+daftarTunggu) ;
}
public void ukuran(int ukuran) {
System.out.println("SUKSES UBAH " + antri.maxLength + " " + ukuran);
if (antri.maxLength<ukuran){
antri.maxLength=ukuran;
antri.arrayDoubling(antri.maxLength);
}else {
antri.maxLength=ukuran;
antri.arrayDecreasing(antri.maxLength);
}
}
public void skip(String nama) throws Exception {
antri.skip(nama);
System.out.println("SKIP SUKSES");
}
// check kondisi orang yang masuk
// pertama boleh vaksn atau engga
// kedua lansia atau engga
public boolean checkIsBolehVaksin(){
return this.tensi<180;
}
public boolean checkIsLansia(){
return this.usia>=60;
}
// String buat tulisan2
// pertama tulisan vaksin
// kedua tulisan lansia
// ketiga tulisan pasien ditolak
// keempat tulisan pasien antri
// kelima tulisan pasien tunggu
public String tulisanTensi(){
return (this.checkIsBolehVaksin() ? "TENSI_BOLEH_DIVAKSIN":"TENSI_TIDAKBOLEH_DIVAKSIN");
}
public String tulisanLansia(){
return (this.checkIsLansia()?"LANSIA":"BUKAN_LANSIA");
}
public String tolakPasien(){
return "TOLAK"+" "+this.nama+" "+tulisanLansia()+" "+tulisanTensi();
}
public String antrePasien(){
return "ANTRE"+" "+this.nama+" "+tulisanLansia();
}
public String tungguPasien(){
return "TUNGGU"+" "+this.nama+" "+tulisanLansia();
}
}
public class Main {
public static void main(String[] args) throws Exception {
masuk learn=new masuk();
Scanner scan=new Scanner(System.in);
String alamat;
while(true) {
System.out.println("Mohon masukkan direktori file txt anda secara lengkap");
System.out.println("contoh = /home/user/Documents/tes.txt");
String lokasi=scan.nextLine();
Path jalur= Paths.get(lokasi);
if(Files.exists(jalur)==true) {
alamat=jalur.toString();
System.out.println("direktori benar");
break;
}else {
System.out.println("direktori salah, mohon ketik kembali");
continue;
}
}
scan.close();
FileReader fr = new FileReader(alamat);
Scanner inFile = new Scanner(fr);
while (inFile.hasNext())
{
String line = inFile.nextLine();
String[] words = line.trim().split(" ");
if(words[0].length()<=3) {
int ukuran=Integer.parseInt(words[0]);
learn.initUkuran(ukuran);
}else if(words[0].equalsIgnoreCase("Baru")) {
String nama=words[1];
int usia=Integer.parseInt(words[2]);
int tensi=Integer.parseInt(words[3]);
learn.baru(nama, usia, tensi);
}else if(words[0].equalsIgnoreCase("status")) {
learn.status();
}else if(words[0].equalsIgnoreCase("selesai")) {
if(words[1].length()<=2) {
int index=Integer.parseInt(words[1]);
System.out.print("SELESAI_VAKSIN");
try{
for (int i =0;i<index;i++){
learn.selesai(index);
}
}catch(Exception e) {
System.err.println(e.getMessage());
}
}else if(words[1].length()>=3) {
String nama=words[1];
learn.selesai(nama);
}
}else if (words[0].equalsIgnoreCase("selesai_nama")){
learn.selesai(words[1]);
}else if(words[0].equalsIgnoreCase("ukuran")) {
int ukuran=Integer.parseInt(words[1]);
learn.ukuran(ukuran);
}else if(words[0].equalsIgnoreCase("skip")) {
String nama=words[1];
learn.skip(nama);
}
}
inFile.close();
}
}