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

Add AmirrezaTarabkhah - 9831041 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
3 changes: 3 additions & 0 deletions AmirrezaTarabkhah/AmirrezaTarabkhah
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Full Name: Amirreza Tarabkhah
Student Number: 9831041

51 changes: 51 additions & 0 deletions AmirrezaTarabkhah/s4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.util.*;

public class Main {

public static void main(String[] arg){
VotingSystem votingSystem = new VotingSystem();
Person person1 = new Person("Amirreza","Tarabkhah");
Person person2 = new Person("Ehsan","Helmi");
Person person3 = new Person("Parham","Ashrafi");
ArrayList<String> choice1 = new ArrayList<>();
choice1.add("Reus");
ArrayList<String> choice2 = new ArrayList<>();
choice2.add("Pele");
ArrayList<String> choice3 = new ArrayList<>();
choice3.add("Messi");
ArrayList<String> choice4 = new ArrayList<>();
choice4.add("Ronaldo");
ArrayList<String> choice5 = new ArrayList<>();
choice5.add("Reus");
choice5.add("Gotze");
ArrayList<String> answer = new ArrayList<>();
answer.add("Ronaldo");
answer.add("Messi");
answer.add("Pele");
answer.add("Reus");
votingSystem.createVoting("Who is the best player?",0, answer);
votingSystem.printVoting(1);
votingSystem.vote(1,person1,choice5);
votingSystem.vote(1,person1,choice1);
votingSystem.vote(1,person3,choice2);
votingSystem.vote(1,person2,choice4);
votingSystem.vote(1,person3,choice3);
votingSystem.printAll(1);
System.out.println();
votingSystem.createVoting("Who are creative player",1, answer);
votingSystem.printVoting(2);
votingSystem.getVoting(2).createPoll("Kaka");
votingSystem.getVoting(2).createPoll("Gotze");
votingSystem.vote(2, person1, choice5);
choice2.add("Kaka");
choice2.add("Messi");
votingSystem.vote(2, person2, choice2);
votingSystem.printAll(2);
System.out.println();
votingSystem.printVotingList();
System.out.println();
votingSystem.printAll(1);
System.out.println();
votingSystem.printAll(2);
}
}
16 changes: 16 additions & 0 deletions AmirrezaTarabkhah/s4/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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;}

public String toString() {return (firstName + lastName);}
}
24 changes: 24 additions & 0 deletions AmirrezaTarabkhah/s4/Vote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import ir.huri.jcal.JalaliCalendar;

public class Vote {

Person person;
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 boolean equals(Vote vote){
if (vote.getDate().equals(date) && vote.getPerson().equals(person))
return true;
return false;
}


}
53 changes: 53 additions & 0 deletions AmirrezaTarabkhah/s4/Voting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import ir.huri.jcal.JalaliCalendar;
import java.util.*;

public class Voting {

private int type;
private JalaliCalendar jalaliCalendar = new JalaliCalendar();
private String question;
private ArrayList<Person> voters = new ArrayList<>();
private HashMap<String, HashSet<Vote>> polls = new HashMap<>();

public Voting(int type, String question) {
this.type = type;
this.question = question;
}

public String getQuestion() {return question;}

public void printVoters() {
for (Person person : voters)
System.out.println(voters.toString());
}

public void vote(Person person, ArrayList<String> votes) {
if (votes.size() > 1 && type == 0){
System.out.println("You cannot vote like this!!!");
return;
}
for (Person person1 : voters) {
if (person.equals(person1)) {
System.out.println("You have voted");
return;
}
}
for (String poll : votes) {
Vote vote = new Vote(person, jalaliCalendar.toString());
polls.get(poll).add(vote);
}
}

public void createPoll(String choice) {
HashSet<Vote> poll = new HashSet<>();
polls.put(choice, poll);
}

public Set<String> getPolls() {return polls.keySet();}

public void printResult() {
Set<String> poll = polls.keySet();
for (String s : poll)
System.out.println(s + " : " + polls.get(s).size());
}
}
39 changes: 39 additions & 0 deletions AmirrezaTarabkhah/s4/VotingSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.ArrayList;

