Advertisement
Guest User

halo

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. package projekt;
  2. import java.util.Scanner;
  3. import java.io.File;
  4. import java.io.*;
  5. import java.io.FileNotFoundException;
  6. import java.io.PrintWriter;
  7.  
  8. public class Projekt {
  9.     public static void main(String[] args)throws IOException{
  10.        String opcja;
  11.        Scanner odczyt =  new Scanner(System.in);
  12.        System.out.println("Witaj w programie bilbiotecznym. Masz do wyboru Dodawanie/Usuwanie/Sortowanie/Wyszukiwanie/Wyswietl");
  13.        opcja = odczyt.nextLine();
  14.        BufferedReader klawiatura = new BufferedReader(new InputStreamReader(System.in));
  15.        BufferedReader przeglad = new BufferedReader(new InputStreamReader(System.in));
  16.        BufferedReader chej = new BufferedReader(new FileReader("ksiazki.txt"));
  17.        
  18.         switch (opcja) {
  19.             case "Dodawanie":
  20.            
  21.                     String c;
  22.                     System.out.println("Podaj książki(Wpisz end po zakończonym wpisywaniu)" );
  23.                    
  24.          
  25.                     try (PrintWriter zapis = new PrintWriter("ksiazki.txt"))
  26.                     {
  27.                        while(!("end".equals((c=odczyt.nextLine()))))zapis.println(c);
  28.                        
  29.                     }
  30.                    
  31.             break;
  32.                
  33.             case "Usuwanie":
  34.                 System.out.println("Usuwanie");
  35.             break;
  36.                
  37.             case "Sortowanie":
  38.                
  39.                
  40.                 System.out.println();
  41.                 System.out.println("Lista książek:");
  42.                 String przegladanie = "";
  43.                 while(przegladanie != null){
  44.                     przegladanie = chej.readLine();
  45.                     if(przegladanie != null)
  46.                         System.out.println(przegladanie);
  47.                 }
  48.                 System.out.println();  
  49.             break;
  50.                
  51.             case "Wyszukiwanie":
  52.                 System.out.println("Podaj książkę: ");
  53.                 String szukaj = klawiatura.readLine();
  54.                String prze = przeglad.readLine();
  55.                
  56.                 String[] x = prze.split(" ");
  57.                
  58.                 while(!szukaj.equals(x[0]) && prze != null){
  59.                     prze = przeglad.readLine();  
  60.                     if(prze != null)
  61.                         x = prze.split(" ");
  62.                 }
  63.                 if(prze == null)
  64.                     System.out.println("Nie ma takiej ksiazki");
  65.                 else
  66.                     System.out.println("Znaleziono ksiazke: " + x[0] + " " + x[1]);
  67.             break;
  68.                
  69.             case "Wyswietl":
  70.                
  71.                
  72.                 File file = new File ("ksiazki.txt");
  73.         Scanner in = new Scanner(file);
  74.                 while(in.hasNext())
  75.                     {
  76.                       System.out.println(in.nextLine());
  77.                     }
  78.        
  79.             break;
  80.             case "koniec":
  81.                 System.out.println("koniec");
  82.             break;
  83.         }
  84.        
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement