Notes
![]() ![]() Notes - notes.io |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Scanner;
import model.Kitap;
import model.Odunc;
public class Kutuphane {
// burada kitap ve ödünç modellerimizi projeme ekliyoruz
static Kitap kitapModel = new Kitap();
static Odunc oduncModel = new Odunc();
// iki model için iki ayrı hashmap oluşturuyoruz
static HashMap kitaplistesi = new HashMap();
static HashMap Odunckitaplistesi = new HashMap();
// kullanıcı girişleri için scanner
static Scanner input = new Scanner(System.in);
// txt için file paketini kullanıyoruz
static File kitapFile = new File("kitapliste.txt");
static File oduncFile = new File("oduncliste.txt");
public static void main(String[] args) throws IOException {
// bu metot kullanıcı menüsüne gönderiyor.
secimYap();
}
static void secimYap() throws IOException {
int secim;
System.out.println("-----------------------------------------");
System.out.println("İşleminizi seçiniz: n1.Kitap ekleme"
+ "n2.Kitapları listeleme"
+ "n3.Ödünç verme"
+ "n4.Ödünç verilen kitapları listelemen5.çıkış");
System.out.println("-----------------------------------------");
secim = input.nextInt();
if (secim == 1) {
kitapEkle();
} else if (secim == 2) {
kitapListele();
} else if (secim == 3) {
oduncVer();
} else if (secim == 4) {
oduncListesi();
} else if (secim == 5) {
System.exit(0);
} else {
secimYap();
}
}
static void kitapEkle() throws IOException {
System.out.print("kitabın numarasını giriniz:");
int key = input.nextInt();
// kitap modeline atama yapıyoruz
kitapModel.setKitapNo(key);
// eklenecek kitap listede var mı kontrol ediyoruz
if (aynisiVarMi(key)) {
System.out.println(key + " numaralı alan dolu.n"
+ "Tekrar numara giriniz.");
kitapEkle();
}
// kitap yoksa ekleme işlemine devam ediyoruz
System.out.print("kitabın adını girniz:");
String value = input.next();
kitapModel.setKitapAdi(value);
// hash map e ekleme yapıyoruz
kitaplistesi.put(kitapModel.getKitapNo(), kitapModel.getKitapAdi());
// güncelle metoduna gidip listemizi txt ye yazdırıyoruz.
kitapGüncelle();
secimYap();
}
static void kitapListele() throws IOException {
// txt den okuma yaptırtıp konsola yazdırıyoruz
try (FileReader fileReaderKitap = new FileReader(kitapFile)) {
String line;
try (BufferedReader br = new BufferedReader(fileReaderKitap)) {
kitaplistesi.clear();
int satir = 0;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
secimYap();
}
static void oduncVer() throws IOException {
System.out.print("Ödünç verilecek kitabın numarasını giriniz:");
int oduncNo = input.nextInt();
// yine kitap var mı diye kontrol ediyoruz.
if (!aynisiVarMi(oduncNo)) {
System.out.println("Aradığınız kitap listede bulunmamaktadır.n"
+ "Lütfen tekrar numara girişi yapınız.");
}
// odunc map ine ekleme yapıyoruz.
Odunckitaplistesi.put(oduncNo, kitaplistesi.get(oduncNo));
// kitap modeldeki kitabın alanını ödünç verildi olarak güncelliyoruz.
kitapModel.setKitapNo(oduncNo);
kitapModel.setKitapAdi("ÖDÜNÇ VERİLDİ");
kitaplistesi.replace(oduncNo, "ÖDÜNÇ VERİLDİ");
// txt leri güncelliyoruz.
oduncKitapGuncelle();
kitapGüncelle();
secimYap();
}
static void oduncListesi() throws IOException {
Date zaman = new Date();
for (int i = 0; i < 100; i++) {
// boş alanları atlıyoruz
if (bosMu(i, Odunckitaplistesi)) {
} else {
System.out.println((i + 1) + "#" + Odunckitaplistesi.get(i) + "tt"
+ zaman.getDate() + "/" + (zaman.getMonth() + 1) + "/" + (zaman.getYear() + 1900));
}
}
System.out.println("-----------------------------------------");
secimYap();
}
static void kitapGüncelle() throws IOException {
if (!kitapFile.exists()) {
kitapFile.createNewFile();
}
FileWriter fileWriterKitap = new FileWriter(kitapFile, false);
BufferedWriter bWriterKitap = new BufferedWriter(fileWriterKitap);
// istenilen formatta dosyaya yazma işlemi yapılıyor.
try {
for (int i = 1; i < 100; i++) {
bWriterKitap.write(i + "#" + kitaplistesi.get(i));
bWriterKitap.newLine();
}
bWriterKitap.close();
System.out.println("Dosyaya yazma işlemi başarı ile sonuçlandı..");
} catch (Exception e) {
System.out.println("Kitap eklenirken bir hata ile karşılaşıldı...");
}
bWriterKitap.close();
secimYap();
}
static void oduncKitapGuncelle() throws IOException {
if (!oduncFile.exists()) {
oduncFile.createNewFile();
}
FileWriter fileWriterOdunc = new FileWriter(oduncFile, false);
BufferedWriter bWriterOdunc = new BufferedWriter(fileWriterOdunc);
// istenilen formatta dosyaya yazma işlemi yapılıyor.
try {
for (int i = 1; i < 100; i++) {
bWriterOdunc.write(i + "#" + Odunckitaplistesi.get(i));
bWriterOdunc.newLine();
}
bWriterOdunc.close();
System.out.println("Dosyaya yazma işlemi başarı ile sonuçlandı..");
} catch (Exception e) {
System.out.println("Ödünç eklenirken bir hata ile karşılaşıldı...");
}
bWriterOdunc.close();
secimYap();
}
static boolean aynisiVarMi(int no) {
if (kitaplistesi.get(no) == null) {
return false;
}
return true;
}
static boolean bosMu(int sayi, HashMap map) {
if (map.get(sayi) == null) {
return true;
}
return false;
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team