// Add a new user to the list of all users given a User object. public bool addUser(User u) { if(!userExists(u.getName())) { users.Add(u); return true; } return false; }
// Load user info from the textfile on the server. Parses the text file at USER_INFO_FILENAME private AllUsers loadUserInfo(string filename) { AllUsers users = new AllUsers(); StreamReader reader = new StreamReader(filename); while(!reader.EndOfStream) { string line = reader.ReadLine(); // reads [USER] line = reader.ReadLine(); // reads the user's name User currentUser = new User(line); // Create User object for the current user being parsed. // If [ is found immediately follow a user's name, then the user hasn't made any payments. if (reader.Peek() == '[') { users.addUser(currentUser); continue; } else { // Get all the payments made by a user and add them to User object. while(reader.Peek() != '[' && !reader.EndOfStream) { line = reader.ReadLine(); currentUser.addPayment(Convert.ToDouble(line)); } } users.addUser(currentUser); // add User object to the list of all users. } reader.Close(); return users; }