Commit b792a00c authored by MostafaRahmati's avatar MostafaRahmati

final version

parents
Pipeline #5952 canceled with stages
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../:\Users\Mostafa\Desktop\APLabSession5\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/APLabSession5.iml" filepath="$PROJECT_DIR$/APLabSession5.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import java.util.Objects;
public class Circle {
private int radius;
public Circle(int radius) {
this.radius = radius;
}
public int getRadius() {
return radius;
}
public double calculatePerimeter(){
return 2*3.14*radius;
}
public double calculateArea(){
return 3.14*radius*radius;
}
public void draw(){
System.out.println("Type: Circle\nPerimeter: "+calculatePerimeter()+"\nArea: "+calculateArea());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Circle)) return false;
Circle circle = (Circle) o;
return getRadius() == circle.getRadius();
}
@Override
public int hashCode() {
return Objects.hash(getRadius());
}
@Override
public String toString() {
return "Type: Circle\nRadius: "+radius;
}
}
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.addCircle(circle1);
paint.addCircle(circle2);
paint.addRectangle(rect1);
paint.addRectangle(rect2);
paint.addRectangle(rect3);
paint.addTriangle(tri1);
paint.addTriangle(tri2);
paint.drawAll();
paint.printAll();
}
}
import java.util.ArrayList;
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<>();
}
public void addTriangle(Triangle triangle){
triangles.add(triangle);
}
public void addRectangle(Rectangle rectangle){
rectangles.add(rectangle);
}
public void addCircle(Circle circle){
circles.add(circle);
}
public void drawAll(){
for (Triangle triangle : triangles) {
triangle.draw();
}
for (Rectangle rectangle : rectangles) {
rectangle.draw();
}
for (Circle circle : circles) {
circle.draw();
}
}
public void printAll(){
for (Triangle triangle : triangles) {
System.out.println(triangle.toString());
}
for (Rectangle rectangle : rectangles) {
System.out.println(rectangle.toString());
}
for (Circle circle : circles) {
System.out.println(circle.toString());
}
}
}
import java.util.ArrayList;
import java.util.Objects;
public class Rectangle {
private ArrayList<Integer> sides;
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);
}
public ArrayList<Integer> getSides() {
return sides;
}
public boolean isSquare() {
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);
}
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;
else
return b*c;
}
public void draw(){
System.out.println("Type: Rectangle\nPerimeter: "+calculatePerimeter()+"\nArea: "+calculateArea());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Rectangle)) return false;
Rectangle rectangle = (Rectangle) o;
return getSides().equals(rectangle.getSides());
}
@Override
public int hashCode() {
return Objects.hash(getSides());
}
@Override
public String toString() {
return "Type: Rectangle\nSides=" + sides;
}
}
import java.util.ArrayList;
import java.util.Objects;
public class Triangle {
private ArrayList<Integer> sides;
public Triangle(int a, int b, int c){
sides=new ArrayList<>();
sides.add(a);
sides.add(b);
sides.add(c);
}
public ArrayList<Integer> getSides() {
return sides;
}
public boolean isEquilateral() {
double a, b, c;
a = sides.get(0);
b = sides.get(1);
c = sides.get(2);
return (a == b && b == c);
}
public double calculatePerimeter(){
double a, b, c;
a = sides.get(0);
b = sides.get(1);
c = sides.get(2);
return a+b+c;
}
public double calculateArea(){
double a, b, c,s;
a = sides.get(0);
b = sides.get(1);
c = sides.get(2);
s=calculatePerimeter()/2;
return Math.sqrt(s*(s-a)*(s-b)*(s-c));
}
public void draw(){
System.out.println("Type: Triangle\nPerimeter: "+calculatePerimeter()+"\nArea: "+calculateArea());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Triangle)) return false;
Triangle triangle = (Triangle) o;
return getSides().equals(triangle.getSides());
}
@Override
public int hashCode() {
return Objects.hash(getSides());
}
@Override
public String toString() {
return "Type: Triangle\nSides=" + sides;
}
}
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