// MSOFT 2016/17 class Elipsa { private Bod f1; private Bod f2; private int a; private int b; public Elipsa(Bod f1, Bod f2, int a, int b) { this.f1 = f1; this.f2 = f2; this.a = a; this.b = b; } public Bod getF1() { return f1; } public Bod getF2() { return f2; } public void setF1(Bod b) { f1.setX(b.getX()); f1.setY(b.getY()); } public void setF2(Bod b) { f2.setX(b.getX()); f2.setY(b.getY()); } public int getA() { return a; } public int getB() { return b; } public void setA(int d) { a = d; // post: a = d -- toto je zjavne z kodu // post: b = b@pre -- ale to, ze garantujeme, ze sa nedotkneme polomera b, si nemusime uvedomovat } public void setB(int d) { b = d; // post: b = d // post: a = a@pre -- analogicky ako pri setA() } } class Bod { private int x; private int y; public Bod(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } } class Kruh extends Elipsa { public Kruh(Bod c, int r) { super(c, c, r, r); } // rovnaky problem vznika aj s ohniskami - prejavi sa pri presune public void setF1(Bod f1) { super.setF1(f1); super.setF2(f1); } public void setF2(Bod f2) { super.setF1(f2); super.setF2(f2); } public void setA(int d) { super.setA(d); super.setB(d); // post: a = d // post: b = d -- v prekonanej metode sme slubili, ze sa polomera b nedotkneme, ale teraz to vzdavame: zoslabujeme dosledok } public void setB(int d) { super.setA(d); super.setB(d); // post: b = d // post: a = d -- analogicky ako pri setA() } } class C { public void magnify(Elipsa e, float m) { // m-nasobne zvacsenie elipsy e.setA((int) (m * e.getA())); e.setB((int) (m * e.getB())); } public static void main(String args[]) { Kruh k = new Kruh(new Bod(100, 100), 10); // kruh je pre nas len specialna elipsa - ocakavame trojnasobne zvacsenie, teda 30 new C().magnify(k, (float) 3); // ale kruh sa zvacsi o dost viac - o kolko? System.out.println(k.getA() + " " + k.getB()); } }