generated from mate-academy/jv-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
82 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
package core.basesyntax; | ||
|
||
public abstract class Figure { | ||
abstract class Figure { | ||
protected String color; | ||
|
||
public Figure(String color) { | ||
this.color = color; | ||
} | ||
|
||
public abstract double getArea(); | ||
|
||
public abstract void draw(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
package core.basesyntax; | ||
|
||
public class IsoscelesTrapezoid extends Figure { | ||
private final double base1; | ||
private final double base2; | ||
private final double height; | ||
class IsoscelesTrapezoid extends Figure { | ||
private double topBase; | ||
private double bottomBase; | ||
private double height; | ||
|
||
public IsoscelesTrapezoid(String color, double base1, double base2, double height) { | ||
public IsoscelesTrapezoid(String color, double topBase, double bottomBase, double height) { | ||
super(color); | ||
this.base1 = base1; | ||
this.base2 = base2; | ||
this.topBase = topBase; | ||
this.bottomBase = bottomBase; | ||
this.height = height; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return 0.5 * (base1 + base2) * height; | ||
return 0.5 * (topBase + bottomBase) * height; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: trapezoid, area: " + getArea() + " sq. units, base1: " + base1 | ||
+ " units, base2: " + base2 + " units, height: " | ||
+ height + " units, color: " + color); | ||
|
||
System.out.println("IsoscelesTrapezoid [color=" + | ||
color + ", topBase=" + | ||
topBase + ", bottomBase=" + | ||
bottomBase + ", height=" + | ||
height + ", area=" + getArea() + "]"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
package core.basesyntax; | ||
|
||
public class Rectangle extends Figure { | ||
private final double length; | ||
private final double width; | ||
class Rectangle extends Figure { | ||
private double width; | ||
private double height; | ||
|
||
public Rectangle(String color, double length, double width) { | ||
public Rectangle(String color, double width, double height) { | ||
super(color); | ||
this.length = length; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return length * width; | ||
return width * height; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: rectangle, area: " + getArea() | ||
+ " sq. units, length: " + length + " units, width: " | ||
+ width + " units, color: " + color); | ||
System.out.println("Rectangle [color=" + | ||
color + ", width=" + width + | ||
", height=" + height + | ||
", area=" + getArea() + "]"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package core.basesyntax; | ||
|
||
public class Square extends Figure { | ||
private final double side; | ||
class Square extends Figure { | ||
private double sideLength; | ||
|
||
public Square(String color, double side) { | ||
public Square(String color, double sideLength) { | ||
super(color); | ||
this.side = side; | ||
this.sideLength = sideLength; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return side * side; | ||
return sideLength * sideLength; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: square, area: " + getArea() + " sq. units, side: " + side | ||
+ " units, color: " + color); | ||
|
||
System.out.println("Square [color=" + | ||
color + ", sideLength=" + | ||
sideLength + ", area=" + | ||
getArea() + "]"); | ||
} | ||
} | ||
|