![]() |
Assignment 10Task
Learn some of the methods of Java's StepsWe're going to write a class that represents the details of a simple user account on a computer system, including full name, first name, last name, initials, username, password, and email address.
Write a class named Instance variables. Whatever you think you need, though they should all be private.
Static variable. One constant (that is, private static final String DOMAIN = "ics.hawaii.edu"; Constructor. You need a constructor that takes only the new user's full name. (If you want to write additional constructors, you may. But your class needs to work properly if only this one constructor is called.)
Accessor methods. Here are the methods you need and descriptions of what they should do in an easily-pasted format. You may use the included /** javadoc */ if you wish. However, do this only if they accurately describe your finished methods! /** * Returns this user's complete name. */ public String getFullName() {} /** * Returns only the user's first name. * That is, returns all characters up to the first space in their full name. * If there is no space in their name, then returns an empty string (""). */ public String getFirstName() {} /** * Returns only the user's last name. * That is, returns all characters from the last space in their full name * to the end of their full name. * If there is no space in their name, then returns the whole name. */ public String getLastName() {} /** * Returns this user's initials. * That is, returns the first letter of each word in their name, * taken together and capitalized, without dots between them. */ public String getInitials() {} /** * A user's username consists of the first letter of each of their first * and middle name(s) (if any), followed by enough of their last name * to fill 8 characters. * * If their last name is short, then the username may be fewer than 8 characters. * In the unlikely event that they have more then 8 words in their name, * the username may be longer than 8 characters (implementation dependent). * * The username is all lowercase. */ public String getUsername() {} /** * The user's email address is their username@DOMAIN. * That is, user.getUsername() + "@" + UserAccount.getDomain() */ public String getEmailAddress() {} /** * Returns this user's current password. * (This method does not generate a new password each time.) * * The returned password is a string of 8 random characters, * including only lowercase letters, uppercase letters, and digits. * It does not include any punctuation. */ public String getPassword() {} /** * Returns the domain name of the system hosting all UserAccounts. */ public static String getDomain() {}
Note that only Mutators methods. Since our system is going to construct usernames from users' full names, we don't want to let users change their name once they sign up for an account. (If they want to do that, they'll have to just delete their account and create a new one.) So the only mutator method we have is: /** * The new password passed to this method should contain at least one character * and should contain only lowercase letters, uppercase letters, or digits. * If it does not, this method will not use it to replace the current password. * * This method returns true if the new password was acceptable; * it returns false if there was a problem and the password for this account * was not updated. */ public boolean setPassword(String newPassword) {}
You will need to use the methods of the String class to complete this assignment. Go to the Java API Documentation and have a look in the Testing
If you like, you can also add a
In addition, your Sample OutputHere is some sample output from running UserAccountCreator: D:\TA\hw\A10>java UserAccountCreator You are creating an account on the ics.hawaii.edu system. Enter your full name: Zachary Michael Tomaszewski --- Your new account details --- Full name: Zachary Michael Tomaszewski First name: Zachary Last name: Tomaszewski Initials: ZMT Username: zmtomasz Email address: zmtomasz@ics.hawaii.edu Password: d0k00bQt Password (reconfirmed): d0k00bQt Enter new password: 4superDuperSecret Password changed. D:\TA\hw\A10>java UserAccountCreator You are creating an account on the ics.hawaii.edu system. Enter your full name: rambo --- Your new account details --- Full name: rambo First name: Last name: rambo Initials: R Username: rambo Email address: rambo@ics.hawaii.edu Password: KACswkl6 Password (reconfirmed): KACswkl6 Enter new password: big gun! Password not changed: "big gun!" is invalid. Hints and Suggestions
What to submit
Attach your FAQs
GradingOut of 10 points:
|
~ztomasze Index :
TA Details: ICS111:
Assignment 10 http://www2.hawaii.edu/~ztomasze |
Last Edited: 11 Mar 2008 ©2008 by Z. Tomaszewski. |