Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package at.ac.campuswien.shape;
- public class Rectangle extends Shape{
- private int x1;
- private int y1;
- private int x2;
- private int y2;
- private static int count;
- public Rectangle(int x1, int y1, int x2, int y2){
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- count++;
- }
- public Rectangle(int x1, int y1, int x2, int y2, String color,String name, boolean stroke) {
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
- super.setColor(color);
- super.setName(name);
- super.setStroked(stroke);
- count++;
- }
- public Rectangle(int width, int height, String color,String name, boolean stroke){
- this.x1 = 0;
- this.y1 = 0;
- this.x2 = width;
- this.y2 = height;
- super.setColor(color);
- super.setName(name);
- super.setStroked(stroke);
- count++;
- }
- public Rectangle(){
- this(0,0,0,0);
- }
- public void Move(int deltax, int deltay){
- this.x1 = this.x1 + deltax;
- this.x2 = this.x2 + deltax;
- this.y1 = this.y1 + deltay;
- this.y2 = this.y2 + deltay;
- }
- public boolean isInside(int x, int y){
- boolean ergebnis = false;
- if(x >= this.x1 && x <= this.x2){
- if(y >= this.y1 && y <= this.y2)
- ergebnis = true;
- }
- return ergebnis;
- }
- public double getWidth(){
- double width = x2-x1;
- return width;
- }
- public static int getCount(){
- return count;
- }
- public double getHeight(){
- return y2-y1;
- }
- public double getArea()
- {
- return getHeight()*getWidth();
- }
- public double getPerimeter(){
- return 2*(getWidth()+getHeight());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement