-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
220 lines (165 loc) · 6.39 KB
/
Main.java
File metadata and controls
220 lines (165 loc) · 6.39 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
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.UUID;
// Ozel Hata Yonetimi
class KuantumCokusuException extends RuntimeException {
public KuantumCokusuException(String id) {
super("DIKKAT!" + id + "ID'li nesne aktiflesti! PATLAMA GERCEKLESIYOR!");
}
}
// Arayuz
interface IKritik {
void acilDurumSogutmasi();
}
// Soyut Sinif
abstract class KuantumNesnesi {
protected String id;
protected double stabilite;
protected int tehlikeSeviyesi;
public KuantumNesnesi(String id, double stabilite, int tehlikeSeviyesi) {
this.id = id;
this.stabilite = stabilite;
this.tehlikeSeviyesi = tehlikeSeviyesi;
}
public String getId() { return id; }
// Kapsulleme
public void setStabilite (double value) {
if(value>100){
this.stabilite = 100;
}
else {
this.stabilite = value;
}
// Stabilite kontrolu
if(this.stabilite <= 0) {
throw new KuantumCokusuException((this.id));
}
}
public double getStabilite() {return stabilite;}
public abstract void analizEt();
public String durumBilgisi(){
// Virgulden sonra 2 basamak gostermek icin formatlama
return "ID: " + id + "| Stabilite : %" + String.format("%.2f",stabilite) +
"| Tehlike : " + tehlikeSeviyesi;
}
}
// Alt Siniflar
class VeriPaketi extends KuantumNesnesi {
public VeriPaketi(String id) {super(id, 100, 1);}
@Override
public void analizEt() {
setStabilite(getStabilite() -5);
System.out.println("Veri icerigi okundu.");
}
}
class KaranlikMadde extends KuantumNesnesi implements IKritik {
public KaranlikMadde(String id) {super(id,100,5);}
@Override
public void analizEt() {
setStabilite(getStabilite() + 50);
}
@Override
public void acilDurumSogutmasi() {
setStabilite(getStabilite() + 50);
System.out.println(id + " sogutuldu.");
}
}
class AntiMadde extends KuantumNesnesi implements IKritik{
public AntiMadde(String id) { super(id,100, 10);}
@Override
public void analizEt() {
setStabilite(getStabilite() - 25);
System.out.println("Evrenin dokusu titriyor ...");
}
@Override
public void acilDurumSogutmasi() {
setStabilite(getStabilite() + 50);
System.out.println(id + " sogutuldu.");
}
}
// Ana Program
public class Main {
public static void main(String[] args) {
List<KuantumNesnesi> envanter = new ArrayList<>();
Scanner scanner = new Scanner(System.in); // System.in
Random rnd = new Random();
try{
while(true) {
System.out.println("\n--- KUANTUM AMBARI KONTROL PANELİ ---");
System.out.println("1. Yeni Nesne Ekle");
System.out.println("2. Tüm Envanteri Listele");
System.out.println("3. Nesneyi Analiz Et");
System.out.println("4. Acil Durum Soğutmasi Yap");
System.out.println("5. Cikis");
System.out.print("Seçiminiz: ");
String secim = scanner.next();
if(secim.equals("1")) {
int tur = rnd.nextInt(3); // 0, 1 veya 2 uretir
// Rastgele ID olusturma (UUID)
String uuid = UUID.randomUUID().toString().substring(0,5).toUpperCase();
if(tur == 0) {
VeriPaketi vp = new VeriPaketi("VP-" + uuid);
envanter.add(vp);
System.out.println("EKLENDI -> " + vp.getId() + "(VeriPaketi)");
}
else if(tur == 1) {
KaranlikMadde km = new KaranlikMadde("KM-" + uuid);
envanter.add(km);
System.out.println("EKLENDI -> " + km.getId() + "(KaranlikMadde)");
}
else {
AntiMadde am = new AntiMadde("AM-" + uuid);
envanter.add(am);
System.out.println("EKLENDI - > " + am.getId() + "(AntiMadde");
}
}
else if(secim.equals("2")){
for(KuantumNesnesi nesne : envanter) {
System.out.println(nesne.durumBilgisi());
}
}
else if(secim.equals("3") || secim.equals("4")){
System.out.print("ID giriniz: ");
String id = scanner.next();
// Listede arama yapma
KuantumNesnesi hedef = null;
for(KuantumNesnesi n: envanter) {
if(n.getId().equals(id)) {
hedef = n;
break;
}
}
if(hedef !=null){
if(secim.equals("3")) {
hedef.analizEt();
}
else{
// Type analizi
if(hedef instanceof IKritik) {
((IKritik) hedef).acilDurumSogutmasi();
}
else{
System.out.println("HATA : Bu nesne sogutulamaz!");
}
}
}
else {
System.out.println("Bulunumadi");
}
}
else if (secim.equals("5")) {
break;
}
}
}
catch (KuantumCokusuException e) {
System.out.println("\n**************************************");
System.out.println("SİSTEM ÇÖKTÜ! TAHLİYE BAŞLATILIYOR...");
System.out.println(e.getMessage());
System.out.println("**************************************");
}
scanner.close();
}
}