Lösungsvorschlag 7.3 - Aufgabe 2: Unterschied zwischen den Versionen
Aus ComeniusWiki
(Die Seite wurde neu angelegt: „<pre> public class Schueler { //Attribute private String name; private String vorname; private String klasse; //Klassenvariable static int schuelerzahl=0; p…“) |
|||
| (2 dazwischenliegende Versionen von einem Benutzer werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
<pre> | <pre> | ||
| − | public class | + | public class Punkt{ |
| − | { | + | |
//Attribute | //Attribute | ||
| − | private | + | private int x; |
| − | private | + | private int y; |
| − | + | ||
| − | // | + | //Konstruktor |
| − | + | public Punkt(int x, int y){ | |
| + | this.x=x; | ||
| + | this.y=y; | ||
| + | } | ||
| − | public | + | //Getter- und Setter-Methoden |
| − | + | public int getX(){ | |
| − | + | return x; | |
| − | + | } | |
| − | + | public int getY(){ | |
| − | + | return y; | |
| − | } | + | } |
| − | public | + | public void setX(int newX){ |
| − | + | x=newX; | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
} | } | ||
| + | public void setY(int newY){ | ||
| + | y=newY; | ||
| + | } | ||
} | } | ||
</pre> | </pre> | ||
<pre> | <pre> | ||
| − | public class | + | public class Kreis{ |
| − | { | + | //Attribute |
| − | + | private int radius; | |
| − | // | + | private Punkt center; |
| − | + | ||
//Konstruktor | //Konstruktor | ||
| − | public | + | public Kreis(int radius, int x, int y){ |
| − | + | this.radius = radius; | |
| − | + | center = new Punkt(x,y); | |
| − | + | } | |
| − | + | ||
| − | + | ||
| − | + | public void verschieben(int newX, int newY){ | |
| − | + | center.setX(newX); | |
| + | center.setY(newY); | ||
} | } | ||
| − | // | + | //Alternative Umsetzung der Methode verschieben() |
| − | public void | + | public void verschiebenAlt(int newX, int newY){ |
| − | + | center = new Punkt(newX, newY); | |
| − | + | ||
} | } | ||
| + | public void radiusVeraendern(int radNew){ | ||
| + | radius=radNew; | ||
| + | } | ||
} | } | ||
</pre> | </pre> | ||
Aktuelle Version vom 17. April 2015, 10:42 Uhr
public class Punkt{
//Attribute
private int x;
private int y;
//Konstruktor
public Punkt(int x, int y){
this.x=x;
this.y=y;
}
//Getter- und Setter-Methoden
public int getX(){
return x;
}
public int getY(){
return y;
}
public void setX(int newX){
x=newX;
}
public void setY(int newY){
y=newY;
}
}
public class Kreis{
//Attribute
private int radius;
private Punkt center;
//Konstruktor
public Kreis(int radius, int x, int y){
this.radius = radius;
center = new Punkt(x,y);
}
public void verschieben(int newX, int newY){
center.setX(newX);
center.setY(newY);
}
//Alternative Umsetzung der Methode verschieben()
public void verschiebenAlt(int newX, int newY){
center = new Punkt(newX, newY);
}
public void radiusVeraendern(int radNew){
radius=radNew;
}
}

