added ws202425 courses
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
package figure;
|
||||
|
||||
public class Circ extends Square{
|
||||
private int radius;
|
||||
|
||||
public Circ(){
|
||||
super();
|
||||
this.radius = 1;
|
||||
}
|
||||
|
||||
public Circ(int initX, int initY){
|
||||
super(initX, initY);
|
||||
this.radius = 1;
|
||||
}
|
||||
|
||||
public Circ(int initX, int initY, int initEdgeLen){
|
||||
super(initX, initY);
|
||||
this.radius = initEdgeLen;
|
||||
}
|
||||
|
||||
public int getSize(){ // Größe von Kreis? was gemeint?
|
||||
return this.radius;
|
||||
}
|
||||
|
||||
public void setSize(int newRadius){
|
||||
this.radius = newRadius;
|
||||
}
|
||||
|
||||
public int getArea(){
|
||||
return this.radius* this.radius * 3 ; // 3 für pi
|
||||
}
|
||||
|
||||
public int getUmfang(){
|
||||
return (2 * (int) Math.PI * this.radius); // pi durch 3 abgekürzt
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
package figure;
|
||||
|
||||
public class Circle extends Figure{
|
||||
private int radius;
|
||||
|
||||
public Circle(){
|
||||
super();
|
||||
this.radius = 1;
|
||||
}
|
||||
|
||||
public Circle(int initEdgeLen){
|
||||
super();
|
||||
this.radius = initEdgeLen;
|
||||
}
|
||||
|
||||
|
||||
public Circle(int initX, int initY){
|
||||
super(initX, initY);
|
||||
this.radius = 1;
|
||||
}
|
||||
|
||||
public Circle(int initX, int initY, int initEdgeLen){
|
||||
super(initX, initY);
|
||||
this.radius = initEdgeLen;
|
||||
}
|
||||
|
||||
public int getSize(){ // Größe von Kreis? was gemeint?
|
||||
return this.radius;
|
||||
}
|
||||
|
||||
public void setSize(int newRadius){
|
||||
this.radius = newRadius;
|
||||
}
|
||||
|
||||
public int getArea(){
|
||||
return this.radius* this.radius * 3 ; // 3 für pi
|
||||
}
|
||||
|
||||
public int getUmfang(){
|
||||
return (2 * 3* this.radius); // pi durch 3 abgekürzt
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
package figure;
|
||||
|
||||
public abstract class Figure{
|
||||
private Point point;
|
||||
|
||||
protected Figure(){
|
||||
point = new Point();
|
||||
}
|
||||
|
||||
protected Figure(int initX, int initY){
|
||||
point = new Point(initX, initY);
|
||||
}
|
||||
|
||||
|
||||
public void moveTo(int new_x, int new_y){
|
||||
this.point.moveTo(new_x, new_y);
|
||||
}
|
||||
|
||||
public int getX(){
|
||||
return this.point.getX();
|
||||
}
|
||||
|
||||
public int getY(){
|
||||
return this.point.getY();
|
||||
}
|
||||
|
||||
abstract public int getSize();
|
||||
abstract public void setSize(int newSize);
|
||||
abstract public int getArea();
|
||||
abstract public int getUmfang();
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Point.class
|
||||
*
|
||||
*/
|
||||
package figure;
|
||||
|
||||
public class Point{
|
||||
private int x, y;
|
||||
|
||||
Point(){
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
}
|
||||
|
||||
Point(int x, int y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void moveTo(int new_x, int new_y){
|
||||
this.x = new_x;
|
||||
this.y = new_y;
|
||||
}
|
||||
|
||||
public int getX(){
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY(){
|
||||
return this.y;
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
||||
package figure;
|
||||
|
||||
public class Square extends Figure{
|
||||
private int size;
|
||||
|
||||
public Square(){
|
||||
super();
|
||||
this.size = 1;
|
||||
}
|
||||
|
||||
public Square(int initX, int initY){
|
||||
super(initX, initY);
|
||||
this.size = 1;
|
||||
}
|
||||
|
||||
public Square(int initX, int initY, int initEdgeLen){
|
||||
super(initX, initY);
|
||||
this.size = initEdgeLen;
|
||||
}
|
||||
|
||||
|
||||
public Square(Square original){
|
||||
super(original.getX(), original.getY());
|
||||
this.size = original.size;
|
||||
}
|
||||
|
||||
|
||||
public int getSize(){
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public void setSize(int newSize){
|
||||
this.size = newSize;
|
||||
}
|
||||
|
||||
public int getArea(){
|
||||
return this.size* this.size;
|
||||
}
|
||||
|
||||
public int getUmfang(){
|
||||
return (4 * this.size);
|
||||
}
|
||||
|
||||
public void show(){
|
||||
System.out.println("Size: "+ this.size + ", Area: " + this.getArea() + ", Umfang: " + this.getUmfang());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
package figure;
|
||||
|
||||
public class TestFigure{
|
||||
|
||||
public static void main(String[] args){
|
||||
Square square = new Square(1,1,5); // links größer oder gleich (Hierachie)
|
||||
System.out.println(square.getArea());
|
||||
square.show();
|
||||
Square squareCopy = new Square(square);
|
||||
squareCopy.show();
|
||||
//System.out.println(square == squareCopy);
|
||||
//System.out.println(square.equals(squareCopy));
|
||||
|
||||
System.out.println(""+ square.toString() + " "+squareCopy.toString());
|
||||
System.out.println("toString: " + square.toString() == squareCopy.toString());
|
||||
|
||||
squareCopy.setSize(10);
|
||||
squareCopy.show();
|
||||
|
||||
Circle circle = new Circle(4,5,3);
|
||||
System.out.println(circle.getX());
|
||||
System.out.println(circle.getArea());
|
||||
Circ circ = new Circ(4,5,3);
|
||||
System.out.println(circ.getX());
|
||||
System.out.println(circ.getArea());
|
||||
|
||||
/*
|
||||
* statischer Dynamischer Type? // links größer oder gleich (Hierachie)
|
||||
*/
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user