Here's a description of the third programming assignment for CSE 11. In this assignment, you will get more experience with object-oriented programming by designing, implementing, and testing Java classes.
>>> Due deadline: ...
>>> Required solution files: Person.java Account.java ElevenDollar.java
This means that the files that contain your solution to the assignment must be turned in by the due deadline. Use the bundleP3 script to turn in your assignment.
It's a good idea to plan to do the assignment well before the deadline; terminals and tutors can get very busy at the last minute.
In doing this assignment, it's your responsibility to understand the course rules for integrity of scholarship.
Money is not a neutral concept--it can be both positive, as in Japan's fureai kippu, and negative, as some think the dollar has become. In this project we will create a currency completely online with a program, and attempt to make use of it.
Currency, as is noted in the above link, is based on trust. When you pay someone dollars for a gallon of milk ($3.95, the last time I bought one), they trust the dollar. They believe that someone else will give them goods and services for that same dollar. They place faith in the dollar, and without this faith the currency is useless. No amount of counterfeit-proofing or security measures can force someone to believe in the dollar--they must do so on their own to make it valuable.
The CSE 11 class will be creating a currency called the 11-dollar, similar to the time-dollar. We will set the value of this currency by telling you what to expect from it, and how much faith you can put into it. An 11-dollar is worth a favor from a fellow CS11 student. It is worth making someone a peanut-butter and jelly sandwich, or xeroxing a copy of lecture notes. It is worth an hour of essay proofreading, or baking a batch of brownies for someone who's heading to the labs. It is approximately worth the same as an hour of your time.
You will not be forced to use this currency--if someone wants your time from you and wants to pay you in 11-dollars, you are not forced to accept. But if you do, someone else may wish to reciprocate in the future, when they have some time to spare.
We hope that the nature of this currency will promote its use, and that an 11-dollar may one day be preferred over an ordinary dollar. This is because when a dollar is spent, it has traveled through a thousand anonymous hands. But when an 11-dollar is spent, it is only through favors to other students. For those of you that have seen the movie "Pay It Forward," this is a method to promote favors without making it appear like charity. Instead it has more similar to an equal trade.
No money will be printed--it's quite difficult to create physical currency that could avoid fraud. Instead a database will hold the accounts of all CS11 students. In this project you will write a program to access this database, and keep records of your 11-dollars.
The class will provide a server on the sunpal machines to handle accounts of each student. Accounts will be seeded with ten 11-dollars each, to represent the ten hours of spare time we expect you to have after this class is through with you. ;) Staff will have accounts as well, but may not charge for duties they would ordinarily perform. They are already being paid for their efforts in ordinary dollars.
A few caveats before we get into the project itself:
This assignment, like the previous two, require your classes and methods to be implemented according to given specifications. Make sure your method signatures match those given.
When finished, your program will function as this sample run
User input is in
; program output is in
plain teletype font.
[cs11w2@sunpal] java ElevenDollar Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit A Which user?(Leave blank to retrieve your own) cs11w Nickname:The Professor Secret Password:*SECRET* Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit A Which user?(Leave blank to retrieve your own) Nickname:SomeStudent Secret Password:11takes_time Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit B New Nickname?(default:SomeStudent) SupercoolStudent New Password?(default:11takes_time) 11isgr8 UPDATE CONFIRMED Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit C You have $10.00 Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit D To which account will you transfer? cs11w How much money? .20 Optional comment? Professor Tax TRANSACTION CONFIRMED Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit C You have $9.80 Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit E Sun Jan 18 22:43:59 PST 2004 cs11w2 cs11w 20 Professor Tax Welcome to the 11-dollar banking system A)Retrieve personal information B)Update your personal information C)Check your balance D)Transfer money to another account E)Check your transaction history X)Exit XIf everything was implemented correctly, the owner of account cs11w should be .20 11-dollars (that is, 20 11-cents) richer.
For each menu choice, your program will communicate to the central server, sending and receiving information about your account. Communication will performed through Strings, which are sent and received through a single method in a class ElevenClient. This class will be given to you--through the magic of abstraction you will need no knowledge of the details of how the server or the network is implemented.
public static String sendMessage(String msg)Call this method with a String you wish to communicate to the server. It will return the server's response as another String. The format for the argument is: a command, followed by zero or more arguments separated by a tab character ('\t'). The following is a table of Strings the server will understand, and their expected replies.
|Command Format||Description||Server Reply|
|BALANCE||requests your balance||BALANCE\t[amount]|
|TRANSFER\t[username]\t[amount]\t[comment]||give money to another user||TRANSACTION CONFIRMED|
|GETINFO||get your personal information||USERINFO\t[nickname]\t[password]|
|GETINFO\t[username]||get another user's info. Note that because this user isn't you, you don't get their password.||"USERINFO\t[nickname]\t*SECRET*"|
|UPDATEINFO\t[nickname]\t[password]||update your stored information||"UPDATE CONFIRMED"|
|GET_HISTORY||Retrieve your transaction history.||[timestamp]\t[from]\t[to]\t[amount]\t[comment]|
[amount]in these strings is an integer number representing 11-cents; so 500 represents five 11-dollars. (The square brackets  are notation; they don't actually appear in these strings.)
For this class you will be defining two constructors:
public Person(String nickname, String password)Stores the nickname and password in instance variables.
public Person(String netString)The netString expected is of the format "[username]\t[password]". Parses this string and stores the username and password in instance variables.
public String getNickname()Returns the nickname
public String getPassword()Returns the password
public void setNickname(String nickname)Sets the nickname to the String passed in
public void setPassword(String password)Sets the password to the String passed in
public boolean equals (Object other)Checks to see if the object passed in is a Person, and has the same nickname and password as the Person this was called on. We won't be using the equals method, but it is good practice to implement one for data types in case you need to compare them in the future.
public String toString()Returns a string of "Nickname:" followed by the nickname, a newline, and then "Password:" followed by the password. (No added spaces!) Suitable for printing to the screen.
public String netString()Returns a concatenation of the nickname followed by a tab and then the password. Useful for certain network commands, particularly UPDATEINFO.
An account needs information stored in a Person to function, so it makes sense to store a Person inside an Account. As for methods, there are three things you can do to an account--namely, update the user information, check its balance, and transfer money to another account.
Make sure this Person has protected visibility. This means
future, if a subclass needs to access this Person, it may do so. Name
this variable "myIdentity", as follows.
private Person myIdentity;
Your Account class will hold one Person object in it, one constructor, one accessor, and five methods.
public Account()Create an new account. Initialize the stored person to null.
public Person getPerson()Return the stored Person. ElevenDollar will use this to modify portions of the stored Person before calling updateInformation(). Methods:
public Person getInformation()Sends a GETINFO request to the server. Parses the reply and creates a new Person object with the name and password initialized. Returns this new Person object.
public Person getInformation(String username)Sends a GETINFO request to the server with one argument. Parses the reply and returns a Person object. Note that the password replied by the server will be "*SECRET*"
public String updateInformation()Sends an UPDATEINFO request to the server, using the stored Person for information to be transmitted.
public double checkBalance()Sends a BALANCE request to the server. It returns the balance, modified to have two decimal places. If the server returns ERROR, then checkBalance()'s results are undefined. That is, your program can do whatever it wants in that case.
public String transferToAcct(String user, double amount, String comment)Sends a TRANSFER request to the server, requesting amount funds to be transferred to the user. The comment part of the request will be stored in the server's database. The server's reply is returned. Remember that you must convert amount to a format that ElevenClient will understand--that is, an amount of 4.92 should be converted to 492 before placed in the message string.
I transferred all my money to someone on accident! What do I do
Be careful with the numbers you're sending around--1000 in the amount field is all ten 11-dollars you're seeded with. If you make a mistake, ask them (politely) if they can give it back, or ask a TA/tutor to loan you some money to test your program with.
What does readLine() return if I just hit enter?
readLine() will return the empty string, "", which you can compare to other strings with the .equals method.
Should I use my social security number, credit card number, PIN
number, or anything important for my password?
No. I actually suggest making it whimsical or funny as opposed to secure, since you can always retrieve it and you can always change it, and it doesn't protect all that much.
What if a program generates an Account and calls
updateInformation before getInformation?
You will almost certainly get a NullPointerException, which is okay for this assignment. Error handling will also be covered in P4.
a. 4 points for your Person classIn each case, doing a part of the assignment means that your code compiles, runs correctly, satisfies the specifications, is well-written and commented.
b. 12 points for your Account class
c. 4 points for your ElevenDollar class