Skip to content
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
29 changes: 29 additions & 0 deletions AmirhosseinSana/4/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.ArrayList;

/**
* The type Main.
*/
public class Main {
/**
* The entry point of application.
*
* @param args the input arguments
*/
public static void main(String[] args) {
VotingSystem vs = new VotingSystem();

ArrayList<String> polls = new ArrayList<>();
polls.add(":)");
polls.add(":(");
polls.add(":/");
polls.add(":|");
vs.createVoting("?", 0, polls);

ArrayList<String> x = new ArrayList<>();
x.add(":)");

vs.vote(0, new Person("a", "b"), x);

vs.getResult(0);
}
}
42 changes: 42 additions & 0 deletions AmirhosseinSana/4/src/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* The type Person.
*/
public class Person {
private String firstName;
private String lastName;

/**
* Instantiates a new Person.
*
* @param fn the fn
* @param ln the ln
*/
public Person(String fn, String ln) {
firstName = fn;
lastName = ln;
}

/**
* Gets first name.
*
* @return the first name
*/
public String getFirstName() {
return firstName;
}

/**
* Gets last name.
*
* @return the last name
*/
public String getLastName() {
return lastName;
}

@Override
public String toString() {
return "firstName= " + firstName + " " +
", lastName= " + lastName;
}
}
54 changes: 54 additions & 0 deletions AmirhosseinSana/4/src/Vote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import ir.huri.jcal.JalaliCalendar;

import java.util.Objects;

/**
* The type Vote.
*/
public class Vote {
private Person person;
private JalaliCalendar date;

/**
* Instantiates a new Vote.
*
* @param p the p
* @param d the d
*/
Vote(Person p, JalaliCalendar d) {
person = p;
date = d;
}

/**
* Gets person.
*
* @return the person
*/
public Person getPerson() {
return person;
}

/**
* Gets date.
*
* @return the date
*/
public JalaliCalendar getDate() {
return 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) &&
Objects.equals(date, vote.date);
}

@Override
public int hashCode() {
return Objects.hash(person, date);
}
}
107 changes: 107 additions & 0 deletions AmirhosseinSana/4/src/Voting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import ir.huri.jcal.JalaliCalendar;

import java.util.*;

/**
* The type Voting.
*/
public class Voting {
private int type;
private String question;
private ArrayList<Person> voters;
private HashMap<String, HashSet<Vote>> polls;

/**
* Instantiates a new Voting.
*
* @param t the t
* @param q the q
*/
public Voting(int t, String q) {
type = t;
question = q;
voters = new ArrayList<>();
polls = new HashMap<>();
}

/**
* Gets question.
*
* @return the question
*/
public String getQuestion() {
return question;
}

/**
* Create poll.
*
* @param poll the poll
*/
public void createPoll(String poll) {
if(polls.keySet().contains(poll)) {
System.out.println("invalid");
return;
}
polls.put(poll, new HashSet<Vote>());
}

/**
* Vote.
*
* @param person the person
* @param choices the choices
*/
public void vote(Person person, ArrayList<String> choices) {
if(voters.contains(person) || (type == 0 && choices.size() > 1)){
System.out.println("invalid");
return;
}
for(String str : choices) {
polls.get(str).add(new Vote(person, new JalaliCalendar()));
}
}

/**
* Gets voters.
*/
public void getVoters() {
System.out.println("voters:");
for(int i = 0; i < voters.size(); i ++)
System.out.println(voters.get(i));
}

/**
* Print votes.
*/
public void printVotes() {
Iterator it1 = polls.entrySet().iterator();
while(it1.hasNext()) {
Map.Entry help = (Map.Entry) it1.next();
System.out.println(help.getKey() + " :");
HashSet<Vote> now = (HashSet<Vote>) help.getValue();
Iterator it2 = now.iterator();
while(it2.hasNext()) {
Vote tof = (Vote) it2.next();
System.out.println(tof.getPerson() + " " + tof.getDate());
}
}
}

/**
* Gets polls.
*
* @return the polls
*/
public ArrayList<String> getPolls() {
ArrayList<String> ret = new ArrayList<>();
for(String str : polls.keySet())
ret.add(str);
return ret;
}

@Override
public String toString() {
return "question: " + question + ", " + "type: " + type;
}
}
68 changes: 68 additions & 0 deletions AmirhosseinSana/4/src/VotingSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.util.ArrayList;

/**
* The type Voting system.
*/
public class VotingSystem {
private ArrayList<Voting> votingList;

/**
* Instantiates a new Voting system.
*/
public VotingSystem() {
votingList = new ArrayList<>();
}

/**
* Create voting.
*
* @param question the question
* @param type the type
* @param polls the polls
*/
public void createVoting(String question, int type, ArrayList<String> polls) {
Voting tmp = new Voting(type, question);
for(String poll : polls) {
tmp.createPoll(poll);
}
votingList.add(tmp);
}

/**
* Gets voting list.
*/
public void getVotingList() {
for(int i = 0; i < votingList.size(); i ++) {
System.out.println(votingList.get(i));
}
}

/**
* Gets voting.
*
* @param index the index
*/
public void getVoting(int index) {
System.out.println(votingList.get(index));
}

/**
* Vote.
*
* @param index the index
* @param person the person
* @param polls the polls
*/
public void vote(int index, Person person, ArrayList<String> polls) {
votingList.get(index).vote(person, polls);
}

/**
* Gets result.
*
* @param index the index
*/
public void getResult(int index) {
votingList.get(index).printVotes();
}
}
62 changes: 62 additions & 0 deletions AmirhosseinSana/5/src/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.util.Objects;

/**
* The type Circle.
*/
public class Circle extends Shape {
private double radius;

/**
* Instantiates a new Circle.
*
* @param r the r
*/
public Circle(double r) {
radius = r;
}

/**
* Gets radius.
*
* @return the 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 void draw() {
System.out.format("Circle, perimeter: %f, area: %f\n",
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 Double.compare(circle.radius, radius) == 0;
}

@Override
public int hashCode() {
return Objects.hash(radius);
}

@Override
public String toString() {
return "Circle{" +
"radius=" + radius +
'}';
}
}
23 changes: 23 additions & 0 deletions AmirhosseinSana/5/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* The type Main.
*/
public class Main {
/**
* The entry point of application.
*
* @param args the input arguments
*/
public static void main(String[] args) {
Paint paint = new Paint();

paint.addShape(new Circle(2));
paint.addShape(new Triangle(2, 3, 4));
paint.addShape(new Triangle(2, 2, 2));
paint.addShape(new Rectangle(2, 3, 2, 3));
paint.addShape(new Rectangle(4, 4, 4, 4));

paint.describeEqualSides();
paint.drawAll();
paint.printAll();
}
}
Loading