Commit aa1ba37e authored by MostafaRahmati's avatar MostafaRahmati

javadoc added

parent b792a00c
Pipeline #5953 failed with stages
import java.util.Objects;
/**
* class for circle
*/
public class Circle {
private int radius;
/**
* constructor of the circle
* @param radius of the circle
*/
public Circle(int radius) {
this.radius = radius;
}
/**
* @return radius of this circle
*/
public int getRadius() {
return radius;
}
/**
* @return perimeter of this circle
*/
public double calculatePerimeter(){
return 2*3.14*radius;
}
/**
* @return area of this circle
*/
public double calculateArea(){
return 3.14*radius*radius;
}
/**
* @return simulation for drawing a circle
*/
public void draw(){
System.out.println("Type: Circle\nPerimeter: "+calculatePerimeter()+"\nArea: "+calculateArea());
System.out.println("Type: Circle\nPerimeter: " + calculatePerimeter() + "\nArea: " + calculateArea());
}
@Override
......
......@@ -2,11 +2,11 @@ public class Main {
public static void main(String[] args) {
Circle circle1 = new Circle(19);
Circle circle2 = new Circle(3);
Rectangle rect1 = new Rectangle(1,4,1,4);
Rectangle rect2 = new Rectangle(8,5,8,5);
Rectangle rect3 = new Rectangle(6,6,6,6);
Triangle tri1 = new Triangle(2,2,2);
Triangle tri2 = new Triangle(4,4,6);
Rectangle rect1 = new Rectangle(1, 4, 1, 4);
Rectangle rect2 = new Rectangle(8, 5, 8, 5);
Rectangle rect3 = new Rectangle(6, 6, 6, 6);
Triangle tri1 = new Triangle(2, 2, 2);
Triangle tri2 = new Triangle(4, 4, 6);
Paint paint = new Paint();
paint.addCircle(circle1);
paint.addCircle(circle2);
......
import java.util.ArrayList;
/**
* paint class
*/
public class Paint {
private ArrayList<Triangle> triangles;
private ArrayList<Rectangle> rectangles;
private ArrayList<Circle> circles;
public Paint(){
triangles= new ArrayList<>();
rectangles=new ArrayList<>();
circles=new ArrayList<>();
/**
* paint constructor
*/
public Paint() {
triangles = new ArrayList<>();
rectangles = new ArrayList<>();
circles = new ArrayList<>();
}
public void addTriangle(Triangle triangle){
/**
* @param triangle which is intended to be added
*/
public void addTriangle(Triangle triangle) {
triangles.add(triangle);
}
public void addRectangle(Rectangle rectangle){
/**
* @param rectangle which is intended to be added
*/
public void addRectangle(Rectangle rectangle) {
rectangles.add(rectangle);
}
public void addCircle(Circle circle){
/**
* @param circle which is intended to be added
*/
public void addCircle(Circle circle) {
circles.add(circle);
}
public void drawAll(){
/**
* draws all shapes
*/
public void drawAll() {
for (Triangle triangle : triangles) {
triangle.draw();
}
......@@ -30,7 +53,10 @@ public class Paint {
}
}
public void printAll(){
/**
* prints all shapes
*/
public void printAll() {
for (Triangle triangle : triangles) {
System.out.println(triangle.toString());
}
......
import java.util.ArrayList;
import java.util.Objects;
/**
* rectangle class
*/
public class Rectangle {
/**
* sides list for rect
*/
private ArrayList<Integer> sides;
public Rectangle(int a, int b, int c, int d){
sides=new ArrayList<>();
/**
* constructor for rectangle
* @param a side1
* @param b side2
* @param c side3
* @param d side4
*/
public Rectangle(int a, int b, int c, int d) {
sides = new ArrayList<>();
sides.add(a);
sides.add(b);
sides.add(c);
sides.add(d);
}
/**
* @return sides of rect
*/
public ArrayList<Integer> getSides() {
return sides;
}
/**
* @return boolean value of being square
*/
public boolean isSquare() {
double a, b, c,d;
double a, b, c, d;
a = sides.get(0);
b = sides.get(1);
c = sides.get(2);
d = sides.get(3);
return (a == b && b == c&& c==d);
return (a == b && b == c && c == d);
}
public double calculatePerimeter(){
return (double) sides.get(0)+sides.get(1)+sides.get(2)+sides.get(3);
/**
* @return perimeter of rect
*/
public double calculatePerimeter() {
return (double) sides.get(0) + sides.get(1) + sides.get(2) + sides.get(3);
}
public double calculateArea(){
int a,b,c;
a=sides.get(0);
b=sides.get(1);
c=sides.get(2);
if (a==b)
return a*c;
else if (b==c)
return a*b;
/**
* @return area of rect
*/
public double calculateArea() {
int a, b, c;
a = sides.get(0);
b = sides.get(1);
c = sides.get(2);
if (a == b)
return a * c;
else if (b == c)
return a * b;
else
return b*c;
return b * c;
}
public void draw(){
System.out.println("Type: Rectangle\nPerimeter: "+calculatePerimeter()+"\nArea: "+calculateArea());
/**
* drawing simulation for this shape
*/
public void draw() {
System.out.println("Type: Rectangle\nPerimeter: " + calculatePerimeter() + "\nArea: " + calculateArea());
}
@Override
......
import java.util.ArrayList;
import java.util.Objects;
/**
* triangle class
*/
public class Triangle {
private ArrayList<Integer> sides;
/**
* constructor for triangle
* @param a first side
* @param b second side
* @param c third side
*/
public Triangle(int a, int b, int c){
sides=new ArrayList<>();
sides.add(a);
sides.add(b);
sides.add(c);
}
/**
* @return sides of triangle
*/
public ArrayList<Integer> getSides() {
return sides;
}
/**
* @return boolean value of being equilateral
*/
public boolean isEquilateral() {
double a, b, c;
a = sides.get(0);
......@@ -22,6 +38,9 @@ public class Triangle {
return (a == b && b == c);
}
/**
* @return perimeter of triangle
*/
public double calculatePerimeter(){
double a, b, c;
a = sides.get(0);
......@@ -30,6 +49,9 @@ public class Triangle {
return a+b+c;
}
/**
* @return area of triangle
*/
public double calculateArea(){
double a, b, c,s;
a = sides.get(0);
......@@ -39,6 +61,9 @@ public class Triangle {
return Math.sqrt(s*(s-a)*(s-b)*(s-c));
}
/**
* drawing simulation for this shape
*/
public void draw(){
System.out.println("Type: Triangle\nPerimeter: "+calculatePerimeter()+"\nArea: "+calculateArea());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment