diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a3417b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/out/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/libraries/JalaliCalendar_1_3_1.xml b/.idea/libraries/JalaliCalendar_1_3_1.xml new file mode 100644 index 0000000..651c19d --- /dev/null +++ b/.idea/libraries/JalaliCalendar_1_3_1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..fa53a49 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..64a7333 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workshop-2.iml b/.idea/workshop-2.iml new file mode 100644 index 0000000..e090a8c --- /dev/null +++ b/.idea/workshop-2.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/EhsanFakhraie/EhsanFakhraie b/EhsanFakhraie/EhsanFakhraie new file mode 100644 index 0000000..9aec595 --- /dev/null +++ b/EhsanFakhraie/EhsanFakhraie @@ -0,0 +1,3 @@ +Full Name: Ehsan Fakhraie +Student Number: 9831092 + diff --git a/EhsanFakhraie/libs/JalaliCalendar-1.3.1.jar b/EhsanFakhraie/libs/JalaliCalendar-1.3.1.jar new file mode 100644 index 0000000..236f2b6 Binary files /dev/null and b/EhsanFakhraie/libs/JalaliCalendar-1.3.1.jar differ diff --git a/EhsanFakhraie/src/paint/v1/Circle.java b/EhsanFakhraie/src/paint/v1/Circle.java new file mode 100644 index 0000000..f7fa119 --- /dev/null +++ b/EhsanFakhraie/src/paint/v1/Circle.java @@ -0,0 +1,44 @@ +package paint.v1; + +public class Circle { + private int radius; + + public Circle(int radius) { + this.radius = radius; + } + + public int getRadius() { + return radius; + } + public double calculatePerimeter(){ + return 2*Math.PI*radius; + } + public double calculateArea(){ + return Math.PI*radius*radius; + } + public void draw(){ + System.out.println("Circle ,"+calculatePerimeter()+","+calculateArea()); + } + + @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; + } + + @Override + public int hashCode() { + return radius; + } + + @Override + public String toString() { + return "Circle{" + + "radius=" + radius + + '}'; + } +} diff --git a/EhsanFakhraie/src/paint/v1/Main.java b/EhsanFakhraie/src/paint/v1/Main.java new file mode 100644 index 0000000..5f7b1f7 --- /dev/null +++ b/EhsanFakhraie/src/paint/v1/Main.java @@ -0,0 +1,30 @@ +package paint.v1; + +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 t1=new Triangle(2,2,2); + Triangle t2=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(t1); + paint.addTriangle(t2); + + paint.drawAll(); + paint.printAll(); + } +} diff --git a/EhsanFakhraie/src/paint/v1/Paint.java b/EhsanFakhraie/src/paint/v1/Paint.java new file mode 100644 index 0000000..46ae363 --- /dev/null +++ b/EhsanFakhraie/src/paint/v1/Paint.java @@ -0,0 +1,45 @@ +package paint.v1; + +import java.util.ArrayList; +import java.util.List; + +public class Paint { + public ArrayList rectangles; + public ArrayList triangles; + public ArrayList circles; + + public Paint() { + rectangles=new ArrayList<>(); + circles=new ArrayList<>(); + triangles=new ArrayList<>(); + } + + public void drawAll(){ + for (Triangle t:triangles) + t.draw(); + for (Rectangle t:rectangles) + t.draw(); + for (Circle t:circles) + t.draw(); + } + + public void printAll(){ + for (Triangle t:triangles) + System.out.println(t); + for (Rectangle t:rectangles) + System.out.println(t); + for (Circle t:circles) + System.out.println(t); + } + + public void addCircle(Circle c){ + circles.add(c); + } + + public void addTriangle(Triangle c){ + triangles.add(c); + } + public void addRectangle(Rectangle c){ + rectangles.add(c); + } +} diff --git a/EhsanFakhraie/src/paint/v1/Rectangle.java b/EhsanFakhraie/src/paint/v1/Rectangle.java new file mode 100644 index 0000000..650de57 --- /dev/null +++ b/EhsanFakhraie/src/paint/v1/Rectangle.java @@ -0,0 +1,52 @@ +package paint.v1; + +import java.util.Arrays; + +public class Rectangle { + double[] sides; + + public Rectangle(double s1,double s2,double s3,double s4) { + this.sides = new double[4]; + sides[0]=s1; + sides[1]=s2; + sides[2]=s3; + sides[3]=s4; + } + + public double[] getSides() { + return sides; + } + + public double calculatePerimeter(){ + double perimeter=0; + for(double side:sides) + perimeter+=side; + return perimeter; + } + public double calculateArea(){ + + return sides[0]*sides[1]; + } + public void draw(){ + System.out.println("Rectangle ,"+calculatePerimeter()+","+calculateArea()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Rectangle rectangle = (Rectangle) o; + for (int i = 0; i < 3; i++) { + if(sides[i]!=rectangle.getSides()[i]) + return false; + } + return true; + } + @Override + public String toString() { + return "Rectangle{" + + "sides=" + Arrays.toString(sides) + + '}'; + } + +} diff --git a/EhsanFakhraie/src/paint/v1/Triangle.java b/EhsanFakhraie/src/paint/v1/Triangle.java new file mode 100644 index 0000000..c3c0b26 --- /dev/null +++ b/EhsanFakhraie/src/paint/v1/Triangle.java @@ -0,0 +1,52 @@ +package paint.v1; + +import java.util.Arrays; + +public class Triangle { + private double[] sides; + + public Triangle(double s1,double s2,double s3) { + this.sides = new double[3]; + sides[0]=s1; + sides[1]=s2; + sides[2]=s3; + } + + public double[] getSides() { + return sides; + } + + public double calculatePerimeter(){ + double perimeter=0; + for(double side:sides) + perimeter+=side; + return perimeter; + } + public double calculateArea(){ + double p=calculatePerimeter(); + return Math.sqrt(p*(p-sides[0])*(p-sides[1])*(p-sides[2])); + } + public void draw(){ + System.out.println("Triangle ,"+calculatePerimeter()+","+calculateArea()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Triangle triangle = (Triangle) o; + for (int i = 0; i < 3; i++) { + if(sides[i]!=triangle.getSides()[i]) + return false; + } + + return true; + } + @Override + public String toString() { + return "Triangle{" + + "sides=" + Arrays.toString(sides) + + '}'; + } +} diff --git a/EhsanFakhraie/src/paint/v2/Circle.java b/EhsanFakhraie/src/paint/v2/Circle.java new file mode 100644 index 0000000..8d9908d --- /dev/null +++ b/EhsanFakhraie/src/paint/v2/Circle.java @@ -0,0 +1,46 @@ +package paint.v2; + +public class Circle extends Shape { + private double radius; + + public Circle(double radius) { + this.radius = radius; + } + + public double getRadius() { + return radius; + } + + @Override + public double calculatePerimeter() { + return 2*Math.PI*radius; + } + + @Override + public double calculateArea() { + return Math.PI*radius*radius; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Circle circle = (Circle) o; + + return Double.compare(circle.radius, radius) == 0; + } + + + @Override + public String toString() { + return "Circle{" + + "radius=" + radius + + '}'; + } + + @Override + public String type() { + return "Circle"; + } +} diff --git a/EhsanFakhraie/src/paint/v2/Main.java b/EhsanFakhraie/src/paint/v2/Main.java new file mode 100644 index 0000000..b120a2d --- /dev/null +++ b/EhsanFakhraie/src/paint/v2/Main.java @@ -0,0 +1,34 @@ +package paint.v2; + +public class Main { + public static void main(String[] args) { + Circle circle1=new Circle(9); + Circle circle2=new Circle(9); + Circle circle3=new Circle(9); + Circle circle4=new Circle(9); + + Rectangle rectangle=new Rectangle(10,10); + Rectangle rectangle2=new Rectangle(10,10); + Rectangle rectangle3=new Rectangle(10,10); + + Triangle triangle=new Triangle(10,2,9); + Triangle triangle2=new Triangle(10,2,9); + Triangle triangle3=new Triangle(10,2,9); + + Paint p=new Paint(); + p.addCircle(circle1); + p.addCircle(circle2); + p.addCircle(circle3); + + p.addRectangle(rectangle); + p.addRectangle(rectangle2); + p.addRectangle(rectangle3); + + p.addTriangle(triangle); + p.addTriangle(triangle2); + p.addTriangle(triangle3); + + p.printAll(); + p.drawAll(); + } +} diff --git a/EhsanFakhraie/src/paint/v2/Paint.java b/EhsanFakhraie/src/paint/v2/Paint.java new file mode 100644 index 0000000..2a38a09 --- /dev/null +++ b/EhsanFakhraie/src/paint/v2/Paint.java @@ -0,0 +1,48 @@ +package paint.v2; + +import paint.v2.Circle; +import paint.v2.Rectangle; +import paint.v2.Triangle; + +import java.util.ArrayList; + +public class Paint { + public ArrayList rectangles; + public ArrayList triangles; + public ArrayList circles; + + public Paint() { + rectangles=new ArrayList<>(); + circles=new ArrayList<>(); + triangles=new ArrayList<>(); + } + + public void drawAll(){ + for (Triangle t:triangles) + t.draw(); + for (Rectangle t:rectangles) + t.draw(); + for (Circle t:circles) + t.draw(); + } + + public void printAll(){ + for (Triangle t:triangles) + System.out.println(t); + for (Rectangle t:rectangles) + System.out.println(t); + for (Circle t:circles) + System.out.println(t); + } + + public void addCircle(Circle c){ + circles.add(c); + } + + public void addTriangle(Triangle c){ + triangles.add(c); + } + public void addRectangle(Rectangle c){ + rectangles.add(c); + } +} diff --git a/EhsanFakhraie/src/paint/v2/Polygon.java b/EhsanFakhraie/src/paint/v2/Polygon.java new file mode 100644 index 0000000..d5e80d3 --- /dev/null +++ b/EhsanFakhraie/src/paint/v2/Polygon.java @@ -0,0 +1,25 @@ +package paint.v2; + +import java.util.ArrayList; +import java.util.Arrays; + +public abstract class Polygon extends Shape { + public ArrayList getSides() { + return sides; + } + + private ArrayList sides = new ArrayList<>(); + + public Polygon(Double... args) { + sides.addAll(Arrays.asList(args)); + } + + @Override + public double calculatePerimeter() { + Polygon p=(Polygon) this; + double perimeter=0; + for(Double d:sides) + perimeter+=d; + return perimeter; + } +} diff --git a/EhsanFakhraie/src/paint/v2/Rectangle.java b/EhsanFakhraie/src/paint/v2/Rectangle.java new file mode 100644 index 0000000..cb0fa74 --- /dev/null +++ b/EhsanFakhraie/src/paint/v2/Rectangle.java @@ -0,0 +1,37 @@ +package paint.v2; + +import java.lang.reflect.Array; +import java.util.Arrays; + +public class Rectangle extends Polygon { + + public Rectangle(double a, double b) { + super(a, b); + } + + public boolean isSquare(Object o) { + return getSides().get(0).equals(getSides().get(1)); + } + + @Override + public double calculateArea() { + return 2*(this.getSides().get(0) * this.getSides().get(1)); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return ((Rectangle) o).getSides().equals(this.getSides()); + } + + @Override + public String toString() { + return "Rectangle{"+ Arrays.toString(getSides().toArray()) +"}"; + } + + @Override + public String type() { + return "Rectangle"; + } +} \ No newline at end of file diff --git a/EhsanFakhraie/src/paint/v2/Shape.java b/EhsanFakhraie/src/paint/v2/Shape.java new file mode 100644 index 0000000..d973532 --- /dev/null +++ b/EhsanFakhraie/src/paint/v2/Shape.java @@ -0,0 +1,18 @@ +package paint.v2; + +public abstract class Shape { + + public abstract double calculatePerimeter(); + + public abstract double calculateArea(); + + public abstract boolean equals(Object o); + + public abstract String toString(); + + public abstract String type(); + + public void draw(){ + System.out.println(type()+" Perimeter"+calculatePerimeter()+" Area"+calculateArea()); + } +} \ No newline at end of file diff --git a/EhsanFakhraie/src/paint/v2/Triangle.java b/EhsanFakhraie/src/paint/v2/Triangle.java new file mode 100644 index 0000000..a441df5 --- /dev/null +++ b/EhsanFakhraie/src/paint/v2/Triangle.java @@ -0,0 +1,35 @@ +package paint.v2; + +import java.util.ArrayList; +import java.util.Arrays; + +public class Triangle extends Polygon { + public Triangle(double a, double b, double c) { + super(a, b, c); + } + + @Override + public double calculateArea() { + Triangle triangle = (Triangle) this; + double p = this.calculatePerimeter(); + ArrayList sides = getSides(); + return Math.sqrt(p * (p - sides.get(0)) * (p - sides.get(1)) * (p - sides.get(2))); + } + + @Override + public boolean equals(Object o) { + Triangle t = (Triangle) o; + return this.getSides() == t.getSides(); + } + + + @Override + public String toString() { + return "Triangle{" + Arrays.toString(getSides().toArray()) + "}"; + } + + @Override + public String type() { + return "Triangle"; + } +} diff --git a/EhsanFakhraie/src/vote/Main.java b/EhsanFakhraie/src/vote/Main.java new file mode 100644 index 0000000..c067824 --- /dev/null +++ b/EhsanFakhraie/src/vote/Main.java @@ -0,0 +1,26 @@ +package vote; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + VotingSystem votingSystem=new VotingSystem(); + votingSystem.createVoting("A",1); + votingSystem.getVoting(0).createChoice("1"); + Scanner sc=new Scanner(System.in); + + + Person person=new Person(sc.nextLine(),sc.nextLine()); + ArrayList votes=new ArrayList<>(); + votes.add("1"); + votes.add("1"); + votes.add("1"); + votes.add("1"); + votes.add("2"); + votingSystem.vote(0,person,votes); + + votingSystem.getVoting(0).printResult(); + + } +} diff --git a/EhsanFakhraie/src/vote/Person.java b/EhsanFakhraie/src/vote/Person.java new file mode 100644 index 0000000..4b4db96 --- /dev/null +++ b/EhsanFakhraie/src/vote/Person.java @@ -0,0 +1,28 @@ +package vote; + +public class Person { + private String firstName; + private String lastName; + + public Person(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + + public String getLastName() { + return lastName; + } + + @Override + public String toString() { + return "Person{" + + "firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + '}'; + } +} diff --git a/EhsanFakhraie/src/vote/Vote.java b/EhsanFakhraie/src/vote/Vote.java new file mode 100644 index 0000000..5425e67 --- /dev/null +++ b/EhsanFakhraie/src/vote/Vote.java @@ -0,0 +1,30 @@ +package vote; + +import java.util.Objects; + +public class Vote { + + private Person person; + + private String date; + + public Vote(Person person, String date) { + this.person = person; + this.date = date; + } + + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Vote vote = (Vote) o; + return Objects.equals(person, vote.person); + } + + @Override + public int hashCode() { + return Objects.hash(person); + } +} diff --git a/EhsanFakhraie/src/vote/Voting.java b/EhsanFakhraie/src/vote/Voting.java new file mode 100644 index 0000000..ab1a2ec --- /dev/null +++ b/EhsanFakhraie/src/vote/Voting.java @@ -0,0 +1,88 @@ +package vote; + +import ir.huri.jcal.JalaliCalendar; + +import java.util.*; + +public class Voting { + /** + * determines type of poll + * 0: single vote + * 1: multi vote + */ + private int type; + private String question; + + private HashMap> polls; + + private ArrayList choices; + + public Voting(String question, int type) { + this.type = type; + this.question = question; + + polls = new HashMap<>(); + choices = new ArrayList<>(); + } + + public void createChoice(String choice) { + choices.add(choice); + polls.put(choice, new HashSet<>()); + } + + public String getNowData() { + JalaliCalendar jalaliDate = new JalaliCalendar(new GregorianCalendar(2016, 4, 16)); + return jalaliDate.toString(); + } + + public void vote(Person p, ArrayList votes) { + if(type==0){ + for (String v : votes) { + if (choices.contains(v)) { + Vote vote = new Vote(p, getNowData()); + HashSet vs = polls.get(v); + vs.add(vote); + polls.replace(v, vs); + }else { + System.out.println("wrong vote"); + } + } + }else{ + String v=votes.get(0); + if (choices.contains(v)) { + Vote vote = new Vote(p, getNowData()); + HashSet vs = polls.get(v); + vs.add(vote); + polls.replace(v, vs); + }else { + System.out.println("wrong vote"); + } + } + + } + + public int getType() { + return type; + } + + public String getQuestion() { + return question; + } + + public HashMap> getPolls() { + return polls; + } + + public ArrayList getChoices() { + return choices; + } + + public void printResult() { + for (Map.Entry> stringHashSetEntry : polls.entrySet()) { + String key = (String) stringHashSetEntry.getKey(); + HashSet votes = stringHashSetEntry.getValue(); + System.out.println("Choice " + key + " Count:" + votes.size()); + } + } + +} diff --git a/EhsanFakhraie/src/vote/VotingSystem.java b/EhsanFakhraie/src/vote/VotingSystem.java new file mode 100644 index 0000000..7618908 --- /dev/null +++ b/EhsanFakhraie/src/vote/VotingSystem.java @@ -0,0 +1,40 @@ +package vote; + +import java.util.ArrayList; + +public class VotingSystem { + + private ArrayList votingList; + + public VotingSystem(){ + votingList=new ArrayList<>(); + } + + public void createVoting(String question,int type){ + votingList.add(new Voting(question,type)); + } + + public ArrayList getVotingList() { + return votingList; + } + + public Voting getVoting(int index){ + return votingList.get(index); + } + + public void printListOfVotings(){ + for (Voting e: votingList){ + System.out.println(e); + } + } + + public void printVoting(int i){ + System.out.println(getVoting(i)); + } + + public void vote(int i,Person p,ArrayList votes){ + votingList.get(i).vote(p,votes); + } + + +} diff --git a/out/production/workshop-2/META-INF/workshop-2.kotlin_module b/out/production/workshop-2/META-INF/workshop-2.kotlin_module new file mode 100644 index 0000000..a49347a Binary files /dev/null and b/out/production/workshop-2/META-INF/workshop-2.kotlin_module differ diff --git a/out/production/workshop-2/paint/v1/Circle.class b/out/production/workshop-2/paint/v1/Circle.class new file mode 100644 index 0000000..3597d1f Binary files /dev/null and b/out/production/workshop-2/paint/v1/Circle.class differ diff --git a/out/production/workshop-2/paint/v1/Main.class b/out/production/workshop-2/paint/v1/Main.class new file mode 100644 index 0000000..d5b13bc Binary files /dev/null and b/out/production/workshop-2/paint/v1/Main.class differ diff --git a/out/production/workshop-2/paint/v1/Paint.class b/out/production/workshop-2/paint/v1/Paint.class new file mode 100644 index 0000000..e8e05b8 Binary files /dev/null and b/out/production/workshop-2/paint/v1/Paint.class differ diff --git a/out/production/workshop-2/paint/v1/Rectangle.class b/out/production/workshop-2/paint/v1/Rectangle.class new file mode 100644 index 0000000..7cbe3a4 Binary files /dev/null and b/out/production/workshop-2/paint/v1/Rectangle.class differ diff --git a/out/production/workshop-2/paint/v1/Triangle.class b/out/production/workshop-2/paint/v1/Triangle.class new file mode 100644 index 0000000..6c52413 Binary files /dev/null and b/out/production/workshop-2/paint/v1/Triangle.class differ diff --git a/out/production/workshop-2/vote/Main.class b/out/production/workshop-2/vote/Main.class new file mode 100644 index 0000000..bfbc610 Binary files /dev/null and b/out/production/workshop-2/vote/Main.class differ diff --git a/out/production/workshop-2/vote/Person.class b/out/production/workshop-2/vote/Person.class new file mode 100644 index 0000000..21f31e5 Binary files /dev/null and b/out/production/workshop-2/vote/Person.class differ diff --git a/out/production/workshop-2/vote/Vote.class b/out/production/workshop-2/vote/Vote.class new file mode 100644 index 0000000..97fa825 Binary files /dev/null and b/out/production/workshop-2/vote/Vote.class differ diff --git a/out/production/workshop-2/vote/Voting.class b/out/production/workshop-2/vote/Voting.class new file mode 100644 index 0000000..a101f26 Binary files /dev/null and b/out/production/workshop-2/vote/Voting.class differ diff --git a/out/production/workshop-2/vote/VotingSystem.class b/out/production/workshop-2/vote/VotingSystem.class new file mode 100644 index 0000000..44e44eb Binary files /dev/null and b/out/production/workshop-2/vote/VotingSystem.class differ