Facebook
From eadsasd, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 258
  1. package domy;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class Domy {
  7.  
  8.     public static void main(String[] args) throws IOException {
  9.         int licznik = 0;
  10.         FileOutputStream fos = new FileOutputStream("dane.dat");
  11.         DataOutputStream dos = new DataOutputStream(fos);
  12.         FileReader fr = new FileReader("domy.txt");
  13.         Scanner sc = new Scanner(fr);
  14.         String linia,nazwa = null;
  15.         String[] dane;
  16.         double cena;
  17.         int kondygnacje;
  18.         while (sc.hasNextLine()){
  19.             linia = sc.nextLine();
  20.             dane = linia.split("-");
  21.             nazwa = dane[0];
  22.             cena = Double.parseDouble(dane[1]);
  23.             kondygnacje = Integer.parseInt(dane[2]);
  24.             if (kondygnacje!=2){
  25.                 dos.writeUTF(nazwa);
  26.                 dos.writeDouble(cena);
  27.                 dos.writeInt(kondygnacje);
  28.                 licznik++;
  29.             }
  30.         }
  31.  
  32.         dos.close();
  33.         PrintWriter pw = new PrintWriter("raport.txt");
  34.         FileInputStream fis = new FileInputStream("dane.dat");
  35.         DataInputStream dis = new DataInputStream(fis);
  36.         for (int i=0; i<licznik; i++ ) {
  37.             nazwa = dis.readUTF();
  38.             cena = dis.readDouble();
  39.             kondygnacje = dis.readInt();
  40.             if(cena < 250000){
  41.                 pw.println(nazwa+", "+cena+", "+kondygnacje);
  42.             }
  43.         }
  44.         dis.close();    
  45.         pw.close();
  46.     }
  47.    
  48. }
  49.