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

Mohamadrezahakimi9831078 #34

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
82 changes: 82 additions & 0 deletions Mohamadrezahakimi/lab 4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

public static void main(String[] args) {

voting_system vs=new voting_system();
ArrayList<String> choices1=new ArrayList<>();

choices1.add("Ali");
choices1.add("reza");
choices1.add("gholi");
choices1.add("saba");
choices1.add("fateme");
choices1.add("parsa");

person person1=new person("a","A");
person person2=new person("b","B");
person person3=new person("c","C");
person person4=new person("d","D");

ArrayList<String> person1_choices=new ArrayList<>();
ArrayList<String> person2_choices=new ArrayList<>();
ArrayList<String> person3_choices=new ArrayList<>();
ArrayList<String> person4_choices=new ArrayList<>();

person1_choices.add("Ali");
person1_choices.add("reza");
person1_choices.add("unknown");

person2_choices.add("fateme");
person2_choices.add("Ali");
person2_choices.add("fateme");

person3_choices.add("reza");
person3_choices.add("saba");

vs.create_voting("who is the best teacher",1,choices1);

vs.vote(1,person1,person1_choices);
vs.vote(1,person2,person2_choices);
vs.vote(1,person3,person3_choices);
//showing user cant vote twice or more
vs.vote(1,person1,person2_choices);

vs.print_results(1);

person1_choices.removeAll(person1_choices);
person2_choices.removeAll(person2_choices);
person3_choices.removeAll(person3_choices);

ArrayList<String> choices2=new ArrayList<>();

choices2.add("iran");
choices2.add("america");
choices2.add("russia");
choices2.add("germany");
choices2.add("spain");

vs.create_voting("where is the most enjoyable place for you to live?:",0,choices2);

person1_choices.add("iran");
//showing he can't choose more than one for voting
person1_choices.add("spain");
person2_choices.add("russia");
person3_choices.add("russia");
person4_choices.add("iran");

vs.vote(2,person1,person1_choices);
vs.vote(2,person2,person2_choices);
vs.vote(2,person3,person3_choices);
vs.vote(2,person4,person4_choices);

vs.print_results(2);





}
}
22 changes: 22 additions & 0 deletions Mohamadrezahakimi/lab 4/person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class person {
private String first_name;
private String last_name;
public person(String first_name,String last_name){
this.first_name=first_name;
this.last_name=last_name;

}

public String getFirst_name() {
return first_name;
}

public String getLast_name() {
return last_name;
}

public String to_string(){
return first_name.concat(" "+last_name);
}
}

23 changes: 23 additions & 0 deletions Mohamadrezahakimi/lab 4/vote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class vote {
private person person;
private String date;
public vote(person person,String date){
this.date=date;
this.person=person;
}

public person get_person() {
return person;
}

public String getDate() {
return date;
}

public boolean equals(vote object){
if(object.get_person().to_string().equalsIgnoreCase(person.to_string())){
return true;
}
else return false;
}
}
92 changes: 92 additions & 0 deletions Mohamadrezahakimi/lab 4/voting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import ir.huri.jcal.JalaliCalendar;

import java.awt.*;
import java.awt.image.AreaAveragingScaleFilter;
import java.time.LocalDateTime;
import java.util.*;
import java.time.LocalDate;

public class voting {

private int type;
private String voting_question;
ArrayList<person> voters;
HashMap<String, HashSet<vote>> list_of_votes_to_choices;

public voting(int one_or_more_voting, String voting_question) {
this.voting_question = voting_question;
list_of_votes_to_choices = new HashMap<>();
voters = new ArrayList<>();
this.type = one_or_more_voting;
}

public void create_choice(String choice_explanation) {
if (!list_of_votes_to_choices.containsKey(choice_explanation)) {
list_of_votes_to_choices.put(choice_explanation, new HashSet<>());
}
}

public void vote(person person, ArrayList<String> choices) {
if ((type == 0 && choices.size() != 1) ) {
System.out.println("Mr or Ms " + person.to_string() + ": you can't choose more thane one choice then we just " +
"consider your first choice as your final decision ");
if (!voters.contains(person)) {
voters.add(person);

GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(new Date());
JalaliCalendar jalaliCalendar = new JalaliCalendar(gregorianCalendar);

vote vote = new vote(person, jalaliCalendar.toString());
String choice = choices.get(0);
if (list_of_votes_to_choices.containsKey(choice)) {
list_of_votes_to_choices.get(choice).add(vote);
} else System.out.println("we don't have this choice in this voting->" + choice);
} else {
System.out.println("Mr or Ms " + person.to_string() + ": you voted before");
}
}
else {
if (!voters.contains(person)) {
voters.add(person);

GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(new Date());
JalaliCalendar jalaliCalendar = new JalaliCalendar(gregorianCalendar);

vote vote = new vote(person, jalaliCalendar.toString());
for (String choice : choices) {
if (list_of_votes_to_choices.containsKey(choice)) {
list_of_votes_to_choices.get(choice).add(vote);
}
else System.out.println("we don't have this choice in this voting->"+choice);
}
}
else {
System.out.println("Mr or Ms "+person.to_string()+": you voted before");
}
}
}


public String getVoting_question() {
return voting_question;
}

public ArrayList<person> getVoters() {
return voters;
}

public void print_votes() {
for (String choice : list_of_votes_to_choices.keySet()) {
System.out.println(choice+":");
if(list_of_votes_to_choices.get(choice).size()!=0) {
for (vote vote : list_of_votes_to_choices.get(choice)) {
System.out.println("\t\t" + "name: "+vote.get_person().to_string() +"\ttime: "+ vote.getDate());
}
}
else System.out.println("\t\t"+"no nobody vote to this choice ");
}
}
}

