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
149 changes: 149 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

# Created by https://www.gitignore.io/api/java,windows,intellij
# Edit at https://www.gitignore.io/?templates=java,windows,intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/**/sonarlint/

# SonarQube Plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
SeyyedMahdiMirfendereski/AP-lab4/.idea
SeyyedMahdiMirfendereski/AP-lab4/out
*.iml
*.class
*.xml

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/java,windows,intellij
3 changes: 0 additions & 3 deletions RashadAnsari/RashadAnsari

This file was deleted.

42 changes: 42 additions & 0 deletions SeyyedMahdiMirfendereski/AP-lab4/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.util.ArrayList;

public class Main {
public static void main(String[] args){
VotingSystem testing=new VotingSystem();
Person firstPerson=new Person("Mahdi","Mirfendereski");
Person secondPerson=new Person("Ali","Mohammadi");
ArrayList<String> firstOptions=new ArrayList<>();
ArrayList<String> secondOptions=new ArrayList<>();
firstOptions.add("+");
firstOptions.add("-");
secondOptions.add("sunday");
secondOptions.add("friday");
secondOptions.add("saturday");
testing.createVoting("Do you come?",0,firstOptions);
testing.createVoting("Which day?",1,secondOptions);
testing.printVotingQuestions();
testing.printVoting(0);
// print voting testing
testing.printVoting(1);
ArrayList<String> votes1 =new ArrayList<>();
ArrayList<String> votes2 =new ArrayList<>();
votes1.add("+");
votes2.add("friday");
votes2.add("saturday");
testing.vote(0,firstPerson,votes1);
testing.vote(1,firstPerson,votes2);
testing.printResult(0);
//2 choices win
testing.printResult(1);
//voting randomly testing
testing.randomVote(0,secondPerson);
votes2.remove(0);
testing.vote(1,secondPerson,votes2);
testing.printResult(0);
testing.printResult(1);
System.out.println("first voting");
testing.getVoters(0);
System.out.println("second voting");
testing.getVoters(1);
}
}
34 changes: 34 additions & 0 deletions SeyyedMahdiMirfendereski/AP-lab4/src/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* this class keep first name and last name of person.
* @author Mahdi Mirfendereski
* @version 0.0
*/
public class Person {
private String firstName ;
private String lastName ;
/**
*
* @param firstName firstName of person
* @param lastName lastName of person
*/
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

@Override
public String toString() {
return "Person{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
'}';
}
}
41 changes: 41 additions & 0 deletions SeyyedMahdiMirfendereski/AP-lab4/src/Vote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.Objects;

/**
* this class represent a vote that include person and data information .
* @author Mahdi Mirfendereski
* @version 0.0
*/
public class Vote {
private Person person ;
private String date ;

/**
*
* @param person who wants voting
* @param date the date of voting
*/
public Vote(Person person, String date) {
this.person = person;
this.date = date;
}
public Person getPerson() {
return person;
}

public String getDate() {
return date;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Vote)) return false;
Vote vote = (Vote) o;
return Objects.equals(person, vote.person);
}

@Override
public int hashCode() {
return Objects.hash(person);
}
}
90 changes: 90 additions & 0 deletions SeyyedMahdiMirfendereski/AP-lab4/src/Voting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

import ir.huri.jcal.JalaliCalendar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;


/**
* this class includes type of voting ,question of voting ,voters and list Of Votes To Choices.
* @author Mahdi Mirfendereski
* @version 0.0
*/
public class Voting {
private int type;
private String question ;
private ArrayList<Person> voters ;
private HashMap<String, HashSet<Vote>> listOfVotesToChoices;

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

public int getType() {
return type;
}

public String getQuestion() {
return question;
}

/**
* adding a new choice to options
* @param choice new option
*/
public void createChoice(String choice) {
listOfVotesToChoices.put(choice,new HashSet<>());

}
public ArrayList<String> getChoices() {
return new ArrayList<>(listOfVotesToChoices.keySet());
}

/**
* record a vote for voter.
* @param voter who wants to vote
* @param choices choices that were decided by voter.
*/
public void vote(Person voter,ArrayList<String> choices){
//check if he is legal
if(!voters.contains(voter)){
voters.add(voter);
for (String s:choices)
listOfVotesToChoices.get(s).add(new Vote(voter,new JalaliCalendar().toString()));
}
}

/**
* print list of voters
*/
public void getVoters(){
for (Person p:voters)
System.out.println(p);
}

/**
* print result of voting
*/
public void printVotes(){
int max=0;
System.out.println(question);
ArrayList<String> choices=getChoices();
for (String s:choices)
if(listOfVotesToChoices.get(s).size()>max)
max=listOfVotesToChoices.get(s).size();
//if we have more than 1 choices that were decided
for (String s1:choices)
if(listOfVotesToChoices.get(s1).size()==max)
System.out.print(s1+":"+max+" | ");
System.out.println();
}
}
Loading