Created
April 29, 2015 07:52
-
-
Save 3c7/f128ff85f9a8a3b78d10 to your computer and use it in GitHub Desktop.
Algorithmen und Datenstrukturen Übung 4 Aufgabe 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 13.04.2015. | |
*/ | |
public abstract class Koerper implements Skalierbar { | |
// Bezugspunkt, geschachtelte Klasse | |
public Koerper.Punkt p; | |
public void verschiebe(double dx, double dy, double dz) { | |
this.p = new Punkt(p.x + dx, p.y + dy, p.z + dz); | |
} | |
public abstract void skaliere(double a); | |
public abstract boolean enthaelt(Punkt a); | |
public abstract double volumen(); | |
public abstract double oberflaeche(); | |
public abstract double durchmesser(); | |
public Punkt bezug() { | |
return this.p; | |
} | |
static boolean between(double a, double min, double max) { | |
if (a >= min && a <= max) return true; | |
return false; | |
} | |
static class Punkt { | |
private double x, y, z; | |
public Punkt(double x, double y, double z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
} | |
public Punkt(Punkt a) { | |
this.x = a.x(); | |
this.y = a.y(); | |
this.z = a.z(); | |
} | |
public double x() { | |
return this.x; | |
} | |
public double y() { | |
return this.y; | |
} | |
public double z() { | |
return this.z; | |
} | |
public Punkt verschiebe(double dx, double dy, double dz) { | |
this.x = this.x() + dx; | |
this.y = this.y() + dy; | |
this.z = this.z() + dz; | |
return this; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 13.04.2015. | |
*/ | |
public class Kugel extends Koerper implements Skalierbar { | |
// Radius | |
private double r; | |
// Konstruktor | |
public Kugel(Punkt p, double r) { | |
this.p = new Punkt(p.x(), p.y(), p.z()); | |
this.r = r; | |
} | |
// Methoden | |
public void skaliere(double a) { | |
this.r = this.r * a; | |
} | |
public boolean enthaelt(Punkt a) { | |
if (Math.sqrt(Math.pow(this.p.x() - a.x(),2) + Math.pow(this.p.y() - a.y(),2) + Math.pow(this.p.z() - a.z(),2)) <= this.r) | |
return true; | |
return false; | |
} | |
public double volumen() { | |
return (4.0 / 3.0) * Math.PI * Math.pow(this.r, 3); | |
} | |
public double oberflaeche() { | |
return 4 * Math.PI * Math.pow(this.r, 2); | |
} | |
public double durchmesser() { | |
return 2 * this.r; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 13.04.2015. | |
*/ | |
public class Quader extends Koerper implements Skalierbar { | |
// Breite, Tiefe, H�he | |
private double b, t, h; | |
public Quader(Punkt p, double b, double t, double h) { | |
this.p = new Punkt(p.x(), p.y(), p.z()); | |
this.b = b; | |
this.t = t; | |
this.h = h; | |
} | |
// Methoden | |
public void skaliere(double a) { | |
this.b = this.b * a; | |
this.t = this.t * a; | |
this.h = this.h * a; | |
} | |
public boolean enthaelt(Punkt a) { | |
if (between(a.x(), this.p.x(), this.p.x() + this.b) && between(a.y(), this.p.y(), this.p.y() + this.t) && between(a.z(), this.p.z(), this.p.z() + this.h)) | |
return true; | |
return false; | |
} | |
public double volumen() { | |
return this.b * this.t * this.h; | |
} | |
public double oberflaeche() { | |
return 2 * this.b * this.t + 2 * this.b * this.h + 2 * this.t * this.h; | |
} | |
public double durchmesser() { | |
return Math.sqrt(Math.pow(this.b, 2) + Math.pow(this.t, 2) + Math.pow(this.h, 2)); | |
} | |
public double b() { | |
return this.b; | |
} | |
public double t() { | |
return this.t; | |
} | |
public double h() { | |
return this.h; | |
} | |
public enum Orientierung { | |
LINKS, RECHTS, VORN, HINTEN, UNTEN, OBEN; | |
} | |
public class Seite { | |
private Orientierung o; | |
public Seite(Orientierung o) { | |
this.o = o; | |
} | |
public double laenge() { | |
switch (o.ordinal()) { | |
case 0: | |
return t(); | |
case 1: | |
return t(); | |
case 2: | |
return b(); | |
case 3: | |
return b(); | |
case 4: | |
return b(); | |
case 5: | |
return b(); | |
} | |
return 0.0; | |
} | |
public double breite() { | |
switch (o.ordinal()) { | |
case 0: | |
return h(); | |
case 1: | |
return h(); | |
case 2: | |
return h(); | |
case 3: | |
return h(); | |
case 4: | |
return t(); | |
case 5: | |
return t(); | |
} | |
return 0.0; | |
} | |
public Punkt bezug() { | |
switch (this.o.ordinal()) { | |
case 0: | |
return p; | |
case 1: | |
return new Punkt(p.x() + b(), p.y(), p.z()); | |
case 2: | |
return p; | |
case 3: | |
return new Punkt(p.x(), p.y() + t(), p.z()); | |
case 4: | |
return p; | |
case 5: | |
return new Punkt(p.x(), p.y(), p.z() + h()); | |
} | |
return p; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 13.04.2015. | |
*/ | |
public interface Skalierbar { | |
void skaliere(double a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment