java-scuola/NetBeans Projects/shape/src/shape/Rectangle.java

58 lines
1.1 KiB
Java
Raw Normal View History

2023-05-03 19:05:50 +02:00
package shape;
/**
*
2023-05-04 16:18:44 +02:00
* @author radaelli11353
2023-05-03 19:05:50 +02:00
*/
public class Rectangle extends Shape {
2023-05-04 16:18:44 +02:00
private double x;
private double y;
private double w;
private double h;
2023-05-03 19:05:50 +02:00
2023-05-04 16:18:44 +02:00
public Rectangle(double x, double y, double w, double h) {
2023-05-03 19:05:50 +02:00
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
@Override
2023-05-04 16:18:44 +02:00
public double width() {
2023-05-03 19:05:50 +02:00
return w;
}
@Override
2023-05-04 16:18:44 +02:00
public double height() {
2023-05-03 19:05:50 +02:00
return h;
}
@Override
2023-05-04 16:18:44 +02:00
public double posX() {
2023-05-03 19:05:50 +02:00
return x;
}
@Override
2023-05-04 16:18:44 +02:00
public double posY() {
2023-05-03 19:05:50 +02:00
return y;
}
@Override
public int hashCode() {
int hash = 5;
hash = 37 * hash + this.x;
hash = 37 * hash + this.y;
hash = 37 * hash + this.w;
hash = 37 * hash + this.h;
return hash;
}
@Override
public boolean equals(Object o) {
if (o == null) return false;
if (getClass() != o.getClass()) return false;
Rectangle r = (Rectangle) o;
2023-05-04 16:18:44 +02:00
return Double.compare(r, r.w) && Double.compare(h, r.h) && Double.compare(x, r.x) && Double.compare(y, r.y);
}
2023-05-03 19:05:50 +02:00
}