Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package testt;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Scanner;
- /**
- *
- * @author suries
- */
- public class Testt {
- static List<Aukcja> listaAukcji = new LinkedList();
- public static void wyswietlWszystkie(){
- for(int i=0; i<listaAukcji.size(); i++){
- Aukcja temp = (Aukcja) listaAukcji.get(i);
- wypiszAukcje(temp);
- }
- }
- public static void wyswietlWgCeny(float min, float max){
- for (Aukcja temp : listaAukcji){
- if(temp.getCena() > min && temp.getCena() < max){
- wypiszAukcje(temp);
- }
- }
- }
- public static void wypiszAukcje(Aukcja aukcja){
- System.out.println("Numer: " + aukcja.getNumer());
- System.out.println("Nazwa: " + aukcja.getNazwa());
- System.out.println("Cena: " + aukcja.getCena());
- System.out.println("");
- }
- public static void init() throws FileNotFoundException{
- File file = new File("plik.txt");
- Scanner scan = new Scanner(file);
- while(scan.hasNextLine()){
- Aukcja temp = new Aukcja();
- int numer = scan.nextInt();
- temp.setNumer(numer);
- String nazwa = scan.next();
- temp.setNazwa(nazwa);
- float cena = scan.nextFloat();
- temp.setCena(cena);
- listaAukcji.add(temp);
- }
- }
- public static void dodajAukcje() throws FileNotFoundException{
- Scanner scan = new Scanner(System.in);
- System.out.println("Nowa Aukcja ");
- System.out.println("Numer: ");
- int numer = scan.nextInt();
- System.out.println("Nazwa: ");
- String nazwa = scan.next();
- System.out.println("Cena: ");
- float cena = scan.nextFloat();
- Aukcja nowa = new Aukcja();
- nowa.setNumer(numer);
- nowa.setNazwa(nazwa);
- nowa.setCena(cena);
- listaAukcji.add(nowa);
- File file = new File("plik.txt");
- PrintWriter pw = new PrintWriter(file);
- for(int i=0; i<listaAukcji.size(); i++){
- Aukcja temp = listaAukcji.get(i);
- pw.println(temp.getNumer());
- pw.println(temp.getNazwa());
- pw.println(temp.getCena());
- }
- pw.println(nowa.getNumer());
- pw.println(nowa.getNazwa());
- pw.println(nowa.getCena());
- pw.close();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- init();
- wyswietlWszystkie();
- dodajAukcje();
- //wyswietlWgCeny(80, 350);
- //System.out.println(listaAukcji.size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement