Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SaeedShafie9831036 #24

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Binary file removed AP-LabManual-Session4.zip
Binary file not shown.
Binary file removed AP-LabManual-Session5.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

AUT AP Workshop 2

Saeed Shafie : 9831036
3 changes: 0 additions & 3 deletions RashadAnsari/RashadAnsari

This file was deleted.

44 changes: 44 additions & 0 deletions SaeedShafie/Lab4/src/Mian.java
Original file line number Diff line number Diff line change
@@ -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<String> poll1 = new ArrayList<String>();
votingSystem.createVoting("Are you Crazy?" , 0 , poll1);
poll1.add("Yes");
poll1.add("No");
ArrayList<String> poll2 = new ArrayList<String>();
votingSystem.createVoting("If not crazy what are you?" , 1 , poll2);
poll2.add("Sadistic");
poll2.add("humorous");
poll2.add("Dumb");
poll2.add("Normal");
ArrayList<String> option= new ArrayList<String>();
votingSystem.vote(0,p1,option);
votingSystem.vote(0,p2,option);
votingSystem.vote(0,p3,option);
votingSystem.printVoting(0);
votingSystem.printResults(0);
ArrayList<String> option2 = new ArrayList<String>();
ArrayList<String> option3 = new ArrayList<String>();
ArrayList<String> option4 = new ArrayList<String>();
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);




}
}
19 changes: 19 additions & 0 deletions SaeedShafie/Lab4/src/Person.java
Original file line number Diff line number Diff line change
@@ -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);
}
}


32 changes: 32 additions & 0 deletions SaeedShafie/Lab4/src/Vote.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
59 changes: 59 additions & 0 deletions SaeedShafie/Lab4/src/Voting.java
Original file line number Diff line number Diff line change
@@ -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<Person> voters;
ArrayList<String> options ;
HashMap<String, HashSet<Vote>> polls;
public Voting(int type , String questions){
this.type = type;
this.questions = questions;
options = new ArrayList<String>();
voters = new ArrayList<Person>();
polls = new HashMap<>();

}
public String getQuestions(){
return questions;
}
public void createPolls(String poll){
options.add(poll);
}
public void vote(Person person , ArrayList<String> 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<String> getPolls(){
ArrayList<String> options=new ArrayList<>();
for(String key:polls.keySet()){
options.add(key);
}
return options;
}
}
43 changes: 43 additions & 0 deletions SaeedShafie/Lab4/src/VotingSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.*;


public class VotingSystem {
private ArrayList<Voting> votingList = new ArrayList<>();
public VotingSystem(){
}
public void createVoting(String question,int type,ArrayList<String> 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<String> options){
Voting voting=votingList.get(votingNum);
voting.vote(person,options);
}

public void printResults(int votingNum){
Voting voting=votingList.get(votingNum);
voting.printVotes();
}
}



26 changes: 26 additions & 0 deletions SaeedShafie/Lab5/src/Circle.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
25 changes: 25 additions & 0 deletions SaeedShafie/Lab5/src/Main.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
34 changes: 34 additions & 0 deletions SaeedShafie/Lab5/src/Paint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.ArrayList;

public class Paint {
private ArrayList<Shape> 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!");
}
}
}
}
}
52 changes: 52 additions & 0 deletions SaeedShafie/Lab5/src/Polygon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.ArrayList;

public class Polygon extends Shape {
protected ArrayList<Integer> sides;

public Polygon(Integer... sides) {
this.sides = new ArrayList<>();
for (Integer side : sides) {
this.sides.add(side);
}
}

public ArrayList<Integer> 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;
}
}
18 changes: 18 additions & 0 deletions SaeedShafie/Lab5/src/Rectangle.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
21 changes: 21 additions & 0 deletions SaeedShafie/Lab5/src/Shape.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading