| CIS 210 Home Page | Last updated 2007/10/17 21:28:08 |
In this problem you are to code a simple object that has a constructor and whose only behavior is that it can be printed as a String.
When you sign up for a computer account or a web account, you often are given a user ID for logging in. A completely random string could be generated as your ID, but a better algorithm would generate something that is easier to remember. Using just your name is likely to collide with other users that have the same name, so we would like to address that issue as well, and have come up with the following requirements for the generated user ID:
Examples of running your code are:
Notice that in the driver code, there are no explicit method calls using the UserID object. So what are you supposed to code?C> javac TestUserID.java UserID.java C> java TestUserID Enter name: David Atkins The UserID is: datki713 C> java TestUserID Enter name: Thomas Wu The UserID is: twu97
Remember that the creation of an object means that a constructor is called. We can see from the way that the UserID object is created that there must be a constructor taking two String's as arguments, so you will have to code that.
How does the UserID object get printed out? Remember that every object in Java has a method that provides a String representation so that objects may be printed out. You must code this method as well as the constructor.
You may define class instance data to hold the generated ID. In particular, if the object is printed repeatedly, it should produce the same ID. Only if a new object is created should you see a different ID.