Question
in java
Complete Program that simulates a login procedure. The program reads a list of names, email addresses and passwords from a fi
changes their password, inform them that it was successfully changed. • If not, end the program by confirming that they have
Sample output 2: Enter your email address (q to quit): cmartin@research.com Email not found, please try again (g to quit): ch
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Program:

import java.util.*;
import java.io.*;

class NamePwdEmail
{
   //Main method
   public static void main(String[] args) throws FileNotFoundException
   {
       int cnt=0;
       //Declaring parallel arrays
       String[] name = new String[50];
       String[] password = new String[50];
       String[] email = new String[50];
      
       //Scanner object
       Scanner fileReader = new Scanner(new File("d:\\Java\\p3.txt"));
      
       //Reading data from file
       while(fileReader.hasNext())
       {
           //Reading in to arrays
           name[cnt] = fileReader.next();
           email[cnt] = fileReader.next();
           password[cnt] = fileReader.next();
          
           //Incrementing count
           cnt++;
       }
      
       //Closing reader
       fileReader.close();
      
       //Opening scanner for user input
       Scanner kbd = new Scanner(System.in);
      
       String emailId, pwd, uName;
       int idx=0;
      
       //Loop
       while(true)
       {
           //Reading email from user
           System.out.println("Enter your email address (q to quit): ");
           emailId = kbd.nextLine();
          
           boolean loop = true;
           while(loop)
           {
               if(emailId.equalsIgnoreCase("q"))
               {
                   System.out.println("\nGoodbye!\n");
                   return;
               }
              
               //Checking for email
               for(int i=0; i<cnt; i++)
               {
                   if(email[i].equalsIgnoreCase(emailId))
                   {
                       idx = i;
                       loop = false;
                       break;
                   }
               }
              
               //Checking loop
               if(loop)
               {
                   System.out.println("Email not found, please try again (q to quit): ");
                   emailId = kbd.nextLine();
               }
               else
               {
                   break;
               }
           }
          
           //Reading password
           System.out.println("Enter your password: ");
           pwd = kbd.nextLine();
          
           int tries=1;
           while(tries < 3)
           {
               //Comparing password
               if(password[idx].equalsIgnoreCase(pwd))
               {
                   break;
               }
               else
               {
                   System.out.println("Password incorrect, please try again: ");
                   pwd = kbd.nextLine();
                   tries += 1;
               }
           }
          
           String choice;
           //Checking tries
           if(tries < 3)
           {
               //Reading user choice
               System.out.println("Welcome " + name[idx] + "! Do you want to change your password (y/n)? ");
               choice = kbd.nextLine();
              
               //Checking choice
               if(choice.equalsIgnoreCase("y"))
               {
                   //New Password
                   System.out.println("Enter new Password: ");
                   pwd = kbd.nextLine();
                   password[idx] = pwd;
                   System.out.println("Your password has been updated.");
               }
               else
               {
                   System.out.println("\nGoodbye!\n");
               }
           }
           else
           {
               System.out.println("\nPassword incorrect. 3 strikes, locked out! \n");
               return;
           }
       }
   }
}

Sample Run:

Add a comment
Answer #2

Java Program:

import java.util.*;
import java.io.*;

