Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Kreis {
- // diese Eigenschaften hat der Kreis
- double x, y;
- double radius;
- Kreis(double x, double y, double radius) {
- this.x = x;
- this.y = y;
- this.radius = radius;
- }
- Kreis() {
- }
- public boolean equals(Object other) {
- // wenn das selbe Objekt uebergeben wird ist jedenfalls true zurueckzugeben, falls das uebergebene Objekt nicht mal ein Kreis ist dann sicher false.
- if(other == this) {
- return true;
- }
- if(!(other instanceof Kreis)) {
- return false;
- }
- // wir casten mal das uebergebene Objekt auf einen Kreis.
- Kreis kother = (Kreis) other;
- // und geben dann den logischen wert von folgenden Vergleich zurueck, der ist nur dann true wenn alles ( x,y,radius) gleich ist)
- return this.x == kother.x && this.y == kother.y && this.radius == kother.radius;
- }
- double addieren(double... zahlen) {
- double summand = 0.0;
- int i = 0;
- while (i < zahlen.length) {
- summand += zahlen[i]; // ist das gleiche wie: summand = summand +
- // zahlen[i]
- i++;
- }
- return summand;
- }
- double umfang(double radius) {
- double umfang = 2 * Math.PI * radius;
- return umfang;
- }
- double flaecheninhalt(double radius) {
- double flaecheninhalt = Math.PI * radius * radius;
- return flaecheninhalt;
- }
- double getRadius () {
- return radius;
- }
- public static void main(String[] args) {
- Kreis k1 = new Kreis(0.0, 0.0, 5.0);
- Kreis k2 = new Kreis(0.0, 0.0, 5.0);
- Kreis k3 = new Kreis(0.0, 1.0, 4.0);
- if ( k1.equals(k2) ){
- System.out.println("Juhu wir sind gleich");
- }
- else {
- System.out.println("Oje ungleich");
- }
- if ( k1.equals(k3) ){
- System.out.println("Juhu wir sind gleich");
- }
- else {
- System.out.println("Oje ungleich");
- }
- }
- }
Add Comment
Please, Sign In to add comment