├── .classpath
├── .gitignore
├── .project
└── src
├── application
└── Program.java
└── model
├── entities
├── AbstractShape.java
├── Circle.java
├── Rectangle.java
└── Shape.java
└── enums
└── Color.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | # Eclipse
26 | .settings/
27 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | course
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/application/Program.java:
--------------------------------------------------------------------------------
1 | package application;
2 |
3 | import model.entities.AbstractShape;
4 | import model.entities.Circle;
5 | import model.entities.Rectangle;
6 | import model.enums.Color;
7 |
8 | public class Program {
9 |
10 | public static void main(String[] args) {
11 |
12 | AbstractShape s1 = new Circle(Color.BLACK, 2.0);
13 | AbstractShape s2 = new Rectangle(Color.WHITE, 3.0, 4.0);
14 |
15 | System.out.println("Circle color: " + s1.getColor());
16 | System.out.println("Circle area: " + String.format("%.3f", s1.area()));
17 | System.out.println("Rectangle color: " + s2.getColor());
18 | System.out.println("Rectangle area: " + String.format("%.3f", s2.area()));
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/model/entities/AbstractShape.java:
--------------------------------------------------------------------------------
1 | package model.entities;
2 |
3 | import model.enums.Color;
4 |
5 | public abstract class AbstractShape implements Shape {
6 |
7 | private Color color;
8 |
9 | public AbstractShape(Color color) {
10 | this.color = color;
11 | }
12 |
13 | public Color getColor() {
14 | return color;
15 | }
16 |
17 | public void setColor(Color color) {
18 | this.color = color;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/model/entities/Circle.java:
--------------------------------------------------------------------------------
1 | package model.entities;
2 |
3 | import model.enums.Color;
4 |
5 | public class Circle extends AbstractShape {
6 |
7 | private Double radius;
8 |
9 | public Circle(Color color, Double radius) {
10 | super(color);
11 | this.radius = radius;
12 | }
13 |
14 | public Double getRadius() {
15 | return radius;
16 | }
17 |
18 | public void setRadius(Double radius) {
19 | this.radius = radius;
20 | }
21 |
22 | @Override
23 | public double area() {
24 | return Math.PI * radius * radius;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/model/entities/Rectangle.java:
--------------------------------------------------------------------------------
1 | package model.entities;
2 |
3 | import model.enums.Color;
4 |
5 | public class Rectangle extends AbstractShape {
6 |
7 | private Double width;
8 | private Double height;
9 |
10 | public Rectangle(Color color, Double width, Double height) {
11 | super(color);
12 | this.width = width;
13 | this.height = height;
14 | }
15 |
16 | public Double getWidth() {
17 | return width;
18 | }
19 |
20 | public void setWidth(Double width) {
21 | this.width = width;
22 | }
23 |
24 | public Double getHeight() {
25 | return height;
26 | }
27 |
28 | public void setHeight(Double height) {
29 | this.height = height;
30 | }
31 |
32 | @Override
33 | public double area() {
34 | return width * height;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/model/entities/Shape.java:
--------------------------------------------------------------------------------
1 | package model.entities;
2 |
3 | public interface Shape {
4 |
5 | double area();
6 | }
7 |
--------------------------------------------------------------------------------
/src/model/enums/Color.java:
--------------------------------------------------------------------------------
1 | package model.enums;
2 |
3 | public enum Color {
4 | BLACK,
5 | WHITE;
6 | }
7 |
--------------------------------------------------------------------------------