-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
94 lines (80 loc) · 3.43 KB
/
Main.java
File metadata and controls
94 lines (80 loc) · 3.43 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
import java.util.Scanner;
// HESAP SINIFI (Musteri Bilgilerini ve Islemleri Tutar)
class BankAccount {
private String ownerName;
private double balance;
// Kurucu Metot (Constructor) - Hesap acildiginda calisir
public BankAccount(String name, double initialBalance) {
this.ownerName = name;
this.balance = initialBalance;
}
// Para Yatirma Fonksiyonu
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("✅ Basarili! Hesabiniza " + amount + " TL yatirildi.");
} else {
System.out.println("❌ Hata: Gecersiz miktar girdiniz!");
}
}
// Para Cekme Fonksiyonu
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.println("✅ Basarili! Hesabinizdan " + amount + " TL cekildi.");
} else {
System.out.println("❌ Hata: Yetersiz bakiye veya gecersiz miktar!");
}
}
// Bakiye Sorgulama
public void checkBalance() {
System.out.println("💰 Sayin " + ownerName + ", Guncel Bakiyeniz: " + balance + " TL");
}
}
// ANA SINIF (Programin Basladigi Yer)
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("==========================================");
System.out.println("=== JAVA BANKACILIK SISTEMINE HOS GELDINIZ ===");
System.out.println("==========================================");
System.out.print("Lutfen isminizi giriniz: ");
String name = scanner.nextLine();
// Yeni bir hesap aciyoruz (Baslangic bakiyesi 1000 TL hediye)
BankAccount myAccount = new BankAccount(name, 1000.0);
System.out.println("\nHos geldin " + name + "! Hesabin olusturuldu.");
boolean isRunning = true;
while (isRunning) {
System.out.println("\n--- Lutfen Bir Islem Secin ---");
System.out.println("1. Bakiye Sorgula");
System.out.println("2. Para Yatir");
System.out.println("3. Para Cek");
System.out.println("4. Cikis Yap");
System.out.print("Seciminiz (1-4): ");
// Kullanicinin sadece sayi girmesini bekliyoruz
if (scanner.hasNextInt()) {
int choice = scanner.nextInt();
if (choice == 1) {
myAccount.checkBalance();
} else if (choice == 2) {
System.out.print("Yatirilacak Miktar: ");
double amount = scanner.nextDouble();
myAccount.deposit(amount);
} else if (choice == 3) {
System.out.print("Cekilecek Miktar: ");
double amount = scanner.nextDouble();
myAccount.withdraw(amount);
} else if (choice == 4) {
System.out.println("\nBankamizi tercih ettiginiz icin tesekkurler! Iyi gunler dileriz. 👋");
isRunning = false;
} else {
System.out.println("⚠️ Lutfen 1 ile 4 arasinda bir sayi girin.");
}
} else {
System.out.println("⚠️ Hatali giris! Lutfen sadece sayi giriniz.");
scanner.next(); // Hatali girisi temizle
}
}
scanner.close();
}
}