Hallo! habe folgende Klasse geschrieben:
Jetzt will ich folgendes machen:
Aber irgendwie macht er das nicht.... Die Fehlermedlung des Compilers versteh ich leider nicht. Kann mir vielleicht jemand helfen? Ich würde gerne die Lösung erarbeiten!!
Danke und Gruß
Java:
class Circle {
int x, y;
int radius;
String color;
Circle() {
this.x = x;
this.y = y;
this.radius = radius;
this.color = color;
}
void shift (int dx, int dy) {
x = x + dx;
y = y + dy;
}
void scale (double a){
this.radius = radius*(int) a;
}
double getArea(){
return Math.PI * radius * radius;
}
void setColor (String color){
this.color = color;
}
}
Java:
class TestCircle {
public static void main(String[] args) {
/*** KREIS 1 *********************************************************/
/* (1) Erzeuge Kreis mit
* x = 0
* y = 0
* radius = 20
* color = red
*/
Circle circle = new Circle();
circle.x = 0;
circle.y = 0;
circle.radius = 20;
cirlce.color = "red;
/* (2) Ausgabe des Flaecheninhalts auf der Konsole
*/
System.out.println("Flaecheninhalt=" + circle.getArea);
//! Fuegt Kreis zum Zeichnen hinzu
CircleDrawer.add(c);
/*** KREIS 2 *********************************************************/
/* (3) Verschiebe Mittelpunkt des Kreises mit der shift-Methode, wobei
* dx = 40
* dy = -60
*/
circle.x = 0+40;
circle.y = 0+-60;
/* (4) Skaliere Kreis mit scale-Methode, wobei
* a = 0.5
*/
circle.radius = 20*(int)0,5;
/* (5) Setze Farbe des Kreises mit der entsprechenden setter-Methode,
* wobei
* color = "blue"
*/
circle.color = "red";
/* (6) Ausgabe des Flaecheninhalts auf der Konsole
*/
System.out.println("Flaecheninhalt=" + circle.getArea);
//! Fuegt Kreis zum Zeichnen hinzu
CircleDrawer.add(c);
//! zeichnet Kreis
CircleDrawer.draw();
}
}
Danke und Gruß
Zuletzt bearbeitet: