Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: http://upload.wikimedia.org/wikipedia/en/thumb/2/2e/Java_Logo.svg/322px-Java_Logo.svg.png   Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: http://hopf.chem.brandeis.edu/yanglingfa/pic/uml.GIF

 

 

 

     Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: D:\_2010_Nokia\Curs Nokia-UPB 2011\ETTI_logo_bleu.jpg

Universitatea POLITEHNICA din Bucuresti

Facultatea de Electronica, Telecomunicatii si Tehnologia Informatiei

Departamentul Telecomunicatii

.

 

 

 

 

 

2011

 

 

 

Laboratorul  – sala B123

 

 

PSNIM

2012

Tehnologii de Programare

in Internet

(TPI)

 

25/03/2014

                     

   

 2013-2014

 

                                           

 

Exemple coduri

 

1.

            1.1.

 

 

public class Cont {

    private double sold; // atribut - field - camp - variabila membru

    private static int nc; // atribut al clasei

 

    public Cont(double soldInitial) { // constructor

        if (soldInitial > 0.0)        // ???

            sold = soldInitial;

        nc++;

    }

   

    public Cont() { // ???

        sold = 0; //  ???

        nc++;

    }

 

    public double situatieCont() { // metoda ???

        return sold;   

    }

 

    public void depunere(double sumaDepusa) { // metoda

        sold = sold + sumaDepusa;   

    }

 

    public void retragere(double sumaRetrasa) { // metoda

        sold = sold - sumaRetrasa;   

    }

}

 

 

public class TestareCont {

 

     public static void main(String[] args){

        Cont c1 = new Cont(100);

        double situatieCont = c1.situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

     }

}

 

 

public class ContSigur {

    private double sold; // atribut

    private boolean admin;

 

    public ContSigur(double soldInitial) { // constructor

        if (soldInitial > 0.0)        // soldul initial nenegativ

            sold = soldInitial;

    }

 

    public ContSigur() { // supraincarcarea numelui (overloading)

        sold = 0;

    }

 

    public double situatieCont() { // metoda getter

        return sold;   

    }

 

    public void setAdmin(boolean admin) { // metoda setter

        this.admin = admin;   

    }

   

    public void depunere(double sumaDepusa) { // metoda setter

        if (admin)

            sold = sold + sumaDepusa;   

    }

 

    public void retragere(double sumaRetrasa) { // metoda setter

        if (admin)

            sold = sold - sumaRetrasa;   

    }

}

 

 

public class TestareAdmin {

 

     public static void main(String[] args){

        ContSigur c1 = new ContSigur(100);

        double situatieCont = c1.situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

        c1.setAdmin(true);

        c1.depunere(10);

        situatieCont = c1.situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

     }

}

 

 

public class TestareNonadmin {

 

     public static void main(String[] args){

        ContSigur c1 = new ContSigur(100);

        double situatieCont = c1.situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

        c1.setAdmin(false);

        c1.depunere(10);

        situatieCont = c1.situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

     }

}

 

 

 

 

 

public class ClientAutoServire {

    private ContSigur c1;

 

    public ClientAutoServire()

    {

        c1 = new ContSigur();

    }

   

    public ContSigur getContSigur(){

        return c1;

    }

}

 

 

public class TestareClientAutoServire {

     public static void main(String[] args){

        ClientAutoServire cl1 = new ClientAutoServire();

        // cl1.setContSigur(new ContSigur(100));

        double situatieCont = cl1.getContSigur().situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

        cl1.getContSigur().setAdmin(false);

        cl1.getContSigur().depunere(10);

        situatieCont = cl1.getContSigur().situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

     }

   

}

 

 

public class ClientContOferit {

    private ContSigur c1;

 

    public ClientContOferit()

    {

    }

 

    public void setContSigur(ContSigur cs){

        c1 = cs;

    }

   

    public ContSigur getContSigur(){

        return c1;

    }

}

 

 

public class TestareClientContOferit {

    

     public static void main(String[] args){

        ClientContOferit cl1 = new ClientContOferit();

        cl1.setContSigur(new ContSigur(100));

        double situatieCont = cl1.getContSigur().situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

        cl1.getContSigur().setAdmin(false);

        cl1.getContSigur().depunere(10);

        situatieCont = cl1.getContSigur().situatieCont();

        System.out.println("Situatia contului: " + situatieCont);

     }

   

}