Skip to content
Snippets Groups Projects
Koerper.java 2.41 KiB
Newer Older
public abstract class Koerper {
   
    //      . z
    //      .
    //      .
    //      .
    //      . 
    //      .
    //      .  +>>>>>>>>>>>>+ 
    //      +./|.........../| y
    //     . +<<<<<<<<<<<<+ |
    //    . c| +>>>>>>>>>>|>+
    //   .   |/ a         |/
    //  .    +<<<<<<<<<<<<+
    // . x           b

    
    private double x;
    private double y;
    private double z;
    
    private String farbe = "black";
    
    public Koerper( double x, double y, double z ) {
        this.x = x;
        this.y = y;        
        this.z = z;
    }
    
    // abstract methods
    public abstract double berechneOberflaeche();
    
    public abstract double berechneVolumen();
    
    public abstract String getParameter();
    
    public abstract void skaliere(double alpha);
    
    public abstract boolean istImKoerper( double x, double y, double z );
    
    // final methods    
    public final String istEin() {
        if( this instanceof Quader ) {
            return "Quader";
        } else {
            return "Kugel";
        }
    }
    
    public final void verschiebeHorizontal(double schritte) {
        this.y = this.y + schritte;
    }
    
    public final void verschiebeVertikal(double schritte) {
        this.z = this.z + schritte;
    }
    
    public final void verschiebeTiefe(double schritte) {
        this.x = this.x + schritte;
    }
    
    public final void setzeNeuePostion( double x, double y, double z ) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    // public methods
    public void setFarbe(String farbe) {
        this.farbe = farbe;
    }
    
    public String getFarbe() {
        return this.farbe;        
    }
    
    public String getPosition() {
        return "x-Koordinate " + this.x + " y-Koordinate " + this.y + " z-Koordinate " + this.z;
    }
            
    public void getMetaDaten() {
        System.out.println("Art: " + this.istEin());
        System.out.println("Lage: " + this.getPosition());
        System.out.println("Parameter: " + this.getParameter());
        System.out.println("Volumen: " + this.berechneVolumen());
        System.out.println("Oberfläche: " + this.berechneOberflaeche());
        System.out.println("Farbe: " + this.getFarbe());
    }
    
    public double getX() {
        return this.x;
    }
    
    public double getY() {
        return this.y;
    }
    
    public double getZ() {
        return this.z;
    }
}