35 changes: 35 additions & 0 deletions Mohamadrezahakimi/lab 4/voting_system.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.ArrayList;

public class voting_system {
ArrayList<voting> votingList;
public voting_system(){
votingList=new ArrayList<>();
}

public void create_voting(String question_name,int one_or_more_answer,ArrayList<String> choices){
voting a=new voting(one_or_more_answer,question_name);
votingList.add(a);
for (String choice:choices){
a.create_choice(choice);
}
}

public void print_voting_question(){
System.out.println("print voting's questions:");
for (voting voting:votingList) {
System.out.println("\t\t"+voting.getVoting_question());
}
}

public int vote(int voting_number, person person,ArrayList<String> choices){
voting_number--;
if(voting_number<0||voting_number>votingList.size())return -1;
votingList.get(voting_number).vote(person,choices);
return 0;
}

public void print_results(int voting_number){
voting_number--;
votingList.get(voting_number).print_votes();
}
}
33 changes: 33 additions & 0 deletions Mohamadrezahakimi/lab 5/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Circle extends shape{
private Integer radius=0;

public Circle(int radius){

this.radius=radius;
}

public boolean equal(Circle x){
if(this.getRadius()==x.getRadius()){
return true;
}
else return false;
}

public String to_string(){
return radius.toString();
}

public double calculate_perimeter() {
return 2*3.14*radius;
}

public double calculate_Area(){
return 3.14*(Math.pow(radius,2));
}

public int getRadius() {
return radius;
}
}


32 changes: 32 additions & 0 deletions Mohamadrezahakimi/lab 5/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Main {

public static void main(String[] args) {
Circle circle1=new Circle(1);
Circle circle2=new Circle(2);

rectangle rectangle1=new rectangle(1,2);
rectangle rectangle2=new rectangle(1,2);
rectangle rectangle3=new rectangle(3,3);

triangle triangle1=new triangle(2 ,3 ,3);
triangle triangle2=new triangle(2 ,3 ,3);
triangle triangle3=new triangle(3 ,3 ,3);

Paint paint=new Paint();

paint.addShape(circle1);
paint.addShape(circle2);

paint.addShape(rectangle1);
paint.addShape(rectangle2);
paint.addShape(rectangle3);

paint.addShape(triangle1);
paint.addShape(triangle2);
paint.addShape(triangle3);

paint.print_all();


}
}
53 changes: 53 additions & 0 deletions Mohamadrezahakimi/lab 5/Paint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import javafx.css.converter.LadderConverter;

import java.util.ArrayList;
import java.util.jar.JarOutputStream;

public class Paint {

ArrayList<shape> shapes=new ArrayList<>();

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

public void draw_all(){
for (shape shape:shapes) {
if(shape instanceof Circle){
System.out.println("Circle:"+"\tperimeter:"+shape.calculate_perimeter()+"\tArea: "+shape.calculate_Area());
}
else if(shape instanceof rectangle ){
System.out.println("Rectangle:"+"\tperimeter:"+shape.calculate_perimeter()+"\tArea: "+shape.calculate_Area());
}
else if(shape instanceof triangle){
System.out.println("Triangle:"+"\tperimeter:"+shape.calculate_perimeter()+"\tArea: "+shape.calculate_Area());

}
}
}

public void print_all(){
for (shape shape:shapes) {
System.out.println("\n");
if(shape instanceof Circle){
System.out.println("Circle:"+"\tperimeter:"+shape.calculate_perimeter()+"\tArea: "+shape.calculate_Area());
}
else if(shape instanceof rectangle ){
if(((rectangle) shape).isSquare()) {
System.out.println("Rectangle(it is square):" + "\tperimeter:" + shape.calculate_perimeter() + "\tArea: " + shape.calculate_Area());
}else {
System.out.println("Rectangle:" + "\tperimeter:" + shape.calculate_perimeter() + "\tArea: " + shape.calculate_Area());
}
}

else if(shape instanceof triangle){
if(!((triangle) shape).isEquilateral()) {
System.out.println("Triangle:" + "\tperimeter:" + shape.calculate_perimeter() + "\tArea: " + shape.calculate_Area());
}
else System.out.println("Triangle(equilateral):"+"\tperimeter:"+shape.calculate_perimeter()+"\tArea: "+shape.calculate_Area());

}
}
}

}
Loading