forked from phuctd99/TrainnerDic
-
Notifications
You must be signed in to change notification settings - Fork 0
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
305 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
public class Circle extends Shape { | ||
private Point center; | ||
private int radius = 1; | ||
private final double PI = 3.14; | ||
|
||
public Circle() {} | ||
|
||
public Circle(Point center, int radius) { | ||
super(); | ||
this.center = center; | ||
this.radius = radius; | ||
} | ||
|
||
public Circle(String color, boolean filled, Point center, int radius) { | ||
super(color, filled); | ||
this.center = center; | ||
this.radius = radius; | ||
} | ||
|
||
public Point getCenter() { | ||
return center; | ||
} | ||
|
||
public void setCenter(Point center) { | ||
this.center = center; | ||
} | ||
|
||
public int getRadius() { | ||
return radius; | ||
} | ||
|
||
public void setRadius(int radius) { | ||
this.radius = radius; | ||
} | ||
|
||
public double getArea() { | ||
return PI * radius * radius; | ||
} | ||
|
||
public double getPerimeter() { | ||
return 2 * PI * radius; | ||
} | ||
|
||
public void move(int x, int y) { | ||
center.setX(this.center.getX() + x); | ||
center.setY(this.center.getY() + y); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
gitimport java.util.ArrayList; | ||
public class Diagram { | ||
private int width = 300; | ||
private int height = 300; | ||
|
||
public Diagram() {} | ||
|
||
public Diagram(int width, int height) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
private ArrayList<Layer> listLayer = new ArrayList<>(); | ||
|
||
public ArrayList<Layer> getListLayer() { | ||
return listLayer; | ||
} | ||
|
||
public void setListLayer(ArrayList<Layer> listLayer) { | ||
this.listLayer = listLayer; | ||
} | ||
|
||
public void removeAllCircle() { | ||
int sizeListLayer = listLayer.size(); | ||
for (int i = 0; i < sizeListLayer; i++) { | ||
for (int j = 0; j < listLayer.get(i).getListShape().size(); j++) { | ||
if (listLayer.get(i).getListShape().get(j) instanceof Circle) | ||
listLayer.get(i).getListShape().remove(j); | ||
} | ||
} | ||
System.out.println("Xóa thành công"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import java.util.ArrayList; | ||
|
||
public class Layer { | ||
private ArrayList<Shape> listShape = new ArrayList<>(); | ||
|
||
public ArrayList<Shape> getListShape() { | ||
return listShape; | ||
} | ||
|
||
public void setListShape(ArrayList<Shape> listShape) { | ||
this.listShape = listShape; | ||
} | ||
|
||
public void removeAllTriangle() { | ||
int sizeListShape = listShape.size(); | ||
for (int i = 0; i < sizeListShape; i++) { | ||
if (listShape.get(i) instanceof Triangle) { | ||
listShape.remove(i); | ||
} | ||
} | ||
System.out.println("Xóa thành công"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class Point { | ||
private int x; | ||
private int y; | ||
|
||
public Point(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public void setX(int x) { | ||
this.x = x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public void setY(int y) { | ||
this.y = y; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
public class Rectangle extends Shape { | ||
private Point top_left; | ||
private Point bot_right; | ||
|
||
public Rectangle() {} | ||
|
||
public Rectangle(Point top_left, Point bot_right) { | ||
super(); | ||
this.top_left = top_left; | ||
this.bot_right = bot_right; | ||
} | ||
|
||
public Rectangle(String color, boolean filled, Point top_left, Point bot_right) { | ||
super(color, filled); | ||
this.top_left = top_left; | ||
this.bot_right = bot_right; | ||
} | ||
|
||
public Point getTop_left() { | ||
return top_left; | ||
} | ||
|
||
public void setTop_left(Point top_left) { | ||
this.top_left = top_left; | ||
} | ||
|
||
public Point getBot_right() { | ||
return bot_right; | ||
} | ||
|
||
public void setBot_right(Point bot_right) { | ||
this.bot_right = bot_right; | ||
} | ||
|
||
public int getArea() { | ||
return (bot_right.getX() - top_left.getX()) * (bot_right.getY() - top_left.getY()); | ||
} | ||
|
||
public int getPerimeter() { | ||
return (bot_right.getX() - top_left.getX()) + (bot_right.getY() - top_left.getY()) * 2; | ||
} | ||
|
||
public void move(int x, int y) { | ||
top_left.setX(top_left.getX() + x); | ||
top_left.setY(top_left.getY() + y); | ||
bot_right.setX(bot_right.getX() + x); | ||
bot_right.setY(bot_right.getY() + y); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public abstract class Shape { | ||
private String color = "while"; | ||
private boolean filled; | ||
|
||
public Shape () {} | ||
|
||
public Shape(String color, boolean filled) { | ||
this.color = color; | ||
this.filled = filled; | ||
} | ||
|
||
public boolean isFilled() { | ||
return filled; | ||
} | ||
|
||
public void setFilled(boolean filled) { | ||
this.filled = filled; | ||
} | ||
|
||
public String getColor() { | ||
return color; | ||
} | ||
|
||
public void setColor(String color) { | ||
this.color = color; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class Square extends Rectangle { | ||
public Square() {} | ||
|
||
public Square(Point top_left, Point bot_right) { | ||
super(top_left, bot_right); | ||
} | ||
|
||
public Square(String color, boolean filled, Point top_left, Point bot_right) { | ||
super(color, filled, top_left, bot_right); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import java.util.ArrayList; | ||
|
||
public class TestDriver { | ||
public static void main(String[] args) { | ||
Shape circle = new Circle(new Point(10,10), 1); | ||
Shape rectangle = new Rectangle(new Point(20, 20), new Point(50,55)); | ||
Shape square = new Square(new Point(60,60), new Point(70,70)); | ||
Shape triangle = new Triangle(new Point(100,100), new Point(100,200), new Point(200,250)); | ||
Diagram diagram = new Diagram(); | ||
ArrayList<Layer> listLayer = new ArrayList<>(); | ||
diagram.setListLayer(listLayer); | ||
Layer layer = new Layer(); | ||
ArrayList<Shape> listShape = new ArrayList<>(); | ||
listShape.add(circle); | ||
listShape.add(rectangle); | ||
listShape.add(square); | ||
listShape.add(triangle); | ||
layer.setListShape(listShape); | ||
listLayer.add(layer); | ||
diagram.removeAllCircle(); | ||
diagram.getListLayer().get(0).removeAllTriangle(); | ||
System.out.println(listShape.size()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
public class Triangle extends Shape { | ||
private Point p1; | ||
private Point p2; | ||
private Point p3; | ||
|
||
public Triangle() {} | ||
|
||
public Triangle(Point p1, Point p2, Point p3) { | ||
super(); | ||
this.p1 = p1; | ||
this.p2 = p2; | ||
this.p3 = p3; | ||
} | ||
|
||
public Triangle(String color, boolean filled, Point p1, Point p2, Point p3) { | ||
super(color, filled); | ||
this.p1 = p1; | ||
this.p2 = p2; | ||
this.p3 = p3; | ||
} | ||
|
||
public Point getP1() { | ||
return p1; | ||
} | ||
|
||
public void setP1(Point p1) { | ||
this.p1 = p1; | ||
} | ||
|
||
public Point getP2() { | ||
return p2; | ||
} | ||
|
||
public void setP2(Point p2) { | ||
this.p2 = p2; | ||
} | ||
|
||
public Point getP3() { | ||
return p3; | ||
} | ||
|
||
public void setP3(Point p3) { | ||
this.p3 = p3; | ||
} | ||
|
||
public int getAre() { | ||
return Math.abs((p2.getX() - p1.getX()) * (p3.getY() - p1.getY()) - (p3.getX() - p1.getX()) * (p2.getY() - p1.getY())); | ||
} | ||
|
||
public double getPerimeter() { | ||
return Math.sqrt((p1.getX() - p2.getX()) * (p1.getX() - p2.getX()) + (p1.getY() - p2.getY()) * (p1.getY() - p2.getY())) | ||
+ Math.sqrt((p1.getX() - p3.getX()) * (p1.getX() - p3.getX()) + (p1.getY() - p3.getY()) * (p1.getY() - p3.getY())) | ||
+ Math.sqrt((p2.getX() - p3.getX()) * (p2.getX() - p3.getX()) + (p2.getY() - p3.getY()) * (p2.getY() - p3.getY())); | ||
} | ||
|
||
public void move(int x, int y) { | ||
p1.setX(p1.getX() + x); | ||
p1.setY(p1.getY() + y); | ||
p2.setX(p2.getX() + x); | ||
p2.setY(p2.getY() + y); | ||
p3.setX(p3.getX() + x); | ||
p3.setY(p3.getY() + y); | ||
} | ||
} |