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
2 changes: 2 additions & 0 deletions AmirrezaRajabi/AmirrezaRajabi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Full Name: AmirrezaRajabi
Student Number: 9831126
40 changes: 40 additions & 0 deletions AmirrezaRajabi/AmirrezaRajabi_9831126_4&5/session4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.ArrayList;

public class Main {

public static void main(String[] args) {
VotingSystem votingsystems = new VotingSystem();
Person voter1 = new Person("amirreza","rajabi");
Person voter2 = new Person("amirhosein","rajabi");
Person voter3 = new Person("mostafa","rajabi");
ArrayList<String> choices1 = new ArrayList<>();
ArrayList<String> choices2 = new ArrayList<>();
choices1.add("supergirl");
choices1.add("superman");
choices1.add("flash");
choices2.add("batman");
choices2.add("batwoman");
choices2.add("arrow");
votingsystems.createVoting("who is the best hero?",0,choices1);
votingsystems.createVoting("who is the best hero?",0,choices2);
ArrayList<String> choice1 = new ArrayList<>();
choice1.add("supergirl");
ArrayList<String> choice2 = new ArrayList<>();
choice2.add("batman");
ArrayList<String> choice3 = new ArrayList<>();
choice3.add("arrow");
votingsystems.getVotingList().get(0).createChoice("blackcanary");
votingsystems.vote(0,voter1,choice1);
votingsystems.vote(0,voter2,choice1);
votingsystems.vote(0,voter3,choice1);
votingsystems.vote(1,voter1,choice2);
votingsystems.vote(1,voter2,choice3);
System.out.println(votingsystems.getVotingList().get(0).getQuestion());
System.out.println("");
votingsystems.printResults(0);
System.out.println("\n\n\n\n\n");
System.out.println(votingsystems.getVotingList().get(1).getQuestion());
System.out.println("");
votingsystems.printResults(1);
}
}
49 changes: 49 additions & 0 deletions AmirrezaRajabi/AmirrezaRajabi_9831126_4&5/session4/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Person class represent a person
*/
public class Person
{
//first name
private String firstName;
//last name
private String lastName;

/**
* create a new person
* @param fName first name
* @param lName last name
*/
public Person(String fName , String lName)
{
this.firstName = fName;
this.lastName = lName;
}

/**
* get first name of person
* @return first name
*/
public String getFirstName()
{
return firstName;
}

/**
* get last name of person
* @return last name
*/
public String getLastName()
{
return lastName;
}

/**
* person to string
* @return name
*/
public String toString()
{
String name =this.firstName + " " + this.lastName;
return name;
}
}
52 changes: 52 additions & 0 deletions AmirrezaRajabi/AmirrezaRajabi_9831126_4&5/session4/Vote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.Objects;

/**
* Vote class reresent a vote
*/
public class Vote {
//person
private Person voter;
//date
private String date;

/**
* create a vote
* @param voter voter
* @param date date
*/
public Vote(Person voter , String date)
{
this.voter = voter;
this.date = date;

}

/**
* get the voter
* @return voter
*/
public Person getPerson() {
return voter;
}

/**
* date of vote
* @return vote
*/
public String 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(voter, vote.voter) && Objects.equals(date, vote.date);
}

@Override
public int hashCode() {
return Objects.hash(voter,date);
}
}
100 changes: 100 additions & 0 deletions AmirrezaRajabi/AmirrezaRajabi_9831126_4&5/session4/Voting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import ir.huri.jcal.JalaliCalendar;

