Assignment 3
due Thursday, January 31 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 (10 pts)
  • Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects.
  • Once the information has been stored, the program should welcome a user and prompt him or her for an email and password
  • The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of the users stored in the ArrayList.
  • If the program finds a match, it should greet the user by name.
  • If the program does not find a match, it should print the message "Sorry! We don't have your account on file." to the console.
  • All of your code should be stored in two files: User.java and Profile.java
  • User.java is a class which defines a User. Given the starter code provided below, it is your job to complete the implementation of this class by writing the methods whose signatures are provided
  • Profile.java should contain a main method. In this main method, you should
    • Read in the data from the file, storing the information for each user in a User object
    • Insert each User object into the provided ArrayList
    • Complete the linearSearch method whose signature is provided
    • Prompt the user to enter an email and password and call the linearSearch method to determine whether the email and password match the information of any of the stored users.
    • Print the appropriate message to the console as described above.
  • Note: you are not allowed to implement any additional methods aside from those whose signatures are provided or to alter the method signatures in any way from what is provided, or you will not receive credit for this assignment.
  • Note 2: Please do not write to a file in this program.
  • When your program is working as shown below, please submit both User.java and Profile.java to Canvas.

names.txt input file:
Jiming Wu
F
4082123458
jwu@gmail.com
abc123
James Brown
M
8315678432
jaime.boy.brown@hotmail.com
jjjbbb123
Leanna Perez
F
4087654433
leaperez@yahoo.com
letmein
Xing Li
M
8313214555
xing.li@sbcglobal.net
555!!!hi
Stacey Cahill
O
8312123333
scahill@gmail.com
r0tr@tr^n
Mohammed Abbas
M
4083134444
downtown_abbas@yahoo.com
1@m@bb@s
Kumari Chakrabarti
F
4086667777
kukuchakrabarti@hotmail.com
passw0rd
Shakil Smith
M
4082123333
shakattaq@gmail.com
qwerty
Jung Ahrin
F
8319257788
jung_ahrin@yahoo.com
password1
Pedro Martinez
M
4086162323
pedro2018@sbcglobal.net
123456789
Ally Gu
O
4089256776
i_am_ally@comcast.net
trustno1
Tamara White
F
8317778978
tamtastic@gmail.com
1qaz2wsx
Alvin Ngo
M
4089256677
drngo@hotmail.com
qwertyuiop
Abir Fadel
M
8316645325
greatabs@comcast.com
qazwsx
Brad Feinman
M
8312023443
bradisrad@gmail.com
11111
Xiaohang Yue
M
8318990033
yue95@yahoo.com
adobe123


User.java Starter Code:

/**
 * Definition of the User class
 * @author
 * CIS 36B
 * Assignment 3
 */

public class User {

    private String name;
    private String gender;
    private String phone;
    private String email;
    private String password;


    /**
     * Default constructor - assigns
     * all member variables to the value
     * "<variable>  unknown"
     * e.g. "name unknown"
     */
    public User() {}
   
    /**
     * Constructor for the User class
     * @param theName the User name
     * @param theGender the User gender
     * @param thePhone the User phone
     * @param theEmail the User email
     * @param thePassword the User password
     */
    public User(String theName, String theGender, String thePhone, String theEmail, String thePassword)     {}
   
    /**
     * Returns the first and last name
     * @return the user name
     */
    public String getName() {
        return name;
    }
   
    /**
     * Returns the gender (F, M, or O)
     * @return the gender
     */
    public String getGender() {
        return "";
    }
   
    /**
     * Returns a phone number formatted
     * in the style (XXX) XXX-XXXX
     * @return the formatted phone number
     */
    public String getFormattedPhone() {
        return "";
    }
   
    /**
     * Returns the user email
     * @return the user email
     */
    public String getEmail() {
        return "";
    }
   
    /**
     * Verifies that password equals the
     * password on file for the user
     * @param userInput the password entered
     * @return whether the password entered matches
     * the password stored
     */
    public boolean verifyPassword(String userInput) {
        return userInput.equals(password);
    }
   
    /**
     * Assigns the user a first and last name
     * @param user_name the name of the user
     */
    public void setName(String user_name) {
        name = user_name;
    }
   
    /**
     * Assigns a value to the gender field
     * @param user_gender a gender F, M or O
     */
    public void setGender(String user_gender) {
        return;
    }
   
    /**
     * Assigns a phone number to the phone field
     * @param user_phone the phone number to assign
     */
    public void setPhone(String user_phone) {
        return;
    }
   
    /**
     * Assigns an email address to the email field
     * @param user_email the email address to assign
     */
    public void setEmail(String user_email) {
        return;
    }
   
    /**
     * Assigns a password to the password field
     * @param user_password the password to assign
     */
    public void setPassword(String user_password) {
        password = user_password;
    }
   
   

    /**
     * Returns the formatted User info as a String
     */
    @Override public String toString() {
        return "";
    }
}

Profile.java Starter Code:

/**
 * Profile.java
 * @author
 * CIS 36B
 * Assignment 6.1
 */

import java.util.ArrayList;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class Profile {
    public static void main(String[] args) throws IOException {
        ArrayList<User> users = new ArrayList<User>();
        File names = new File("names.txt");
        Scanner input = new Scanner(names);
        String name, phone, gender, email, password;
        while (input.hasNextLine()) {
            //read in the information for each user
            //create a new User object
            //call setter methods to assign values to user object
            //insert user object into users ArrayList
        }
        input.close();
        input = new Scanner(System.in);
        System.out.println("Welcome!\n");
        System.out.print("Enter your email address: ");
        email = input.nextLine();
        System.out.print("Enter your password: ");
        password = input.nextLine();
        //search
           
    }

  
    /**
     * 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 static int linearSearch(String email, String password, ArrayList<User> users) {
        return -1;
    }
}


Notes and Helpful Hints:

  • Below is an example of the output that the toString() method should provide:
Name: Leanna Perez
Gender: F
Phone: (408) 876-5443
Email: leaperez@yahoo.com

  • Don't forget that you can always consult the ArrayList API (documentation) on the Oracle website for additional methods not covered in class.


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


What to submit:

  • Submit User.java, Profile.java and (optionally) your pair programming contract to Canvas when you are finished.
  • Please make sure that your name(s) are on both files.