Montag, 10. Oktober 2011

 

Java -> Python (POS1: 2B)

Wandeln Sie folgendes Java-Programm in ein Python Programm um:
public class Dreiecksbestimmung {

    public static void main(String[] args) {
      dreiecksbestimmung(3.0, 4.0, 5.0);
      dreiecksbestimmung(3.0, 3.0, 3.0);
      dreiecksbestimmung(3.0, 3.0, 5.0);
      dreiecksbestimmung(3.0, 4.5, 5.0);
      dreiecksbestimmung(1.0, 2.0, 3.0);
    }

    private static void dreiecksbestimmung(double a, double b, double c) {
      System.out.printf("a = %.2f, b = %.2f, c = %.2f: ", a, b, c);
      if (dreieck(a, b, c)) {
        if (gleichseitig(a, b, c)) {
          System.out.print("gleichseitiges ");
        } else if (gleichschenkelig(a, b, c)) {
          System.out.print("gleichschenkeliges ");
        }
        if (rechtwinkelig(a, b, c)) {
          System.out.print("rechtwinkeliges ");
        }
        System.out.println("Dreieck");
      } else {
        System.out.println("kein gültiges Dreieck");
      }
    }

    private static boolean rechtwinkelig(double a, double b, double c) {
      double a2 = a * a;
      double b2 = b * b;
      double c2 = c * c;
      return a2 + b2 == c2 || a2 + c2 == b2 || b2 + c2 == a2;
    }

    private static boolean gleichschenkelig(double a, double b, double c) {
      return a == b || a == c || b == c;
    }

    private static boolean gleichseitig(double a, double b, double c) {
      return a == b && b == c;
    }

    private static boolean dreieck(double a, double b, double c) {
      return a + b > c && a + c > b && b + c > a;
    }

}
Ergänzen Sie Ihr Programm um geeignete Doc-Strings und Kommentare!

Labels: , , ,


Kommentare:

Kommentar veröffentlichen

Abonnieren Kommentare zum Post [Atom]





<< Startseite

This page is powered by Blogger. Isn't yours?

Abonnieren Posts [Atom]