Question

User Profiles Write a program that reads in a series of customer information -- including name,...

User Profiles

  • 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
[email protected]
abc123
James Brown
M
8315678432
[email protected]
jjjbbb123
Leanna Perez
F
4087654433
[email protected]
letmein
Xing Li
M
8313214555
[email protected]
555!!!hi
Stacey Cahill
O
8312123333
[email protected]
r0tr@tr^n
Mohammed Abbas
M
4083134444
[email protected]
1@m@bb@s
Kumari Chakrabarti
F
4086667777
[email protected]
passw0rd
Shakil Smith
M
4082123333
[email protected]
qwerty
Jung Ahrin
F
8319257788
[email protected]
password1
Pedro Martinez
M
4086162323
[email protected]
123456789
Ally Gu
O
4089256776
[email protected]
trustno1
Tamara White
F
8317778978
[email protected]
1qaz2wsx
Alvin Ngo
M
4089256677
[email protected]
qwertyuiop
Abir Fadel
M
8316645325
[email protected]
qazwsx
Brad Feinman
M
8312023443
[email protected]
11111
Xiaohang Yue
M
8318990033
[email protected]
adobe123

User.java Starter Code:

/**
* Definition of the User class
* @author

* @author

* CIS 36B, Lab 6
*/

public class User {

    public String name;
    public String gender;
    public String phone;
    public String email;
    public String password;


   
   /**
    * prints a User's information to the console

     * in the below format:

     * Name: <name>

   * Gender: <gender>

     * Phone: (XXX) XXX-XXXX

   * Email: <email>

     */
    public void printUser() {

        System.out.println("You fill in here!");

    }

}

Profile.java Starter Code:

/**
* Profile.java
* @author

* @author

* CIS 36B, Lab 6
*/

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

            //assign values to user object's variables

            //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:

  • Note that if you call the get method on the users ArrayList, it will return a User object from the list:

        User u = users.get(0); //retrieves first User object from the ArrayList

   users.get(0).printUser(); //prints the information about User at index 0

   System.out.println(users.get(0).email); //prints the email address of the User at index 0

  • Below is an example of the output that the printUser() method should provide:

Name: Leanna Perez
Gender: F
Phone: (408) 765-4433

Email: [email protected]

  • 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: [email protected]
Enter your password: letmein

Hi, Leanna Perez!
We have the following information on file for you:
Name: Leanna Perez
Gender: F
Phone: (408) 765-4433

Email: [email protected]

Alternately:

Welcome!

Enter your email address: [email protected]
Enter your password: 555111jjjlll

Sorry! We don't have your account on file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

User.java

/**
* Definition of the User class
* @author
* @author
*        CIS 36B, Lab 6
*/

public class User {

   public String name;
   public String gender;
   public String phone;
   public String email;
   public String password;

   /**
   * prints a User's information to the console
   * in the below format:
   * Name: <name>
   * Gender: <gender>
   * Phone: (XXX) XXX-XXXX
   * Email: <email>
   */
   public void printUser() {
       System.out.println("Hi, "+name+"!");
       System.out.println("We have the following information on file for you:");
       // USe substring to format number into (XXX) XXX-XXXX
       System.out.println("Name: "+name
                       +"\nGender: "+gender
                       +"\nPhone: "+"("+phone.substring(0, 3)+") "+phone.substring(3,6)+"-"+phone.substring(6,10)
                       +"\nEmail: "+email);
              
   }

}

Profile.java

/**
* Profile.java
* @author
* @author
* CIS 36B, Lab 6
*/

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
           name = input.nextLine();
           gender = input.nextLine();
           phone = input.nextLine();
           email = input.nextLine();
           password = input.nextLine();

           // create a new User object
           User user = new User();

           // assign values to user object's variables
           user.name = name;
           user.gender = gender;
           user.phone = phone;
           user.email = email;
           user.password = password;

           // insert user object into users ArrayList
           users.add(user);
       }
       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
       System.out.println();
       int index = linearSearch(email, password, users);
       // If returned value is not -1, print user information
       // Else, print message accordingly
       if (index != -1) {
           users.get(index).printUser();
       } else {
           System.out.println("Sorry! We don't have your account on file.");
       }
   }

   /**
   * 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) {
       // Iterate over arraylist, if email and password matches
       // return index i
       // else return -1 after the loop
       for (int i = 0; i < users.size(); i++) {
           User u = users.get(i);
           if (u.email.equals(email) && u.password.equals(password)) {
               return i;
           }
       }
       return -1;

   }

}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
User Profiles Write a program that reads in a series of customer information -- including name,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 1.4: Arrays, File I/O and Method Review (40 pts) Assume you work for a company...

    Lab 1.4: Arrays, File I/O and Method Review (40 pts) Assume you work for a company that received a list of email addresses of potential new customers from a data broker. Your company receives a file named customers.txt with the below information: Jiming Wu [email protected] James Brown [email protected] Leanna Perez [email protected] Xing Li [email protected] Stacey Cahill [email protected] Mohammed Abbas [email protected] Kumari Chakrabarti [email protected] Shakil Smith Shakattaq2G.com Jung Ahrin [email protected] Pedro Martinez [email protected] Ally Gu [email protected] Tamara White [email protected] Alvin Ngo...

  • Please run the program and show the result with screenshots after. Thank you (Java Eclipse) Customer...

    Please run the program and show the result with screenshots after. Thank you (Java Eclipse) Customer Data: Area Codes Assume you work for a company that tracks customer information, including name, gender and phone numbers Your company has a file called customers.txt which contains the following information: Jiming Wu F 4082123458 James Brown M 8315678432 Leanna Perez F 4087654433 Xing Li M 8313214555 Stacey Cahill O 8312123333 Mohammed Abbas M 4083134444 Kumari Chakrabarti F 4086667777 Shakil Smith M 4082123333 Jung...

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • in java Complete Program that simulates a login procedure. The program reads a list of names,...

    in java Complete Program that simulates a login procedure. The program reads a list of names, email addresses and passwords from a file p3.txt. Store the information in parallel array lists names, emails and passwords. Your program will prompt the user for their email address. If the email is not in the system, prompt the user to try again. Provide the option to quit. If the email is found in the system, prompt the user to enter their password. After...

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • Use BlueJ to write a program that reads a sequence of data for several car objects...

    Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program...

  • Write a program in Java that prompts a user for Name and id number. and then...

    Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main {    public static void main(String[] args) {                       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);        String name = thedata;        Student pupil = new Student(name);                   //add code here       ...

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT