Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Please help me modify the following code according to the instructions. Thank you. Instructions: Account class Superclass Instance variables clearPassword String Must be at

Java: Please help me modify the following code according to the instructions. Thank you.

Instructions:

  1. Account class
    1. Superclass
    2. Instance variables
      1. clearPassword
        1. String
        2. Must be at least 8 characters long
      2. encryptedPassword : String
      3. key
        1. int
        2. Must be between 1 and 10(inclusive)
      4. accountId - A unique integer that identifies each account
      5. nextIDNum a static int that starts at 1000 and is used to generate the accountID
      6. no other instance variables needed.
    3. Default constructor set all instance variables to a default value.
    4. Parameterized constructor
      1. Takes in clearPassword, key.
      2. Calls encrypt method to create encryptedPassword
    5. setClearPassWord(String newPassword)
      1. Takes in a new clear text password.
      2. Calls encrypt method as the encrypted password would need to change.
    6. no encryptedPassword mutator method
    7. setKey(int newKey)
      1. Takes in a new key
      2. calls encrypt method as the encrypted password would need to change.
    8. accountId mutator - uses the static variable nextIDNum to retrieve the next available userID number
    9. encrypt method
      1. Uses the instance variables clearPassword and key to encrypt the password.
      2. Stores the encrypted password in the encryptedPassword instance variable
    10. toString - returns a nicely formatted String representing the instance variables of the Account class

NOTE: Your Account class should ensure the clearPassword is valid as described in the requirements. If not write an error message to the standard output and continue. Set the clearPassword and encyrptedPassword to the empty String.

Code:

public class Account {

private String clearPassword; private String encryptedPassword; private String key; private int accountId; private static int nextIDNum = 1000; /** * Constructor that initializes the variables. */ public Account() { clearPassword = ""; encryptedPassword = ""; key = ""; accountId = 0; }

/** * Constructor that sets the variables equal to the input information. It calls on the passwordCheck * method to make sure the password meets the requirements. It calls the encrypt method to encrypt * the password. It calls the addAccountId method to give the Account and ID number. */ public Account(String newClearPassword, String newKey){ clearPassword = newClearPassword; key = newKey; passwordCheck(); if(passwordCheck() == false) { clearPassword = ""; encryptedPassword = ""; }

addAccountId(); encrypt(); } /** * Method to set the password. It calls on the passwordCheck method to make sure the password * meets the requirements. It also calls the encrypt method to encrypt the password. */ public void setClearPassword(String newClearPassword) { clearPassword = newClearPassword; passwordCheck(); if(passwordCheck() == false) { clearPassword = ""; encryptedPassword = ""; } encrypt(); }

/** * Retrieves the clear password */ public String getClearPassword(){ return clearPassword; } /** * Retrieves the encrypted password */ public String getEncryptedPassword() { return encryptedPassword; } /** * Retrieves the password ke */ public String getKey(){ return key; }

/** * Sets the key to the input key. Calls the encrypt method to use key for encryption. */ public void setKey(String newKey) { key = newKey; encrypt(); }

/** * Returns the account ID */ public int getAccountId() { return accountId; }

/** * Method to make sure the password meets the requirements of one special character, one number and 8 characters * long or more. */ private boolean passwordCheck() { int asciiValueClearPswd[] = new int [100]; int asciiValueClearPswdTwo[] = new int [100]; for(int i = 0; i < clearPassword.length(); i++) { asciiValueClearPswd[i] = clearPassword.charAt(i); for(int j = 0; j < clearPassword.length(); j++){ asciiValueClearPswdTwo[j] = clearPassword.charAt(j); if((asciiValueClearPswd[i] >= 35 && asciiValueClearPswd[i] <= 38) && (asciiValueClearPswdTwo[j] >= 48 && asciiValueClearPswdTwo[j] <= 57) && (clearPassword.length() > 7)){ return true; } }

} return false; }

/** * The method that encrypts the clear password. Uses Vigenere Cipher for Ascii characters */ private void encrypt() {

int j = 0; int encryptNum[] = new int[100]; int asciiValueKey[] = new int[100]; int asciiValueClearPswd[] = new int [100]; byte encryptByte [] = new byte [clearPassword.length()]; for(int i = 0; i < clearPassword.length(); i++) { asciiValueKey[i] = key.charAt(j); asciiValueClearPswd[i] = clearPassword.charAt(i); encryptNum[i] = asciiValueKey[i] - 33; encryptNum[i] = (encryptNum[i] + asciiValueClearPswd[i]) - 90; encryptByte[i] = (byte) encryptNum[i];

if(encryptNum[i] < 33) { encryptNum[i] = (encryptNum[i] - 32) + 122; encryptByte[i] = (byte) encryptNum[i]; } if(key.length() - j == 1) { j = 0; } else { j++; } encryptedPassword = new String(encryptByte); } }

/** * Adds an account ID number to the Account. */ public int addAccountId() { accountId = nextIDNum; nextIDNum++; return accountId; }

/** * Returns the information for the account. */ public String toString(){ String info; info = String.format("%-5d %s %s %s ", getAccountId(), getEncryptedPassword(), getClearPassword(), getKey()); return info; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Give an example of hierarchical planning in an organization.

Answered: 1 week ago