
package userIO;
import java.util.*;
import ConnectToDB.ConnecToDB;
import java.sql.*;
/**
 *
 * @author Soukaina
 */
public class UserIO {
  
    private ResultSet res;
    private User user=new User();
    private ArrayList<User> users=new ArrayList<>();  
    
   //Create a default constructor 
    public UserIO()
    {
        //It should be nothing inside 
        
    }
          
    //This method read all users records from user table in BHCCgame datebase and save all the records inside an arraylist
    public void readUsers(ConnecToDB conn)
    {
         
        //Create a query 
        String query="SELECT * FROM PLAYER";
        
        try
        {
            res=conn.getStm().executeQuery(query);
            while(res!=null)
            {
                user=new User(res.getInt(1), res.getString(2));
                users.add(user);
            }
        }catch (SQLException exception)
        {
            System.out.println(exception.getMessage());
        }
    }
    
    //This method accept a username as a paramter to go look in the array list return
    //by readusers() methods above and see if the username existe or not. 

   
   public int checkTheUserOut(String username)
   {
       
       int userId=0;
      for (int i=0; i<users.size(); i++)
      {
          if(username.equals(users.get(i).getUsername()))
          {
              userId=users.get(i).getUserId();
          }
      }
      return userId;
   }
}

@@ -1,8 +1,11 @@
+%0D%0A 
 %0D%0Apackag
@@ -66,16 +66,48 @@
 necToDB;
+ // Import my ConnectToDB pakage
 %0D%0Aimport
@@ -155,16 +155,118 @@
 a%0D%0A */%0D%0A
+ %0D%0A // UserIO  conains methods that manipulates the data %0D%0A //in the user table in the game database%0D%0A
 public c
@@ -483,50 +483,8 @@
     
-  //It should be nothing inside %0D%0A        
 %0D%0A  
@@ -498,32 +498,33 @@
         %0D%0A    //
+ 
 This method read
@@ -579,16 +579,25 @@
 atebase 
+%0D%0A    // 
 and save
@@ -634,16 +634,22 @@
 aylist%0D%0A
+    %0D%0A
     publ
@@ -691,27 +691,16 @@
 %0A    %7B%0D%0A
-         %0D%0A
         
@@ -697,24 +697,25 @@
 %0D%0A        //
+ 
 Create a que
@@ -1139,24 +1139,30 @@
    %7D%0D%0A    %0D%0A
+    %0D%0A
     //This m
@@ -1312,18 +1312,16 @@
  not. %0D%0A
-%0D%0A
    %0D%0A   
@@ -1371,25 +1371,16 @@
 %0D%0A   %7B%0D%0A
-       %0D%0A
        i

Update UserIO.java