public class VotingSystem {

private ArrayList<Voting> votingList;

public VotingSystem(){
votingList = new ArrayList<>();
}

public void createVoting(String question, int type, ArrayList<String> answers){
Voting voting = new Voting(type, question);
for (String answer : answers)
voting.createPoll(answer);
votingList.add(voting);
}

public Voting getVoting(int index) {return votingList.get(index - 1);}

public void printVotingList() {
for (Voting voting : votingList)
System.out.println(voting.getQuestion());
}

public void printVoting(int index) {
int i = 0;
System.out.println(votingList.get(index - 1).getQuestion());
for (String answer : votingList.get(index - 1).getPolls()){
i++;
System.out.println(i + ") " + answer);
}
}

public void vote(int index, Person person, ArrayList<String> votes){
votingList.get(index - 1).vote(person, votes);
}

public void printAll(int index) {votingList.get(index - 1).printResult();}
}
48 changes: 48 additions & 0 deletions AmirrezaTarabkhah/s5/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.ArrayList;

public class Circle extends Shape {

private int radius;

public Circle(int radius) {this.radius = radius;}

@Override
public double calculateArea(int... nums) {
double i = 1;
for (int n : nums)
i *= n;
i *= i * pi;
return i;
}

@Override
public double calculatePerimeter(int... nums){
double i = 0;
for (int n : nums)
i += n;
i *= 2 * pi;
return i;
}

@Override
public void draw() {System.out.println("Circle - Area = " + calculateArea(radius) + " - Perimeter = " + calculatePerimeter(radius));}

@Override
public boolean equals(Shape shape) {
if (shape.getSides().get(0) == radius)
return true;
return false;
}

@Override
public ArrayList<Integer> getSides() {
ArrayList arrayList = new ArrayList();
arrayList.add(radius);
return arrayList;
}

@Override
public String toString() {
return "Circle : " + "radius = " + radius;
}
}
22 changes: 22 additions & 0 deletions AmirrezaTarabkhah/s5/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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);
Rectangle rect2 = new Rectangle(8,5);
Rectangle rect3 = new Rectangle(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();
}
}
18 changes: 18 additions & 0 deletions AmirrezaTarabkhah/s5/Paint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.ArrayList;

public class Paint {

private ArrayList<Shape> shapes = new ArrayList<>();

public void addShape(Shape shape) {shapes.add(shape);}

public void drawAll() {
for (Shape shape : shapes)
shape.draw();
}

public void printAll() {
for (Shape shape : shapes)
System.out.println(shape.toString());
}
}
30 changes: 30 additions & 0 deletions AmirrezaTarabkhah/s5/Polygon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.ArrayList;

public class Polygon extends Shape {

protected ArrayList<Integer> sides = new ArrayList<>();

public Polygon(int... nums){
for (int i : nums)
sides.add(i);
}

public double calculateArea(int... nums){
return 0;
}

public double calculatePerimeter(int... nums){
return 0;
}

public void draw() {}

public boolean equals(Shape shape) {return false;}

public ArrayList<Integer> getSides() {return null;}

@Override
public String toString() {
return null;
}
}
63 changes: 63 additions & 0 deletions AmirrezaTarabkhah/s5/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.util.ArrayList;

public class Rectangle extends Polygon {

public Rectangle(int a, int b) {super(a, b);}

@Override
public double calculateArea(int... nums) {
int i = 1;
for (int n : nums)
i *= n;
return i;
}

@Override
public double calculatePerimeter(int... nums){
double i = 0;
for (int n : nums)
i += n;
return i;
}

@Override
public void draw() {
System.out.println("Rectangle - Area = " + calculateArea(sides.get(0), sides.get(1)) + " - Perimeter = " + calculatePerimeter(sides.get(0), sides.get(1)));
}

@Override
public ArrayList<Integer> getSides() {
return sides;
}

@Override
public boolean equals(Shape shape) {
int p = 0;
for (int i = 0; i < 1; i++)
{
for (int j = 0; j < 1; j++) {
if (shape.getSides().get(i) == sides.get(j))
p++;
}
}
if (p == 2){
if (!isSquare())
if (!(shape.getSides().get(0) == shape.getSides().get(1)))
return true;
}
if (p == 4)
return true;
return false;
}

public boolean isSquare(){
if (sides.get(0) == sides.get(1))
return true;
return false;
}

@Override
public String toString() {
return "Rectangle :" + " Side 1 = " + sides.get(0) + " Side 2 = " + sides.get(1);
}
}
20 changes: 20 additions & 0 deletions AmirrezaTarabkhah/s5/Shape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.*;

public abstract class Shape {

protected final static double pi = 3.1415926535;

public Shape() {}

public abstract double calculateArea(int... nums);

public abstract double calculatePerimeter(int... nums);

public abstract void draw();

public abstract boolean equals(Shape shape);

public abstract String toString();

public abstract ArrayList<Integer> getSides();
}
Loading