> Do I have to join al the three classes together? How do I add the main METHOD then? The programe are under. How can it then be interrupted with "throw new error();" as well give information to the user?
>
>
> ANSWER
> public class Parallelogramm {
>
> private Koordinate k1,k2;
> private double a,b,h;
> private double alpha;
> public Parallelogramm(Koordinate k1, Koordinate k2, double alpha) {
> this.k1 = k1;
> this.k2 = k2;
> this.alpha = alpha;
> h = Math.abs(k2.getY()-k1.getY());
> b = h / Math.sin(alpha);
> a = Math.abs(k2.getX()-k1.getX()) - b*Math.cos(alpha);
> }
> public Parallelogramm(Koordinate k1, Koordinate k2, int alpha) {
> this(k1,k2,alpha*Math.PI/180);
> }
> public double getA() { return a; }
> public double getB() { return b; }
> public double getH() { return h; }
> public double getAlpha() { return alpha; }
> public double Area() {
> return a*h;
> }
> public double Circumfrence() {
> return 2*(a+b);
> }
> }
> public class Rectangle extends Parallelogramm {
> public Rectangle(Koordinate k1, Koordinate k2) {
> super(k1,k2,90); // alternativ: super(k1,k2,Math.PI/2);
> }
> }
>
> public class Square extends Rectangle {
> public Square(Koordinate k1, Koordinate k2) {
> super(k1,k2);
> if (Math.abs(this.getSeite1()-this.getSeite2())>0.0001) {
> throw new Error("The Coordinates do not describe a Square");
> }
> }
> }
I have no idea, but Askme.com has several people you can ask
Replies: