/** For our user login accounting program, a user is a person who has * account on the system. We are interested in keeping track of the * person's username (a String) and a count of the number of times that * user has logged in. * Later, we may want to improve the program by adding an attribute that * sums the total time (minutes) the person was logged in. */ public class User { private String name; private int numLogins; /** Constructor: When we want to create a user on the system, * it is reasonable to expect the person will be given a name * but no logins yet. But to be flexible, let's make both variables * parameters, so it'll become a typical initial-value constructor. */ public User (String name, int numLogins) { this.name = name; this.numLogins = numLogins; } // At some point we may wish to retrieve a user's attributes. // Note that with Javadoc, it's not necessary to include the name // of the function in the comment. /** Return the String containing the user's username. */ public String getName() { return name; } /** Return the number of logins associated with this user's account. */ public int getNumLogins() { return numLogins; } /** Return a string representation of the user object. * Here's something to think about: how would we change this function * if we wanted the word "logins" to be singular if numLogins is 1? */ public String toString() { return String.format("%-8s %4d logins", name, numLogins); } /** Provide a way for us to add 1 to the number of logins. */ public void addLogin() { ++numLogins; } }