Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed AP-LabManual-Session4.zip
Binary file not shown.
Binary file removed AP-LabManual-Session5.pdf
Binary file not shown.
67 changes: 67 additions & 0 deletions AmirparsaSalmankhah/Paint/src/com/company/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.company;

/**
* Represents a circle.
* @author Amirparsa Salmnakhah
* @version 1.0.0
*/
public class Circle extends Shape{
//radius
private double radius;

/**
* Constructor with a paramter.
* @param radius Radius of the circle
*/
public Circle(double radius) {
this.radius = radius;
}

/**
* Gets radius of the circle
* @return Radius of the circle
*/
public double getRadius() {
return radius;
}

/**
* Calculates area of the shape
* @return Area of the shape
*/
@Override
public double calculateArea() {
return Math.pow(radius, 2) * Math.PI;
}

/**
* Calculates perimeter of the shape.
* @return Perimeter of the shape
*/
@Override
public double calculatePerimeter() {
return 2 * radius * Math.PI;
}

/**
* Draws the circle
*/
@Override
public void draw() {
System.out.println("Circle ");
super.draw();
}

/**
* Checks the equality between the circle and another object.
* @param o Another object
* @return true if they are equal and false if not.
*/
@Override
public boolean equals(Object o){
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Circle circle = (Circle) o;
return radius == circle.radius;
}
}
32 changes: 32 additions & 0 deletions AmirparsaSalmankhah/Paint/src/com/company/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.company;

/**
* This is a class for testing our painting.
* @author Amirparsa Salmankhah
* @version 1.0.0
*/
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);
Paint paint = new Paint();
paint.addShape(circle1);
paint.addShape(circle2);
paint.addShape(rect1);
paint.addShape(rect2);
paint.addShape(rect3);
paint.addShape(tri1);
paint.addShape(tri2);
paint.drawAll();
System.out.println();
paint.printAll();
System.out.println();
paint.describeEqualSides();
}
}
56 changes: 56 additions & 0 deletions AmirparsaSalmankhah/Paint/src/com/company/Paint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.company;

import java.util.ArrayList;

/**
* Represents a class for painting shapes.
* @author Amirparsa Salmankhah
* @version 1.0.0
*/
public class Paint {
//list of shapes
private ArrayList<Shape> shapes;

/**
* Constructor with no parameter.
*/
public Paint() {
shapes = new ArrayList<>();
}

/**
* Adds a shape to list of the shapes.
* @param shape The shape
*/
public void addShape(Shape shape) {
shapes.add(shape);
}

/**
* Draws all of the shapes
*/
public void drawAll() {
for(Shape shape : shapes)
shape.draw();
}

/**
* Prints all of the shapes
*/
public void printAll() {
for(Shape shape : shapes)
System.out.println(shape);
}

/**
* Prints all of equal side shapes.
*/
public void describeEqualSides(){
for(Shape shape : shapes){
if(shape instanceof Rectangle && ((Rectangle) shape).isSquare())
System.out.println(shape);
else if(shape instanceof Triangle && ((Triangle) shape).isEquilateral())
System.out.println(shape);
}
}
}
45 changes: 45 additions & 0 deletions AmirparsaSalmankhah/Paint/src/com/company/Polygon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.company;

import java.util.ArrayList;
import java.util.Collections;

/**
* Represents a polygon.
* @author Amirparsa Salmankhah
* @version 1.0.0
*/
abstract public class Polygon extends Shape {
//sides
private ArrayList<Double> sides;

/**
* Constructor with var args parameters.
* @param sides Some double numbers.(sides of the polygon)
*/
public Polygon(double... sides) {
this.sides = new ArrayList<>();
for (double side : sides)
this.sides.add(side);
Collections.sort(this.sides);
}

/**
* Gets list of sides.
* @return List of sides
*/
public ArrayList<Double> getSides() {
return sides;
}

/**
* Returns an string containing polygon details.
* @return polygon details
*/
@Override
public String toString() {
String str = super.toString() + " ";
for (int i = 0; i < sides.size(); i++)
str = str + "Side" + (i + 1) + ":" + sides.get(i) + " ";
return str;
}
}
75 changes: 75 additions & 0 deletions AmirparsaSalmankhah/Paint/src/com/company/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.company;

