The 5th and 6th condition got me so confused. Can you help me with this please? Any help will be appreciated!
package com.codegym.task.task24.task2404;
/*
Refactoring Rectangle
*/
public class Solution {
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(1, 2, 3, 4);
//System.out.println(getHeight(rectangle));
//System.out.println(getWidth(rectangle));
/////////////////////expected//////////////////
System.out.println(getHeight(rectangle.castToHasHeight()));
System.out.println(getWidth(rectangle.castToHasWidth()));
}
public static double getHeight(HasHeight rectangle) {
return rectangle.castToHasHeight();
}
public static double getWidth(HasWidth rectangle) {
return rectangle.castToHasWidth();
}
public static class Rectangle {
private Point point1;
private Point point2;
public Rectangle(double x1, double y1, double x2, double y2) {
point1 = new Point(x1, y1);
point2 = new Point(x2, y2);
}
public HasHeight castToHasHeight() {
class innerHeight implements HasHeight {
@Override
public double castToHasHeight() {
return Math.abs(point1.getY() - point2.getY()) ;
}
}
return new innerHeight();
//return Math.abs(point1.getY() - point2.getY());
}
public HasWidth castToHasWidth() {
class innerWidth implements HasWidth {
@Override
public double castToHasWidth() {
return Math.abs(point1.getX() - point2.getX());
}
}
return new innerWidth();
}
}
}