Commit b2145d02 authored by 9831067's avatar 9831067

Add project to git!

parents
Pipeline #2883 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="F:/java/WorkSpace/group24-9831067/JalaliCalendar-1.3.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>group24-9831067</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=10
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=10
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=10
File added
File added
File added
import ir.huri.jcal.JalaliCalendar;
public class Person {
//firstName of person
private String firstName ;
//lastName of person
private String lastName ;
/**
* Create a new person with given firstName and LastName
* @param firstName firstName of person
* @param lastName lastName of person
*/
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
/**
* Get fisrName of person
* @return
*/
public String getFirstName() {
return firstName;
}
/**
* Get lastName of person
* @return
*/
public String getLastName() {
return lastName;
}
@Override
public String toString() {
return "Person --> firstName= " + firstName + ", lastName= " + lastName ;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
return true;
}
}
import java.util.ArrayList;
import java.util.Random;
import java.util.stream.IntStream;
public class Run{
public static void main(String[] args) {
Person person = new Person("ali", "nowrouzi");
Person person2 = new Person("poorya" , "nowrouzii");
Person person3 = new Person("payman", "nowrouziii") ;
Person randomPerson = new Person("MrRandom" , "Randomly") ;
ArrayList<String> options1 = new ArrayList<String>() ;
options1.add("notOk") ;
options1.add("fine!") ;
options1.add("bad") ;
options1.add("nice") ;
ArrayList<String> options2 = new ArrayList<String>() ;
options2.add("goooood") ;
options2.add("notOk") ;
options2.add("veryBad") ;
ArrayList<String> options13 = new ArrayList<String>() ;
options13.add("veryBad") ;
ArrayList<String> options14 = new ArrayList<String>() ;
options14.add("notOk") ;
options14.add("veryBad") ;
//at the first create the randomArray
//randomArray has a random length
//randomArray has a random elements of each of ArrayLists
ArrayList<String> randomArray = new ArrayList<String>() ;
//array is an ArrayList that we are work with
ArrayList<String> array = options1 ;
Random random = new Random() ;
int size = array.size() ;
int randomLentgh = random.nextInt(size) + 1 ;
for(int i = 0 ; i< randomLentgh ; i++) {
int randomElementIndex = random.nextInt(array.size() ) ;
randomArray.add(array.get(randomElementIndex)) ;
}
VotingSystem votingSystem = new VotingSystem() ;
votingSystem.createVoting("how are you?", 0, options1);
votingSystem.createVoting("what?", 0, options2);
votingSystem.vote(0, randomPerson, randomArray);
votingSystem.vote(1, person3, options2);
votingSystem.vote(1, person2, options2);
votingSystem.vote(1, person, options2);
votingSystem.vote(0, person, options1);
votingSystem.vote(0, person2, options1 );
votingSystem.printVotingQuestions();
votingSystem.printVoting(0);
votingSystem.printResult(0);
votingSystem.printVoting(1);
votingSystem.printResult(1);
}
}
import ir.huri.jcal.JalaliCalendar;
public class Vote {
// person who voted
private Person person ;
// date of vote
private String date ;
/**
* Create a new vote with given person and date
* @param person person who voted
* @param date when the person voted
*/
public Vote(Person person, String date) {
this.person = person;
this.date = date;
}
/**
* Get a person from a PersonClass
* @return
*/
public Person getPerson() {
return person ;
}
/**
* Get date of voting
* @return
*/
public String getDate() {
return new JalaliCalendar().toString() ;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((person == null) ? 0 : person.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Vote other = (Vote) obj;
if (person == null) {
if (other.person != null)
return false;
} else if (!person.equals(other.person))
return false;
return true;
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import ir.huri.jcal.JalaliCalendar;
public class Voting {
// type of question
private int type ;
// question for voting
private String question ;
//arrayList of persons who voted
private ArrayList<Person> voters ;
//HashMap of choices and votes
private HashMap<String, HashSet<Vote>> listOfVotesToChoices ; ;
/**
* Create new voting with given type and question
* @param type Type of vote
* @param question
*/
public Voting(int type, String question) {
voters = new ArrayList<Person>() ;
listOfVotesToChoices = new HashMap<String, HashSet<Vote>>() ;
this.type = type;
this.question = question;
}
/**
* Get a question of voting
* @return
*/
public String getQuestion() {
return question ;
}
/**
* Create a choice for question
* @param option choice for question
*/
public void createChoice (String option) {
listOfVotesToChoices.put(option, new HashSet<Vote>()) ;
}
/**
* Create a vote with given person and arrayList of choices
* @param person Person who voted
* @param choice Choices of person for question
*/
public void createVote(Person person , ArrayList<String> choice) {
String date = new JalaliCalendar().toString() ;
if(type== 0) {
if(listOfVotesToChoices.containsKey(choice.get(0)) ) {
Vote vote = new Vote(person, date) ;
boolean bool = listOfVotesToChoices.get(choice.get(0)).contains(vote) ;
if(bool) {
System.out.println("Votes have alreadey been submitted!\n");
}
else {
listOfVotesToChoices.get(choice.get(0)).add(vote) ;
voters.add(person) ;
}
}
}
else {
boolean voterBool = false ;
boolean boool = false ;
for(String str : choice) {
if(listOfVotesToChoices.containsKey(str)) {
boool = true ;
Vote vote = new Vote(person, date) ;
boolean bool = listOfVotesToChoices.get(str).contains(vote) ;
if(!bool){
listOfVotesToChoices.get(str).add(vote) ;
voterBool = true ;
}
}
}
if(voterBool) {
voters.add(person) ;
}
if(!voterBool && boool ) {
System.out.println("Votes have alreadey been submitted!\n") ;
}
}
}
/**
* print result of this question
*/
public void printVotes() {
Set<String> keySet = listOfVotesToChoices.keySet() ;
System.out.println("Result of this question!: " + getQuestion() + "");
int i = 1 ;
for(String key : keySet) {
int choiceSize = listOfVotesToChoices.get(key).size() ;
System.out.println(" "+ i++ + ": " + key +" --> " + choiceSize );
}
System.out.println("Voters : ");
getVoters();
System.out.println();
}
/**
* print voters who voted this question
*/
public void getVoters() {
if(voters.size() == 0)
System.out.println(" Nobody has voted this question!");
else {
HashSet<Vote> votes = new HashSet<Vote>() ;
Set<String> keys = listOfVotesToChoices.keySet() ;
for(String key : keys) {
Set<Vote> hashSets = listOfVotesToChoices.get(key) ;
for(Vote hashSet : hashSets) {
votes.add(hashSet) ;
}
}
for(Vote vote : votes) {
System.out.println(" " + vote.getPerson().toString() + " Date-->" + vote.getDate().toString() ) ;
}
}
}
/**
* print choices for this question
*/
public void getChoices() {
int i = 1 ;
Set<String> choices = listOfVotesToChoices.keySet() ;
for(String choice : choices ) {
System.out.println(" " + i++ + ": " + choice);
}
System.out.println();
}
}
import java.util.ArrayList;
public class VotingSystem {
//ArrayList of voting
private ArrayList<Voting> votingList ;
/**
* Create a new VotingSystem
*/
public VotingSystem() {
votingList = new ArrayList<Voting>() ;
}
/**
* Create a voting with given question and type and options
* @param question question of voting
* @param type type of voting
* @param options choices of this voting
*/
public void createVoting(String question , int type , ArrayList<String> options ) {
Voting voting = new Voting(type, question) ;
for(String option : options) {
voting.createChoice(option);
}
votingList.add(voting) ;
}
/**
* vote on a question
* @param votingNumber number of voting
* @param person person who voted
* @param personChoices choices of person
*/
public void vote(int votingNumber , Person person , ArrayList<String> personChoices) {
votingList.get(votingNumber).createVote(person, personChoices);
}
/**
* print a voting by given votingNumber index
* @param votingNumber index of votingList
*/
public void printVoting(int votingNumber){
String question = votingList.get(votingNumber).getQuestion() ;
System.out.println("Question is : " + question );
votingList.get(votingNumber).getChoices() ;
}
/**
* print a questions of votingSystem
*/
public void printVotingQuestions(){
if(votingList.size() == 0) {
System.out.println("VotingList is empty! ");
;
}
else {
System.out.println("List Of Voting Questions : ");
int i = 1 ;
for(Voting voting : votingList) {
String question = voting.getQuestion() ;
System.out.println(" Question"+ i++ + ": "+ question);
}
}
System.out.println();
}
/**
* print result of voting with given votingNumber index
* @param votingNumber index of votingList
*/
public void printResult(int votingNumber) {
votingList.get(votingNumber).printVotes();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment