Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
tungvv318 authored Oct 15, 2018
1 parent 96cbaaf commit 0bb575d
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Lab06/Circle.java
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);
}
}
33 changes: 33 additions & 0 deletions Lab06/Diagram.java
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");
}
}
23 changes: 23 additions & 0 deletions Lab06/Layer.java
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");
}
}
25 changes: 25 additions & 0 deletions Lab06/Point.java
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;
}
}
49 changes: 49 additions & 0 deletions Lab06/Rectangle.java
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);
}
}
28 changes: 28 additions & 0 deletions Lab06/Shape.java
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;
}

}
11 changes: 11 additions & 0 deletions Lab06/Square.java
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);
}
}
24 changes: 24 additions & 0 deletions Lab06/TestDriver.java
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());
}
}
64 changes: 64 additions & 0 deletions Lab06/Triangle.java
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);
}
}

0 comments on commit 0bb575d

Please sign in to comment.