Advertisement
Guest User

Allez

a guest
Oct 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1.  
  2. public class LoginInfo
  3. {
  4.     //******  instance data ******/
  5.     private String loginID = "";        // Last_First name
  6.     private String password;            // default is 3 random characters A-Z
  7.    
  8.     //******  Constructor   ******/
  9.     /** Constructor, sets loginID to parameter (change format!)
  10.      *          sets password to a random String of 3 characters
  11.      * Precondition: parameter is not null, or of the form "first last" or ""
  12.      *          if parameter is empty string assign empty string to loginID
  13.      */
  14.     public LoginInfo(String id){
  15.         if (id.equals("")){loginID = "";}
  16.         loginID = id;
  17.         password = genDefaultPassword();
  18.     }
  19.    
  20.     //******  accessor methods  ******/
  21.    
  22.     /** getLoginID
  23.      * @return loginID (String)
  24.      */
  25.     public String getLoginID(){
  26.         return loginID;
  27.     }
  28.    
  29.     /** getPassword
  30.      * @return password (String)
  31.      */
  32.     public String getPassword(){
  33.         return password;
  34.     }
  35.    
  36.     //*******   modifier methods    ******/
  37.     /** setLoginID -- sets the loginID field to "Lastname_Firstname"
  38.      * Precondition: parameter is not null, or of the form "first last" or ""
  39.      * @param String sets the loginID field to "Last_First" or "" if n is ""
  40.      */
  41.     public void setLoginID(String id){
  42.         loginID = id;
  43.         if (id.equals("")){loginID = "";}
  44.     }
  45.    
  46.     /** setPassword
  47.      * @param the new password (String)
  48.      */
  49.     public void setPassword(String p){
  50.         password = p;
  51.     }
  52.    
  53.    
  54.     //*******   return methods  ******/
  55.     /** getInitials -- Extracts initials from loginID
  56.      * @return 2 characters, the first character of the first name
  57.      *          + first character of last name (String)
  58.      */
  59.     public String getInitials(){
  60.         return ("" + loginID.charAt((loginID.indexOf("_")+1)) + loginID.charAt(0)).toUpperCase();
  61.     }
  62.    
  63.    
  64.     /** getDisplayName -- Extracts first and last name from loginID,
  65.      *      returns "First Last", make sure the first char of each are
  66.      *      capitalized
  67.      * @return "Firstname Lastname" (String)
  68.      */
  69.     public String getDisplayName(){
  70.         String q = loginID.toUpperCase();
  71.         return "" + q.substring((q.indexOf("_")+1)) + " " + q.substring(0,q.indexOf("_"));
  72.     }
  73.    
  74.     public String genDefaultPassword(){
  75.         String p = "";
  76.         for(int i=0; i<3; i++){
  77.             p.concat("" + ((int) (Math.random() * 26) + 65));
  78.         }
  79.         return p;
  80.     }
  81.    
  82.     /** toString
  83.      * @return data (String) -- see Lab sheet for example
  84.      */
  85.     public String toString(){
  86.         return getDisplayName() + " (" + getInitials() + ") Login ID: " + getLoginID() + ", Password: " + getPassword();
  87.     }
  88.    
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement