Hallo Leute,
hab mal wieder Probleme mit meiner hausaufgabe. bin mal so dreist und geb euch erstmal die aufgabe und anschließend mein lösungsvorschlag.
Aufgabe:
-Erstellen einer Klasse "Triangle" zur Präsentation von Dreiecken
-Dreiecke durch 3 Punkte gegeben (x1,y1;x2y2;x3,y3) vom Datentyp float
-Klasse soll folgendes enthalten:
1.) Konstruktor ohne Paramenter: public Triangle ()
2.) Konstruktor mit Koordinaten der 3 Punkte : public Triangle (float x1, float y1, float x2 ....)
3.) Methode zur Flächeninhaltsberechnung: public float area ()
4.) Mehtode zur Verschiebung des Dreiecks um gegebenen Vektor: public void move (float delta_x, float delta_y)
Nun mein Lösungsansatz:
Leider meckert der Compiler schon beim leeren Konstruktor rum. Außerdem will er nicht, dass der Flächeninhalt über float berechnet wird.
Es wäre also nett, wenn ihr mir veilleicht, sagt, ob ich noch irgendwelche Syntaxfehler habe und, ob ich das überhaupt richtig formuliert habe. meine methoden scheinen mir ganz schön kompliziert.
hab mal wieder Probleme mit meiner hausaufgabe. bin mal so dreist und geb euch erstmal die aufgabe und anschließend mein lösungsvorschlag.
Aufgabe:
-Erstellen einer Klasse "Triangle" zur Präsentation von Dreiecken
-Dreiecke durch 3 Punkte gegeben (x1,y1;x2y2;x3,y3) vom Datentyp float
-Klasse soll folgendes enthalten:
1.) Konstruktor ohne Paramenter: public Triangle ()
2.) Konstruktor mit Koordinaten der 3 Punkte : public Triangle (float x1, float y1, float x2 ....)
3.) Methode zur Flächeninhaltsberechnung: public float area ()
4.) Mehtode zur Verschiebung des Dreiecks um gegebenen Vektor: public void move (float delta_x, float delta_y)
Nun mein Lösungsansatz:
Java:
class Triangle {
float x1;
float y1;
float x2;
float y2;
float x3;
float y3; //Deklaration der Vektoren des Dreiecks
float xneu1 = Math.abs(x1-x2); // Subtraktion der einzelnen Vektoren mit Betrag
float yneu1 = Math.abs(y1-y2);
float a = Math.sqrt (xneu1*xneu1+yneu1*yneu1); // Berechnung der Seitenlänge a
float xneu2 = Math.abs(x2-x3);
float yneu2 = Math.abs(y2-y3);
float b = Math.sqrt (xneu2*xneu2+yneu2*yneu2);
float xneu3 = Math.abs(x3-x1);
float yneu3 = Math.abs(y3-y1);
float c = Math.sqrt (xneu3*xneu3+yneu3*yneu3);
float s = (a+b+c)/2;
float delta_x = 2;
float delta_y = 0;
public Triange ()
public Triangle (float x1, float y1, float x2, float y2, float x3, float y3) {
// Konstruktor
this.x1 = x1;
this.y1 = y2;
this.x2 = x2;
this.y2 = y2;
this.x3 = x3;
this.y3 = y3;
}
public void main (String [] args) {
Triangle dreieck = new Triangle (0,0,4,0,2,2); // Wertzuweisung
System.out.println(area(a,b,c,s));
}
public float area (float a, float b, float c, float s) {
// Methoese zur Berechnung des Flächeninhalts des Dreiecks
float A;
A = 1/4 * Math.sqrt((a+b+c)*(a+b-c)*(b+c-a)*(c+a-b));
return A;
}
public void move (float delta_x , float delta_y ) {
// Methode zur Verschiebung des Dreiecks um einen gegebenen Vektor
float x1n = delta_x + x1;
float y1n = delta_y + y1;
float x2n = delta_x + x2;
float y2n = delta_y + y2;
float x3n = delta_x + x3;
float y3n = delta_y + y3;
}
}
Leider meckert der Compiler schon beim leeren Konstruktor rum. Außerdem will er nicht, dass der Flächeninhalt über float berechnet wird.
Es wäre also nett, wenn ihr mir veilleicht, sagt, ob ich noch irgendwelche Syntaxfehler habe und, ob ich das überhaupt richtig formuliert habe. meine methoden scheinen mir ganz schön kompliziert.