diff --git a/AP-LabManual-Session4.zip b/AP-LabManual-Session4.zip deleted file mode 100644 index 4ed1f76..0000000 Binary files a/AP-LabManual-Session4.zip and /dev/null differ diff --git a/AP-LabManual-Session5.pdf b/AP-LabManual-Session5.pdf deleted file mode 100644 index db26fda..0000000 Binary files a/AP-LabManual-Session5.pdf and /dev/null differ diff --git a/README.md b/README.md index ab9e3fe..011d4e9 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,4 @@ AUT AP Workshop 2 +Saeed Shafie : 9831036 diff --git a/RashadAnsari/RashadAnsari b/RashadAnsari/RashadAnsari deleted file mode 100644 index b2afe10..0000000 --- a/RashadAnsari/RashadAnsari +++ /dev/null @@ -1,3 +0,0 @@ -Full Name: Rashad Ansari -Student Number: XXXXXXXXXX - diff --git a/SaeedShafie/Lab4/src/Mian.java b/SaeedShafie/Lab4/src/Mian.java new file mode 100644 index 0000000..b6e323a --- /dev/null +++ b/SaeedShafie/Lab4/src/Mian.java @@ -0,0 +1,44 @@ +import java.util.ArrayList; + +public class Mian { + public static void main(String[] args) { + Person p1 = new Person("Bob","Bobby"); + Person p2 = new Person("Sam","Sami"); + Person p3 = new Person("Jack","Jackie"); + Person p4 = new Person("Fred","Fredie"); + VotingSystem votingSystem = new VotingSystem(); + ArrayList poll1 = new ArrayList(); + votingSystem.createVoting("Are you Crazy?" , 0 , poll1); + poll1.add("Yes"); + poll1.add("No"); + ArrayList poll2 = new ArrayList(); + votingSystem.createVoting("If not crazy what are you?" , 1 , poll2); + poll2.add("Sadistic"); + poll2.add("humorous"); + poll2.add("Dumb"); + poll2.add("Normal"); + ArrayList option= new ArrayList(); + votingSystem.vote(0,p1,option); + votingSystem.vote(0,p2,option); + votingSystem.vote(0,p3,option); + votingSystem.printVoting(0); + votingSystem.printResults(0); + ArrayList option2 = new ArrayList(); + ArrayList option3 = new ArrayList(); + ArrayList option4 = new ArrayList(); + option2.add("Normal"); + option3.add("Dumb"); + option3.add("Sadistic"); + option4.add("Normal"); + votingSystem.vote(1,p1,option2); + votingSystem.vote(1,p2,option2); + votingSystem.vote(1,p3,option3); + votingSystem.vote(1,p4,option4); + votingSystem.printVoting(1); + votingSystem.printResults(1); + + + + + } +} \ No newline at end of file diff --git a/SaeedShafie/Lab4/src/Person.java b/SaeedShafie/Lab4/src/Person.java new file mode 100644 index 0000000..dfd28e6 --- /dev/null +++ b/SaeedShafie/Lab4/src/Person.java @@ -0,0 +1,19 @@ +public class Person { + private String firstName; + private String lastName; + public Person(String firstName,String lastName){ + this.firstName = firstName; + this.lastName = lastName; + } + public String getLastName() { + return lastName; + } + public String getFirstName() { + return firstName; + } + public String toString() { + return String.format("Voters_Information = %s %s", firstName, lastName); + } +} + + diff --git a/SaeedShafie/Lab4/src/Vote.java b/SaeedShafie/Lab4/src/Vote.java new file mode 100644 index 0000000..fb36e6f --- /dev/null +++ b/SaeedShafie/Lab4/src/Vote.java @@ -0,0 +1,32 @@ +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; + } + public Person getPerson() { + return person; + } + + public String getDate() { + return date; + } + public int hashCode() { + return Objects.hash(person, date); + } + public boolean equals(Object o) { + if (this == o) { + return true; + } + else if (o == null || getClass() != o.getClass()) { + return false; + } + Vote vote = (Vote) o; + return Objects.equals(person, vote.person) && + Objects.equals(date, vote.date); + } + +} diff --git a/SaeedShafie/Lab4/src/Voting.java b/SaeedShafie/Lab4/src/Voting.java new file mode 100644 index 0000000..5dcd17d --- /dev/null +++ b/SaeedShafie/Lab4/src/Voting.java @@ -0,0 +1,59 @@ +import ir.huri.jcal.JalaliCalendar; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +public class Voting { + int type; + String questions; + ArrayList voters; + ArrayList options ; + HashMap> polls; + public Voting(int type , String questions){ + this.type = type; + this.questions = questions; + options = new ArrayList(); + voters = new ArrayList(); + polls = new HashMap<>(); + + } + public String getQuestions(){ + return questions; + } + public void createPolls(String poll){ + options.add(poll); + } + public void vote(Person person , ArrayList votes){ + voters.add(person); + if(type==0){ + JalaliCalendar calendar=new JalaliCalendar(); + Vote vote=new Vote(person,calendar.toString()); + polls.get(options.get(0)).add(vote); + }else{ + for(String choice:options){ + JalaliCalendar calendar=new JalaliCalendar(); + Vote vote=new Vote(person,calendar.toString()); + polls.get(choice).add(vote); + } + } + } + public void getVoters() { + for(Person voter:voters){ + System.out.println(voter); + } + } + public void printVotes(){ + System.out.println(questions); + for (int i = 0; i < options.size(); i++) { + System.out.println((i+1) + ") " + options.get(i)); + } + } + public ArrayList getPolls(){ + ArrayList options=new ArrayList<>(); + for(String key:polls.keySet()){ + options.add(key); + } + return options; + } +} \ No newline at end of file diff --git a/SaeedShafie/Lab4/src/VotingSystem.java b/SaeedShafie/Lab4/src/VotingSystem.java new file mode 100644 index 0000000..5af56a5 --- /dev/null +++ b/SaeedShafie/Lab4/src/VotingSystem.java @@ -0,0 +1,43 @@ +import java.util.*; + + +public class VotingSystem { + private ArrayList votingList = new ArrayList<>(); + public VotingSystem(){ + } + public void createVoting(String question,int type,ArrayList options){ + Voting voting=new Voting(type,question); + for(String option:options){ + voting.createPolls(option); + } + votingList.add(voting); + + } + public void printVotingQuestions(){ + for(Voting voting:votingList){ + System.out.println(voting.getQuestions()); + } + } + + public void printVoting(int votingNumber){ + Voting voting = votingList.get(votingNumber); + System.out.println(voting.getQuestions()); + for(String option:voting.getPolls()){ + System.out.println(option); + } + + } + + public void vote(int votingNum,Person person,ArrayList options){ + Voting voting=votingList.get(votingNum); + voting.vote(person,options); + } + + public void printResults(int votingNum){ + Voting voting=votingList.get(votingNum); + voting.printVotes(); + } +} + + + diff --git a/SaeedShafie/Lab5/src/Circle.java b/SaeedShafie/Lab5/src/Circle.java new file mode 100644 index 0000000..bd97238 --- /dev/null +++ b/SaeedShafie/Lab5/src/Circle.java @@ -0,0 +1,26 @@ +public class Circle extends Shape { + private int radius; + + public Circle(int radius) { + this.radius = radius; + } + + public int getRadius() { + return radius; + } + + public String toString() { + return "Circle:: radius:" + radius; + } + + public double calculatePerimeter() { + return 2 * Math.PI * radius; + } + + public double calculateArea() { + return Math.PI * Math.pow(radius, 2); + } + public void Draw() { + System.out.println(" s = " + this.calculateArea() + " , p = " + this.calculatePerimeter()); + } +} diff --git a/SaeedShafie/Lab5/src/Main.java b/SaeedShafie/Lab5/src/Main.java new file mode 100644 index 0000000..7920d08 --- /dev/null +++ b/SaeedShafie/Lab5/src/Main.java @@ -0,0 +1,25 @@ +public class Main { + public static void main(String[] args) { + Circle circle1 = new Circle(19); + Circle circle2 = new Circle(3); + Circle circle3 = 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(); + paint.printAll(); + if (circle2.equals(circle3)){ + System.out.println("circle 2 equals circle 3"); + } + } +} \ No newline at end of file diff --git a/SaeedShafie/Lab5/src/Paint.java b/SaeedShafie/Lab5/src/Paint.java new file mode 100644 index 0000000..987a977 --- /dev/null +++ b/SaeedShafie/Lab5/src/Paint.java @@ -0,0 +1,34 @@ +import java.util.ArrayList; + +public class Paint { + private ArrayList shapes = new ArrayList<>(); + + public void addShape(Shape shapeToAdd) { + shapes.add(shapeToAdd); + } + + public void drawAll() { + for (Shape shape : shapes) { + shape.draw(); + } + } + public void printAll() { + for (Shape shape : shapes) { + System.out.println(shape); + } + } + public void describeEqualSides() { + for (Shape shape : shapes) { + if (shape instanceof Triangle) { + if (((Triangle) shape).isEquilateral()) { + System.out.println(shape + " is equal"); + } + } + if (shape instanceof Rectangle) { + if (((Rectangle) shape).isSquare()) { + System.out.println(shape + " is square!"); + } + } + } + } +} \ No newline at end of file diff --git a/SaeedShafie/Lab5/src/Polygon.java b/SaeedShafie/Lab5/src/Polygon.java new file mode 100644 index 0000000..5601d9d --- /dev/null +++ b/SaeedShafie/Lab5/src/Polygon.java @@ -0,0 +1,52 @@ +import java.util.ArrayList; + +public class Polygon extends Shape { + protected ArrayList sides; + + public Polygon(Integer... sides) { + this.sides = new ArrayList<>(); + for (Integer side : sides) { + this.sides.add(side); + } + } + + public ArrayList getSides() { + return sides; + } + + public double calculatePerimeter() { + double sum = 0; + for (Integer side : sides) { + sum += side; + } + return sum; + } + + public void Draw() { + if (this instanceof Rectangle){ + if (this.isEqual()){ + System.out.println(" s = " + this.calculateArea() + " , p = " + this.calculatePerimeter()); + } + else { + System.out.println(" s = " + this.calculateArea() + " , p = " + this.calculatePerimeter()); + } + } + else { + if (this.isEqual()){ + System.out.println(" s = " + this.calculateArea() + " , p = " + this.calculatePerimeter()); + } + else { + System.out.println(" s : " + this.calculateArea() + " , p = " + this.calculatePerimeter()); + } + } + } + public boolean isEqual(){ + Integer s1 = sides.get(0); + for (int i = 1; i < sides.size() ; i++) { + if (!s1.equals(sides.get(i))){ + return false; + } + } + return true; + } +} diff --git a/SaeedShafie/Lab5/src/Rectangle.java b/SaeedShafie/Lab5/src/Rectangle.java new file mode 100644 index 0000000..76b47aa --- /dev/null +++ b/SaeedShafie/Lab5/src/Rectangle.java @@ -0,0 +1,18 @@ +public class Rectangle extends Polygon { + + public Rectangle(Integer... sides) { + super(sides); + } + public double calculateArea() { + return sides.get(0) * sides.get(1); + } + public boolean isSquare() { + if (sides.get(0) == sides.get(1) && sides.get(1) == sides.get(2) && sides.get(2) == sides.get(3)) { + return true; + } + return false; + } + public String toString() { + return "Rectangle:: " + super.toString(); + } +} \ No newline at end of file diff --git a/SaeedShafie/Lab5/src/Shape.java b/SaeedShafie/Lab5/src/Shape.java new file mode 100644 index 0000000..97f9ce6 --- /dev/null +++ b/SaeedShafie/Lab5/src/Shape.java @@ -0,0 +1,21 @@ +public class Shape { + public double calculatePerimeter() { + return 1; + } + public double calculateArea() { + return 1; + } + public void draw() { + System.out.println(this.getClass().getName()); + System.out.println("Perimeter = " + calculatePerimeter()); + System.out.println("Area = " + calculateArea()); + } + + public String toString() { + return ""; + } + + public boolean equals(Object obj) { + return super.equals(obj); + } +} \ No newline at end of file diff --git a/SaeedShafie/Lab5/src/Triangle.java b/SaeedShafie/Lab5/src/Triangle.java new file mode 100644 index 0000000..78a6a38 --- /dev/null +++ b/SaeedShafie/Lab5/src/Triangle.java @@ -0,0 +1,23 @@ +public class Triangle extends Polygon { + + public Triangle(Integer... sides) { + super(sides); + } + public boolean isEquilateral() { + if (sides.get(0) == sides.get(1) && sides.get(1) == sides.get(2)) { + return true; + } + return false; + } + public double calculateArea() { + double p = calculatePerimeter() / 2; + double area = p; + for (Integer side : sides) { + area *= (p - side); + } + return Math.sqrt(area); + } + public String toString() { + return "Triangle:: " + super.toString(); + } +} \ No newline at end of file