Commit aa1ba37e authored by MostafaRahmati's avatar MostafaRahmati

javadoc added

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