Advertisement
Guest User

Untitled

a guest
May 27th, 2015
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package testt;
  8.  
  9. import java.io.File;
  10. import java.io.FileNotFoundException;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. import java.util.LinkedList;
  14. import java.util.List;
  15. import java.util.Scanner;
  16.  
  17. /**
  18.  *
  19.  * @author suries
  20.  */
  21. public class Testt {
  22.     static List<Aukcja> listaAukcji = new LinkedList();
  23.    
  24.     public static void wyswietlWszystkie(){
  25.         for(int i=0; i<listaAukcji.size(); i++){
  26.             Aukcja temp = (Aukcja) listaAukcji.get(i);
  27.            
  28.             wypiszAukcje(temp);
  29.         }
  30.     }
  31.    
  32.     public static void wyswietlWgCeny(float min, float max){
  33.         for (Aukcja temp : listaAukcji){
  34.             if(temp.getCena() > min && temp.getCena() < max){
  35.                 wypiszAukcje(temp);
  36.             }
  37.         }
  38.     }
  39.    
  40.     public static void wypiszAukcje(Aukcja aukcja){
  41.         System.out.println("Numer: " + aukcja.getNumer());
  42.         System.out.println("Nazwa: " + aukcja.getNazwa());
  43.         System.out.println("Cena: " + aukcja.getCena());
  44.         System.out.println("");
  45.     }
  46.    
  47.     public static void init() throws FileNotFoundException{
  48.         File file = new File("plik.txt");
  49.         Scanner scan = new Scanner(file);
  50.         while(scan.hasNextLine()){
  51.             Aukcja temp = new Aukcja();
  52.            
  53.             int numer = scan.nextInt();
  54.             temp.setNumer(numer);
  55.            
  56.             String nazwa = scan.next();
  57.             temp.setNazwa(nazwa);
  58.            
  59.             float cena = scan.nextFloat();
  60.             temp.setCena(cena);
  61.            
  62.             listaAukcji.add(temp);
  63.         }
  64.     }
  65.    
  66.     public static void dodajAukcje() throws FileNotFoundException{
  67.         Scanner scan = new Scanner(System.in);
  68.        
  69.         System.out.println("Nowa Aukcja ");
  70.         System.out.println("Numer: ");
  71.         int numer = scan.nextInt();
  72.        
  73.         System.out.println("Nazwa: ");
  74.         String nazwa = scan.next();
  75.        
  76.         System.out.println("Cena: ");
  77.         float cena = scan.nextFloat();
  78.        
  79.         Aukcja nowa = new Aukcja();
  80.         nowa.setNumer(numer);
  81.         nowa.setNazwa(nazwa);
  82.         nowa.setCena(cena);
  83.        
  84.         listaAukcji.add(nowa);
  85.        
  86.        
  87.         File file = new File("plik.txt");
  88.         PrintWriter pw = new PrintWriter(file);
  89.        
  90.         for(int i=0; i<listaAukcji.size(); i++){
  91.             Aukcja temp = listaAukcji.get(i);
  92.            
  93.             pw.println(temp.getNumer());
  94.             pw.println(temp.getNazwa());
  95.             pw.println(temp.getCena());
  96.         }
  97.        
  98.         pw.println(nowa.getNumer());
  99.         pw.println(nowa.getNazwa());
  100.         pw.println(nowa.getCena());
  101.         pw.close();
  102.     }
  103.  
  104.     /**
  105.      * @param args the command line arguments
  106.      */
  107.     public static void main(String[] args) throws IOException {
  108.        
  109.         init();
  110.        
  111.         wyswietlWszystkie();
  112.         dodajAukcje();
  113.        //wyswietlWgCeny(80, 350);
  114.         //System.out.println(listaAukcji.size());
  115.        
  116.     }
  117.    
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement