All pastes #955716 Raw Edit

Miscellany

public java v1 · immutable
#955716 ·published 2008-03-24 20:25 UTC
rendered paste body
/* * Winkel.java * * Created on 9 maart 2007, 9:03 * * To change this template, choose Tools | Template Manager * and open the template in the editor. *//** * * * @author lecturer */import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import java.util.*;import javax.swing.*;public class Winkel implements Serializable{        private ArrayList<Cd> cdWinkel = new ArrayList<Cd>();            /** Creates a new instance of Winkel */    public Winkel() {    }            public Cd findCd( String artiest, String titel ) {        for( Cd cd: cdWinkel ) {            if( cd.getArtiest().equalsIgnoreCase( artiest ) &&                cd.getTitel().equalsIgnoreCase( titel ) )                return cd;        }        return null;    }            public void printAll() {        for( Cd cd: cdWinkel )            System.out.println( cd );    }            public String getAll() {        String all = "";        for( Cd cd: cdWinkel )            all = all + cd.toString() + "\n";        return all;    }            public void addCd( String artiest, String titel, String label, int voorraad ) {        Cd cd = new Cd( artiest, titel, label, voorraad );        cdWinkel.add( cd );    }        public void deleteCd( String artiest, String titel ) {        Cd cd = findCd( artiest, titel );        cdWinkel.remove( cd );    }        public void wijzigVoorraad( String artiest, String titel, int voorraad ) {        Cd cd = findCd( artiest, titel );        cd.setVoorraad( voorraad );    }     public void write( String fileName ) {        try {            ObjectOutputStream uit = new ObjectOutputStream(new FileOutputStream(fileName));                        uit.writeObject(cdWinkel);            uit.close();        }        catch (IOException io){}    }    public void read( String fileName ) {        try {            ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));            cdWinkel = (ArrayList<Cd>) in.readObject();            in.close();        }        catch (IOException io){}        catch (ClassNotFoundException cnf){}            }        public void nieuw() {        cdWinkel.clear();    }}