E8

public class Bod {
        // instancne premenne
        private double x;
        private double y;

        // konstruktory
        public Bod() {
                this.x = 0;
                this.y = 0;
        }

        public Bod(double x, double y) {
                this.x = x;
                this.y = y;
        }

        // gettre
        public double getX() {
                return this.x;
        }

        public double getY() {
                return this.y;
        }

        // settre
        public void setX(double x) {
                this.x = x;
        }

        public void setY(double y) {
                this.y = y;
        }

        public String toString() {
                return "[" + this.x + "," + this.y + "]";
        }

        public void nastav(double x, double y) {
                this.x = x;
                this.y = y;
        }

        public void nastav(Bod b) {
                if (b == null)
                        return;
                this.x = b.getX();
                this.y = b.getY();
        }

        public boolean rovnakeSuradnice(Bod bod) {
                if (bod == null)
                        return false;
                if (this.x != bod.getX())
                        return false;
                if (this.y != bod.getY())
                        return false;
                return true;
        }

        public double vzdialenostK(double x, double y) {
                return Math.sqrt((this.x - x) * (this.x - x)
                                       + (this.y - y) * (this.y - y));
        }

        public double vzdialenostK(Bod b) {
                if (b == null)
                        return Double.NaN;
                return Math.sqrt((this.x - b.getX()) * (this.x - b.getX())
                                       + (this.y - b.getY()) * (this.y - b.getY()));
        }

        public void posunO(double dx, double dy) {
                this.x = this.x + dx;
                this.y = this.y + dy;
//              skrateny zapis
//              this.x += dx;
//              this.y += dy;
        }

        public Bod posunutyBod(double dx, double dy) {
                return new Bod(this.x + dx, this.y + dy);
        }
}

public class ZoznamBodov {

        private Bod[] zoznam;

        public ZoznamBodov() {
                zoznam = new Bod[0];
        }

        public int dlzka() {
                return zoznam.length;
        }

        public void pridajBod(Bod bod) {
                Bod[] novyZoznam = new Bod[zoznam.length+1];
                System.arraycopy(zoznam, 0, novyZoznam, 0, zoznam.length);
                novyZoznam[zoznam.length] = bod;
                zoznam = novyZoznam;
        }

        public Bod dajBod(int index) {
                return zoznam[index];
        }

        public String toString() {
                String s = "[";
                for (int i = 0; i < zoznam.length - 1; i++) {
                        s += zoznam[i].toString() + ",";
                }
                if (zoznam.length > 0) {
                        s += zoznam[zoznam.length - 1];
                }
                s += "]";
                return s;
                // alebo return Arrays.toString(body);
        }

        public void odoberBod(int index) {
                //ak je index mimo pola tak nic nespravime
                if (index < 0 || index > zoznam.length - 1)
                        return;

                Bod[] novyZoznam = new Bod[zoznam.length - 1];
                System.arraycopy(zoznam, 0, novyZoznam, 0, index);
                System.arraycopy(zoznam, index + 1, novyZoznam, index, zoznam.length - index - 1);
                zoznam = novyZoznam;
        }
}

public class Spustac {

        /**
         * @param args
         */

        public static void main(String[] args) {
                Bod b = new Bod(20, 50);
                System.out.println(b.getX() + " " + b.getY());
                b.nastav(new Bod(26,35));


                Bod novyBod = b.posunutyBod(10, 10);
                System.out.println(novyBod);
                System.out.println(b);

                ZoznamBodov z = new ZoznamBodov();
                System.out.println(z);
                z.pridajBod(new Bod(20.5, 30));
                System.out.println(z);
                z.pridajBod(new Bod(21, 32));
                System.out.println(z);
                z.pridajBod(new Bod(13, 32));
                System.out.println(z);
                z.odoberBod(0);
                System.out.println(z);
        }

}