Assignment 4
due Thursday, February 7 at 11:59pm on Canvas


Pair Programming Extra Credit Opportunity (1 pt)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your source code files to Canvas.
  • Only ONE partner submits the assignment to Canvas. Please make sure both your names are on the files.

User Profiles Improved (10 pts)
  • Open up Profile.java and User.java and verify that the formatting of your code in these two files is correct (-1 for incorrect formatting).
  • In Profile.java, add the following method signature and implement the body of the method:
/**
     * Sorts an ArrayList of User objects alphabetically
     * according to email address, using the bubbleSort
     * algorithm
     * @param users the ArrayList of Users
     */
    public void bubblesort(ArrayList<User> users){}

  • Next, remove your linearSearch method and replace it with the following binarySearch method signature. Then add the body of this method:
   /**
     * Searches for a user whose email and password match
     * those currently stored in the users ArrayList
     * @param email the email that was input
     * @param password the password input
     * @param users the ArrayList storing customers on file
     * @return the location of the user or -1 if not found
     */
    public int binarySearch(String email, String password, ArrayList<User> users) {
        return -1;
    }
  • To call these methods (they are not static), you will need to make a new Profile object inside of main.
  • Place the below variable declaration at the top of main:
Profile p = new Profile();
  • Now, for example, you can call bubbleSort like this:
p.bubbleSort(users);
  • Finally, update your Profile.java class so that it writes out the *sorted* list of Users to an output file called accounts.txt once the program completes.
    • Make sure that any new Users are also displayed in the file.
  • Don't forget that you can always consult the ArrayList API (documentation) on the Oracle website for additional methods not covered in class.
  • When you are finished, upload User.java and Profile.java to Canvas.


Sample Output:

Welcome!

Enter your email address: leaperez@yahoo.com
Enter your password: letmein

Hi, Leanna Perez!
We have the following information on file for you:
Name: Leanna Perez
Gender: F
Phone: (408) 876-5443
Email: leaperez@yahoo.com

Alternately:

Welcome!

Enter your email address: jaylaw@sbcglobal.net
Enter your password: 555111jjjlll

Sorry! We don't have your account on file.
Let's create an account for you!

Enter your name: Jennifer Lawrence
Enter your gender: F
Enter your 10 digit phone number (no spaces or punctuation): 5555555555
Thank you, Jennifer Lawrence!
Your account has now been created.

Name: Jennifer Lawrence
Gender: F
Phone: (555) 555-5555
Email: jaylaw@sbcglobal.net



Sample accounts.txt Output File:

Name: Brad Feinman
Gender: M
Phone: (831) 202-3443
Email: bradisrad@gmail.com

Name: Mohammed Abbas
Gender: M
Phone: (408) 313-4444
Email: downtown_abbas@yahoo.com

Name: Alvin Ngo
Gender: M
Phone: (408) 925-6677
Email: drngo@hotmail.com

Name: Abir Fadel
Gender: M
Phone: (831) 664-5325
Email: greatabs@comcast.com

Name: Ally Gu
Gender: O
Phone: (408) 925-6776
Email: i_am_ally@comcast.net

Name: James Brown
Gender: M
Phone: (831) 567-8432
Email: jaime.boy.brown@hotmail.com

Name: Jung Ahrin
Gender: F
Phone: (831) 925-7788
Email: jung_ahrin@yahoo.com

Name: Jiming Wu
Gender: F
Phone: (408) 212-3458
Email: jwu@gmail.com

Name: Kumari Chakrabarti
Gender: F
Phone: (408) 666-7777
Email: kukuchakrabarti@hotmail.com

Name: Leanna Perez
Gender: F
Phone: ((40) 8) -765-
Email: leaperez@yahoo.com

Name: Pedro Martinez
Gender: M
Phone: (408) 616-2323
Email: pedro2018@sbcglobal.net

Name: Stacey Cahill
Gender: O
Phone: (831) 212-3333
Email: scahill@gmail.com

Name: Shakil Smith
Gender: M
Phone: (408) 212-3333
Email: shakattaq@gmail.com

Name: Tamara White
Gender: F
Phone: (831) 777-8978
Email: tamtastic@gmail.com

Name: Xing Li
Gender: M
Phone: (831) 321-4555
Email: xing.li@sbcglobal.net

Name: Xiaohang Yue
Gender: M
Phone: (831) 899-0033
Email: yue95@yahoo.com