Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5.  
  6. /*
  7.     Zdecydowanie się późno za to zabrałem...
  8.     Odczyt jest próbkowy, ale działa, nie ważne przy jakiej ilości danych.
  9.     Zapisywanie do pliku zadań też działa... tylko, że zamiast dopisywać to nadpisuje :/
  10. */
  11. class AskMe {
  12.     public static void readFile(String name) throws IOException {
  13.         FileReader plikIn = null;
  14.  
  15.         try {
  16.             plikIn = new FileReader(name);
  17.             int c;
  18.             while ((c = plikIn.read()) != -1) {
  19.                 System.out.print((char) c);
  20.             }
  21.         }finally {
  22.             if (plikIn != null) {
  23.                 plikIn.close();
  24.             }
  25.         }
  26.     }
  27.  
  28.     public static void deleteFile(String name) throws IOException {
  29.         //nie wiem, brak czasu (słaba wymówka xD)
  30.     }
  31.  
  32.  
  33.     public static void addFile(String name) throws IOException {
  34.         PrintWriter save = new PrintWriter(name);
  35.  
  36.         Scanner act = new Scanner(System.in);
  37.         String questName;
  38.         String questType;
  39.         String questWeight;
  40.         String timeStart;
  41.         String timeStop;
  42.         System.out.print("Podaj nazwę zadania:\n");
  43.         questName = act.nextLine();
  44.         System.out.print("Podaj typ zadania:\n");
  45.         questType = act.nextLine();
  46.         System.out.print("Podaj wagę zadania:\n");
  47.         questWeight = act.nextLine();
  48.         System.out.print("Podaj czas rozpoczęcia:\n");
  49.         timeStart = act.nextLine();
  50.         System.out.print("Podaj czas zakończenia:\n");
  51.         timeStop = act.nextLine();
  52.         save.print("Nazwa zadania: " + questName+ ", Typ: " + questType + ", Waga" + questWeight
  53.                 + ", Czas rozpoczęcia: " + timeStart + ", Czas zakończenia: " + timeStop);
  54.         save.close();
  55.     }
  56.  
  57.     public static void main(String[] args) throws IOException {
  58.         System.out.print("Co chcesz zrobić?\n");
  59.         System.out.print("Wybierz 1, jeżeli chcesz doddać zadanie\n");
  60.         System.out.print("Wybierz 2, jeżeli chcesz wyświetlić dostępne zadania\n");
  61.         System.out.print("Wybierz 3, jeżeli chcesz usunąć zadanie\n");
  62.  
  63.         Scanner now = new Scanner(System.in);
  64.         int number;
  65.         String plikTxt = "Dane.txt";
  66.         number = now.nextInt();
  67.  
  68.         switch (number) {
  69.             case 1:
  70.                 System.out.print("Wybrałeś 1\n");
  71.                 addFile(plikTxt);
  72.                 break;
  73.             case 2:
  74.                 System.out.print("Wybrałeś 2\n");
  75.                 readFile(plikTxt);
  76.                 break;
  77.             case 3:
  78.                 System.out.print("Wybrałeś 3\n");
  79.                 deleteFile(plikTxt);
  80.                 break;
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement