The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
May 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

You might find some help here

Posted by Steve on May 25, 2000 at 2:09 AM

> Title: Exception Handling.
> QUESTION: The Programm is to define a class Calculate, which contains the "main method" (public static void main(String[] arg) and has to function like this:

> java Calculate
> is Parallelogram, Rectangle or Square.
> is Area or Circumfrence.
> is Parallelogram:, , Angle.
> Rectangle:,
> Square:

> 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:


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us