/**
* Voting class represent a Voting
*/
public class Voting {
//type of voting 0: single vote , 1: multi votes
private int type;
//question voting
private String question;
//voters
private ArrayList<Person> voters;
//list of vote to choices
private HashMap<String, HashSet<Vote>> listOfVotesToChoices;

/**
* create a voting
* @param type type of voting
* @param question question of voting
*/
public Voting(int type , String question)
{
this.type = type;
this.question = question;
this.listOfVotesToChoices = new HashMap<>();
this.voters = new ArrayList<>();
}

/**
* get a question of voting
* @return question
*/
public String getQuestion() {
return question;
}

/**
* create a choices
* @param choice
*/
public void createChoice(String choice){
listOfVotesToChoices.put(choice,new HashSet<Vote>());
}

/**
* do a vote
* @param voter voter
* @param choices choices
*/
public void vote(Person voter,ArrayList<String> choices){
voters.add(voter);
if(type==0){
JalaliCalendar date = new JalaliCalendar();
Vote vote = new Vote(voter,date.toString());
listOfVotesToChoices.get(choices.get(0)).add(vote);
}
if (type == 1){
for(String choice:choices){
JalaliCalendar date = new JalaliCalendar();
Vote vote = new Vote(voter,date.toString());
listOfVotesToChoices.get(choice).add(vote);
}
}
}

/**
* get voters of voting
* @return
*/
public ArrayList<Person> getVoters() {
return voters;
}

/**
* get choices of voting
* @return
*/
public ArrayList<String> getChoices(){
ArrayList<String> choices = new ArrayList<>();
for(String key:listOfVotesToChoices.keySet())
{
choices.add(key);
}
return choices;
}

/**
* voting result
*/
public void printVotes()
{
for(String key:listOfVotesToChoices.keySet()){

System.out.println(key + ": " + listOfVotesToChoices.get(key).size() + " votes ");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import java.util.ArrayList;

/**
* represent voting System
*/
public class VotingSystem {
//list of voting
private ArrayList<Voting> votingList;

/**
* create a voting System
*/
public VotingSystem()
{
this.votingList = new ArrayList<>();
}

/**
* create a voting
* @param question question
* @param type type of voting
* @param choices voters can choice
*/
public void createVoting(String question,int type,ArrayList<String> choices)
{
Voting voting = new Voting(type,question);
for(String choice:choices){
voting.createChoice(choice);
}
votingList.add(voting);
}

/**
* print voting questions
*/
public void printVotingQuestions()
{
for(Voting voting:votingList){
System.out.println(voting.getQuestion());
}
}

/**
* print voting
* @param votingNumber voting number
*/
public void printVoting(int votingNumber)
{
Voting voting = votingList.get(votingNumber-1);
System.out.println(voting.getQuestion());
for(String choice:voting.getChoices()){
System.out.println(choice);
}
}

/**
* vote to a voting
* @param votingNum voting number
* @param voter voter
* @param choices choices
*/
public void vote(int votingNum ,Person voter ,ArrayList<String> choices){
Voting voting = votingList.get(votingNum);
voting.vote(voter,choices);
}

/**
* print result of a voting
* @param votingNumber voting number
*/
public void printResults(int votingNumber){
Voting voting = votingList.get(votingNumber);
voting.printVotes();
}

public ArrayList<Voting> getVotingList() {
return votingList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* circle Class inherits from Shape
*/
public class Circle extends Shape {
private int radius;

/**
* create a circle
* @param radius radius of circle
*/
public Circle(int radius) {
this.radius = radius;
}

/**
* calculate perimeter of circle: 2 * π * radius
* @return perimeter of circle
*/
@Override
public double calculatePerimeter() {
return 2 * Math.PI * radius;
}

/**
* calculate area of circle: π * radius * radius
* @return area of circle
*/
@Override
public double calculateArea() {
return Math.PI * radius * radius;
}

public int getRadius() {
return radius;
}

/**
* circle to string
* @return circle to string
*/
@Override
public String toString() {
return "circle (radius = " + radius +")";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Main {

public static void main(String[] args)
{
Paint paint = new Paint();
Shape circle1 = new Circle(19);
Shape circle2 = new Circle(3);
Polygon rectangle1 = new Rectangle(1,4,1,4);
Polygon rectangle2 = new Rectangle(8, 5, 8, 5);
Polygon rectangle3 = new Rectangle(6, 6, 6, 6);
Polygon triangle1 = new Triangle(2, 2, 2);
Polygon triangle2 = new Triangle(4, 4, 6);
paint.addShape(circle1);
paint.addShape(triangle1);
paint.addShape(rectangle1);
paint.addShape(rectangle2);
paint.addShape(rectangle3);
paint.addShape(triangle2);
paint.drawAll();
paint.printAll();
paint.describeEqualSides();
}
}
Loading