class NamePwdEmail
{
   //Main method
   public static void main(String[] args) throws FileNotFoundException
   {
       int cnt=0;
       //Declaring parallel arrays
       String[] name = new String[50];
       String[] password = new String[50];
       String[] email = new String[50];
      
       //Scanner object
       Scanner fileReader = new Scanner(new File("d:\\Java\\p3.txt"));
      
       //Reading data from file
       while(fileReader.hasNext())
       {
           //Reading in to arrays
           name[cnt] = fileReader.next();
           email[cnt] = fileReader.next();
           password[cnt] = fileReader.next();
          
           //Incrementing count
           cnt++;
       }
      
       //Closing reader
       fileReader.close();
      
       //Opening scanner for user input
       Scanner kbd = new Scanner(System.in);
      
       String emailId, pwd, uName;
       int idx=0;
      
       //Loop
       while(true)
       {
           //Reading email from user
           System.out.println("Enter your email address (q to quit): ");
           emailId = kbd.nextLine();
          
           boolean loop = true;
           while(loop)
           {
               if(emailId.equalsIgnoreCase("q"))
               {
                   System.out.println("\nGoodbye!\n");
                   return;
               }
              
               //Checking for email
               for(int i=0; i<cnt; i++)
               {
                   if(email[i].equalsIgnoreCase(emailId))
                   {
                       idx = i;
                       loop = false;
                       break;
                   }
               }
              
               //Checking loop
               if(loop)
               {
                   System.out.println("Email not found, please try again (q to quit): ");
                   emailId = kbd.nextLine();
               }
               else
               {
                   break;
               }
           }
          
           //Reading password
           System.out.println("Enter your password: ");
           pwd = kbd.nextLine();
          
           int tries=1;
           while(tries < 3)
           {
               //Comparing password
               if(password[idx].equalsIgnoreCase(pwd))
               {
                   break;
               }
               else
               {
                   System.out.println("Password incorrect, please try again: ");
                   pwd = kbd.nextLine();
                   tries += 1;
               }
           }
          
           String choice;
           //Checking tries
           if(tries < 3)
           {
               //Reading user choice
               System.out.println("Welcome " + name[idx] + "! Do you want to change your password (y/n)? ");
               choice = kbd.nextLine();
              
               //Checking choice
               if(choice.equalsIgnoreCase("y"))
               {
                   //New Password
                   System.out.println("Enter new Password: ");
                   pwd = kbd.nextLine();
                   password[idx] = pwd;
                   System.out.println("Your password has been updated.");
               }
               else
               {
                   System.out.println("\nGoodbye!\n");
               }
           }
           else
           {
               System.out.println("\nPassword incorrect. 3 strikes, locked out! \n");
               return;
           }
       }
   }
}

Sample Run:


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
in java Complete Program that simulates a login procedure. The program reads a list of names,...
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
  • 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...

  • Assignment 14.3: Valid Email (10 pts) image source Write a program that takes as input an...

    Assignment 14.3: Valid Email (10 pts) image source Write a program that takes as input an email address, and reports to the user whether or not the email address is valid. For the purposes of this assignment, we will consider a valid email address to be one that contains an @ symbol The program must allow the user to input as many email addresses as desired until the user enters "q" to quit. For each email entered, the program should...

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • Create a java program that reads an input file named Friends.txt containing a list 4 names...

    Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do:   1. Add a new name   2. Change a name 3. Delete a name 4. Print the list   or 5. Quit    When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...

  • Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user...

    Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user login system. Your code should do the following: 3, create-user_name() #use this function to create the user name 1.Create your user database called "UD.txt", this should be in CSV format 4, write-file() #user this function to save the user name and password into "UD.txt" Deliverables: Sample: the data you saved...

  • ATM MACHINE

    Kindly help me In this assignment you will create a RMI based system that allows a user to do the following: 1) Create a bank account by supplying a user id and password. 2) Login using their id and password. 3) Quit the program. Main Manu of ATM service window *Separate remote methods will be created for all of these functionalities. ->To create account see output below Hi! Welcome to  ATM Machine! Please select an option from the menu below: l -> Loginc -> Create New Account q -> Quit > c...

  • Hashmap concept

    HashMap:  We can use a HashMap to store key value pairs.  Reminder that only reference types can be used as the key or value.  It you want to use a number as the key then an Integer data type could be used but not an int primitive data type.Create a class called Login which contains a HashMap as a private attribute.  It should also have an instance method called loadCredentials which accepts the two arrays.  It will load the HashMap...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • Write a Java program that: 1. Decide on a list of n favorites (songs, bands, movies,...

    Write a Java program that: 1. Decide on a list of n favorites (songs, bands, movies, video games, etc.) (between 5 and 10 favorites is fine). 2. Write a program that lists the n favorites but with a small twist. 3. Read in a file of n favorites (sample file in the Resources/Sample File area)...Please make your own. 4. Print a list of all n favorites to the user (so they know what is coming) 5. Ask if the user...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

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