/**
* Represents a rectangle.
* @author Amirparsa Salmankhah
* @version 1.0.0
*/
public class Rectangle extends Polygon {

/**
* Constructor with 4 parameters.
* @param side1 first side
* @param side2 second side
* @param side3 third side
* @param side4 forth side
*/
public Rectangle(double side1, double side2, double side3, double side4) {
super(side1, side2, side3, side4);
}

/**
* Checks if the rectangle is an square.
* @return true if it is and false if not.
*/
public boolean isSquare() {
boolean check = true;
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 4; j++)
if (!getSides().get(i).equals(getSides().get(j))) {
check = false;
break;
}
return check;
}

/**
* Calculates area of the shape
* @return Area of the shape
*/
@Override
public double calculateArea() {
return getSides().get(0) * getSides().get(2);
}

/**
* Calculates perimeter of the shape.
* @return Perimeter of the shape
*/
@Override
public double calculatePerimeter() {
return 2 * (getSides().get(0) + getSides().get(2));
}

/**
* Draws the rectangle
*/
@Override
public void draw() {
System.out.println("Rectangle ");
super.draw();
}

/**
* Checks equality between the rectangle and another object.
* @param o Another object
* @return true if they are equal and false if not.
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Rectangle rectangle = (Rectangle) o;
return rectangle.getSides().get(0).equals(getSides().get(0)) && rectangle.getSides().get(2).equals(getSides().get(2));
}
}
47 changes: 47 additions & 0 deletions AmirparsaSalmankhah/Paint/src/com/company/Shape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.company;

/**
* Represents a shape.
* @author Amirparsa Salmankhah
* @version 1.0.0
*/
abstract public class Shape {
/**
* Calculates area of the shape.
* @return Area of the shape
*/
abstract public double calculateArea();

/**
* Calculates perimeter of the shape.
* @return Perimeter of the shape
*/
abstract public double calculatePerimeter();

/**
* Draws the shape
*/
public void draw(){
System.out.println("Area: " + calculateArea() + " Perimeter: " + calculatePerimeter());
}

/**
* Checks equality between the shape and another object
* @param o Another object
* @return true if they are equal and false if not
*/
abstract public boolean equals(Object o);

/**
* returns an string containing shape details.
* @return shape details
*/
@Override
public String toString() {
if(this instanceof Triangle)
return "Triangle";
else if(this instanceof Rectangle)
return "Rectangle";
return "Circle: Radius:" + ((Circle)this).getRadius();
}
}
67 changes: 67 additions & 0 deletions AmirparsaSalmankhah/Paint/src/com/company/Triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.company;

/**
* Represents a triangle.
* @author Amirparsa Salmankhah
* @version 1.0.0
*/
public class Triangle extends Polygon{

/**
* Constructor with 3 parameters.
* @param side1 first side
* @param side2 second side
* @param side3 third side
*/
public Triangle(double side1, double side2, double side3) {
super(side1,side2,side3);
}

/**
* Checks if the triangle is equilateral.
* @return true if it is and false if not.
*/
public boolean isEquilateral() {
return getSides().get(0).equals(getSides().get(1)) && getSides().get(0).equals(getSides().get(2)) && getSides().get(1).equals(getSides().get(2));
}

/**
* Calculates area of the shape
* @return Area of the shape
*/
@Override
public double calculateArea(){
double p = calculatePerimeter() / 2;
return Math.sqrt(p * (p - getSides().get(0)) * (p - getSides().get(1)) * (p - getSides().get(2)));
}

/**
* Calculates perimeter of the shape.
* @return Perimeter of the shape
*/
@Override
public double calculatePerimeter() {
return getSides().get(0) + getSides().get(1) + getSides().get(2);
}

/**
* Draws the triangle.
*/
@Override
public void draw() {
System.out.println("Triangle ");
super.draw();
}

/**
* Checks the equality between the triangle and another object.
* @param o Another object
* @return true if they are equal and false if not.
*/
public boolean equals(Object o){
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Triangle triangle = (Triangle) o;
return triangle.getSides().get(0).equals(getSides().get(0)) && triangle.getSides().get(1).equals(getSides().get(1)) && triangle.getSides().get(2).equals(getSides().get(2));
}
}
Binary file added AmirparsaSalmankhah/Vote/JalaliCalendar-1.3.1.jar
Binary file not shown.
Loading