-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoting.java
More file actions
56 lines (44 loc) · 1.78 KB
/
Copy pathVoting.java
File metadata and controls
56 lines (44 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package System;
import Users.Candidate;
import java.sql.SQLException;
import java.util.Scanner;
public class Voting {
VotingSystem votingSystem;
Candidate candidate;
private String title;
public Voting(String title,VotingSystem votingSystem){
this.votingSystem = votingSystem;
this.title = title;
}
public String getTitle(){
return title;
}
public Candidate addCandidate(String NameCandidate) throws SQLException {
String query = "SELECT NameCandidate FROM election.candidate WHERE NameCandidate = " + "'" + NameCandidate + "'";
if (BDateMySql.query(query).next()) {
System.out.println("Уже есть такой");
} else {
BDateMySql.update("INSERT INTO election.candidate (NameCandidate,Voices) VALUES ('" + NameCandidate + "' ,'"+ 0 +"')");
Candidate candidate = new Candidate(NameCandidate);
this.candidate = candidate;
}
return candidate;
}
public void getListCandidate() throws SQLException {
String guery = "SELECT * FROM election.voters";
while (BDateMySql.query(guery).next()) {
int id = BDateMySql.query(guery).getInt("id");
String NameCandidate = BDateMySql.query(guery).getString("NameCandidate");
System.out.println(id + ". " + NameCandidate);
}
}
public void beginVoid(String Login,String Password) throws SQLException {
if (votingSystem.findUser(Login, Password)) {
getListCandidate();
Scanner in = new Scanner(System.in);
int choose = Integer.parseInt(in.nextLine());
String guery ="update election.candidate set Voices = Voices+1 where id = '" + choose + "' ";
BDateMySql.update(guery);
}
}
}