Ejemplo n.º 1
0
  public static UserID createNewAccount(Scanner scan) {

    String username = checkString(Func.USERNAME, scan, true, null);
    String password = checkString(Func.PASSWORD, scan, true, null);
    String name = checkString(Func.NAME, scan, true, null);

    // Attributes
    Attributes.Gender gender =
        (Attributes.Gender) setUpEnumAttribute(scan, Attributes.AttributeEnum.GENDER);
    int age = makeSureValInRange(scan, 18, 200, "age", ValType.INTEGER, false, true).intValue();
    int weight =
        makeSureValInRange(scan, 70, 2000, "weight", ValType.INTEGER, false, true).intValue();
    double height =
        makeSureValInRange(scan, 3, 10, "height", ValType.DOUBLE, false, true).doubleValue();
    Attributes.Sexuality sexuality =
        (Attributes.Sexuality) setUpEnumAttribute(scan, Attributes.AttributeEnum.SEXUALITY);
    Attributes.EyeColor eyeColor =
        (Attributes.EyeColor) setUpEnumAttribute(scan, Attributes.AttributeEnum.EYE_COLOR);
    Attributes.HairColor hairColor =
        (Attributes.HairColor) setUpEnumAttribute(scan, Attributes.AttributeEnum.HAIR_COLOR);
    Attributes.Ethnicity ethnicity =
        (Attributes.Ethnicity) setUpEnumAttribute(scan, Attributes.AttributeEnum.ETHNICITY);
    Attributes.Education education =
        (Attributes.Education) setUpEnumAttribute(scan, Attributes.AttributeEnum.EDUCATION);
    Attributes.Zodiac zodiac =
        (Attributes.Zodiac) setUpEnumAttribute(scan, Attributes.AttributeEnum.ZODIAC);

    // preparing the fields to be packaged and updated in database
    String[] strFields = new String[Attributes.NUM_ENUM_FIELDS + UserID.NUM_UID_ENTRIES];
    int i = 0;
    strFields[i] = username;
    strFields[++i] = password;
    strFields[++i] = name;
    strFields[++i] = gender.toString();
    strFields[++i] = sexuality.toString();
    strFields[++i] = ethnicity.toString();
    strFields[++i] = eyeColor.toString();
    strFields[++i] = hairColor.toString();
    strFields[++i] = education.toString();
    strFields[++i] = zodiac.toString();
    DBConnect connection = new DBConnect();
    connection.insertRow(strFields, age, weight, height);
    // Update registered users hash table
    Attributes attr =
        new Attributes(
            gender, sexuality, eyeColor, hairColor, ethnicity, education, zodiac, age, weight,
            height);
    UserID user = new UserID(username, password, name, attr);
    registeredUsers.put(username, user);
    return user;
  }
Ejemplo n.º 2
0
  public UserManager() {

    registeredUsers = new Hashtable<String, UserID>(HTABLE_INIT_CAP, HTABLE_LOAD_FACT);
    DBConnect connection = new DBConnect();
    connection.setResultSet();
    ResultSet data = connection.getData();

    try {
      while (data.next()) {
        String username = data.getString("Username");
        String password = data.getString("Password");
        String name = data.getString("Name");

        String[] enumFieldString = new String[Attributes.NUM_ENUM_FIELDS];
        int start = UserID.NUM_UID_ENTRIES + 1;
        int i = start;
        int j = 0;
        while (i < start + Attributes.NUM_ENUM_FIELDS) {
          enumFieldString[j] = data.getString(i);
          i++;
          j++;
        }

        int age = data.getInt("Age");
        int weight = data.getInt("Weight");
        double height = data.getDouble("Height");

        Attributes attributes = new Attributes(enumFieldString, age, weight, height);
        UserID user = new UserID(username, password, name, attributes);
        registeredUsers.put(username, user);
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    connection.closeConnection();
  }