Guest User

Untitled

a guest
Feb 28th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. Assignment Analysis and Design
  2.  
  3. From Chapter 15 Exercise 4: “Creating User Names from Email Addresses. Email addresses are of the form [email protected] where xxx identifies the domain type. A new online software subscription service is free to anyone who is a student or who works for a school or college. Users are considered students if they have educational email address ending in “.edu” The person’s user name for the subscription service must be the name part of their email address.
  4. Your task is to create a method that will ask for the user’s email address, verify that it is an educational email address, then tell the user his or her user name, then ask the user to enter a new password. If the email address is not an educational email address, the program should tell the user this and allow the user to start over or end the program.”
  5. Using print statements to the console, I instructed the user to enter their email address. I used Scanner to record this input to a String. I passed this String to a validate function. If the string ended in “.edu” I returned a 1, else I returned a 0.
  6. If the String is valid, within main I find the location of the last @ character. Using this, I set username to be from substring sub 0 to substring of the last @ char. I inform the user of their username, have them enter a password. I had a System.exit(0); here to exit the program but I changed that to making again = ‘n’; to use the while loop to take advantage of the system.exit(0); already build into the main method which will be discussed a bit later.
  7. If email address is not an education email address, first I inform the user with a console message. I then print two options to the console: 1: to reenter email or 2: to quit program.
  8. If user enters 1, the program restarts. This is accomplished with the entire program being within a while loop. The while loops works by char again equaling ‘y’. As this is not interrupted, the loop restarts.
  9. If user enters 2, again is set to ‘n’, which causes the while loop to terminate. As the entire main function is encased in this while loop, the final statement is a System.exit(0); which terminates the program.
  10. If user enters anything aside from 1 or 2, an Invalid Option message prints and the program terminates.
  11.  
  12. Assignment Code
  13. See attached file
  14.  
  15. Assignment Testing
  16. I ran the program and confirmed the output was accurate. I tested this with multiple versions of email addresses, namely ones ending in .edu, emails without .edu, and options 1, 2, and options other than 1 and 2.
  17.  
  18. Assignment Evaluation
  19. This is a good assignment to work with Strings, but it’s not ideal for testing email addresses as there is a lot more to test than what is required in the assignment. I liked this assignment because I think there were a lot of ways to complete it and I think I could probably get a lot more efficient. I could also get more modular. I considered separating some of the logic into additional methods, namely everything involving finding the username. The logic seemed rather small so I kept it in the main method. However, upon further reflection I realize that my code will return an error if there is no @ character in the user inputted string, but it does end with a .edu. Dealing with this would probably increase the code to a point where I would want to modularize this and take it out of the main method. I also experimented a bit with having the invalid option loop back to “choose an option” under the else loop but the program didn’t call for this to happen so I decided it would also be appropriate to end the program at that point.
Advertisement
Add Comment
Please, Sign In to add comment