-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperviseCustomer.java
113 lines (92 loc) · 2.82 KB
/
SuperviseCustomer.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package oodp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.*;
import java.sql.*;
public class SuperviseCustomer
{
private static Connection conn;
private static Statement stmt;
private ResultSet rs;
private int number_of_student;
private int number_of_professor;
private ArrayList<Customer> customer;
private Iterator iterator;
public SuperviseCustomer()
{
customer = new ArrayList<Customer>();
try
{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "bitnami");
stmt=conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM stuinfo");
while(rs.next()){
if(rs.getInt("identifier")==1){
Student newStudent = new Student(rs.getString("id"),rs.getString("password"),rs.getInt("point"),rs.getInt("coupon"));
customer.add((Customer)newStudent);
number_of_student++;
}
else{
Professor newProfessor = new Professor(rs.getString("id"),rs.getString("password"),rs.getInt("coupon"));
customer.add(newProfessor);
number_of_professor++;
}
iterator = customer.iterator();
}
}
catch(Exception exc){}
}
public int getStudentNumber(){
return this.number_of_student;
}
public int getProfessorNumber(){
return this.number_of_professor;
}
public int getCustomerNumber(){
return this.number_of_student + this.number_of_professor;
}
public String[] getStudentList(){
String[] studentList = new String[this.getStudentNumber()];
int count = 0;
for(Customer temp : customer){
if(temp instanceof Student){
studentList[count] = temp.getId();
count++;
}
}
return studentList;
}
public String[] getProfessorList(){
String[] professortList = new String[this.getStudentNumber()];
int count = 0;
for(Customer temp : customer){
if(temp instanceof Professor){
professortList[count] = temp.getId();
count++;
}
}
return professortList;
}
public Customer findById(String id){
for(Customer temp : customer){
if((temp instanceof Professor)&&temp.getId().equals(id)){
Customer theProf = new Professor(temp.getId(),temp.getPassword(),temp.getCoupon());
return theProf;
}
if((temp instanceof Student)&&temp.getId().equals(id)){
try{
ResultSet qry = stmt.executeQuery("SELECT * FROM stuinfo");
while(qry.next()){
if(qry.getString("id").equals(id)){
Customer theStu = new Student(temp.getId(),temp.getPassword(),qry.getInt("point"),temp.getCoupon());
return theStu;
}
}
}
catch(Exception exc){}
}
}
return null;
}
}