Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA! Your next task is to create a method StoreCredentials that will store the

ID: 3684112 • Letter: J

Question

JAVA! Your next task is to create a method StoreCredentials that will store the credentials for one user of your system. The method will receive two arrays: UserNames[] and Passwords[] and the variable userNumber that holds the number of the user in the system. The array UserNames[] stores user names and the array Passwords their corresponding passwords. The method StoreCredentials should call the method CreateAccount and store the returning credentials in the position corresponding to the number of the user in the system. Note that you will have to split the returning value from CreateAccount to separate the user from the password. For example, for the return value “mary,503” you need to extract the username “mary” and the password “503”. 1. Write the pseudocode for the method StoreCredentials. 2. Write the java code for the method StoreCredentials. 3. Assume that StoreCredentials is called with the userNumber variable holding the value “3”, the third user in the system. Trace how your method would work to create the credentials for the third user in the system with the username “mary” and password “503”. Note: No need to trace the statements inside the method CreateAccount.

Explanation / Answer

package chegg;

public class Example {

   public void storeCredential(String[] userNames, String[] passwords,
           int userNumber) {
       String userPass = createAccount(userNames, passwords, userNumber);
       String[] data = userPass.split(",");

       System.out.println("Username : " + data[0]);
       System.out.println("Password : " + data[1]);
      
   }

   private String createAccount(String[] userNames, String[] passwords,
           int userNumber) {
       return userNames[userNumber-1] + "," + passwords[userNumber-1];
   }

   public static void main(String[] args) {
  
       String[] userNames = new String[]{"user1","user2","mary"};
       String[] passwords = new String[]{"501","502","503"};
      
      
       new Example().storeCredential(userNames, passwords, 3);
      
   }
}