Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package projekt;
- import java.util.Scanner;
- import java.io.File;
- import java.io.*;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- public class Projekt {
- public static void main(String[] args)throws IOException{
- String opcja;
- Scanner odczyt = new Scanner(System.in);
- System.out.println("Witaj w programie bilbiotecznym. Masz do wyboru Dodawanie/Usuwanie/Sortowanie/Wyszukiwanie/Wyswietl");
- opcja = odczyt.nextLine();
- BufferedReader klawiatura = new BufferedReader(new InputStreamReader(System.in));
- BufferedReader przeglad = new BufferedReader(new InputStreamReader(System.in));
- BufferedReader chej = new BufferedReader(new FileReader("ksiazki.txt"));
- switch (opcja) {
- case "Dodawanie":
- String c;
- System.out.println("Podaj książki(Wpisz end po zakończonym wpisywaniu)" );
- try (PrintWriter zapis = new PrintWriter("ksiazki.txt"))
- {
- while(!("end".equals((c=odczyt.nextLine()))))zapis.println(c);
- }
- break;
- case "Usuwanie":
- System.out.println("Usuwanie");
- break;
- case "Sortowanie":
- System.out.println();
- System.out.println("Lista książek:");
- String przegladanie = "";
- while(przegladanie != null){
- przegladanie = chej.readLine();
- if(przegladanie != null)
- System.out.println(przegladanie);
- }
- System.out.println();
- break;
- case "Wyszukiwanie":
- System.out.println("Podaj książkę: ");
- String szukaj = klawiatura.readLine();
- String prze = przeglad.readLine();
- String[] x = prze.split(" ");
- while(!szukaj.equals(x[0]) && prze != null){
- prze = przeglad.readLine();
- if(prze != null)
- x = prze.split(" ");
- }
- if(prze == null)
- System.out.println("Nie ma takiej ksiazki");
- else
- System.out.println("Znaleziono ksiazke: " + x[0] + " " + x[1]);
- break;
- case "Wyswietl":
- File file = new File ("ksiazki.txt");
- Scanner in = new Scanner(file);
- while(in.hasNext())
- {
- System.out.println(in.nextLine());
- }
- break;
- case "koniec":
- System.out.println("koniec");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement