Question

JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE...

JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT!

PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE

Below is the program -- fill the code as per the instructions commented:

//---------------------------------------------------------------------------------------------------------------------------------------------------------------//

/*

The idea of this HW is as follows :
A password must meet special requirements, for instance , it has to be of
specific length, contains at least 2 capital letters , 2 lowercase letters,
2 symbols and 2 digits. A customer is hiring you to create a class that
can be utilized for several clients of the customer.

The first object created will be for the first level clients which requires
a moderate level password which contains ( at least 1 capital letters ,
1 lowercase letters,1 symbol and 1 digit).
The first level should be created using a default constructor.
The length of any password should be at least 8 characters for all levels.
Hint, should be static.

The second object created will be for the second level clients which requires
a harder level password which contains ( at least 2 capital letters ,
2 lowercase letters,2 symbol and 2 digits).
The second level should be created using an overloaded constructor.
the length of the second level password should be at least 8 as it
required for any levels.


*/


import java.util.Scanner;

public class Password{

/*(1 point) Create a private static default password variable and set
it to Def@u1tPa$$w0rd which meets the standards of accepted password*/

//(1 point) Create a private static int length of the password and set to 8.

// Private settings that should be met for each password instance/objects
//(1 point) Create a private variable to store the number of symbols

//(1 point) Create a private variable to store the number of capital letters

//(1 point) Create a private variable to store the number of lower case letters

//(1 point) Create a private variable to store the number of digits

// (1 point)Create a private variable to store the password

/** (6 points) Create the default constructor, set the default required number
* for capital and lowercase letters, symbols, digits to 1
* set the password variable to the default password
*/
Password()
{ // default values

}

/**( 6 points) Create an overloaded constructor ,that takes
* number of ( symbols , capital letters, small letters, digits)
* these will be considered settings for initializing an instance of
* the password set the global private variables (also known as data fields)
* to the passed in arguments
*/
Password ( int numSymbols, int numCap, int numSmall, int numDigits )
{

}

  
  
/**(3 points) Create a method that takes a string password and check if
* it is equal to the length specified then return true, false if not */
public boolean validLength(String pass)
{


}
  
/**(10 points) Create a method that takes a string password ,
* the method checks if the password has at least the
* required number of symbols and return true, false if not
  
  
// Declare a counter variable
  
// Declare a boolean to hold the answer
  
// Loop through the length of the password
  
// Once you counted the required number, set answer to true and break
  

// Using the Ascii table, check each index if in the range [32 -47] or [58-64]

  
// increment the count
  
  
// return the answer

*/

  
/**( 2 points) Create a method that takes a string password ,
* the method checks if the password has at least the
* required number of digits and return true, false if not
* the style of this method will be similar to the previous method
* use the range in the Ascii table [48 -57] for digits
*/

  
  
  
/**( 2 points)Create a method that takes a string password ,
* the method checks if the password has at least the
* required number of capital letters and return true, false if not
* the style of this method will be similar to the previous method
* use the range in the Ascii table [65 -90] for capital letters
*/

  
/** ( 2 points) Create a method that takes a string password ,
* the method checks if the password has at least the
* required number of lowercase letters and return true, false if not
* the style of this method will be similar to the previous method
* use the range in the Ascii table [97 -122] for lowercase letters
*/
  
  
/**(2 points) create a getter method to return the password*/

/** ( 15 points) Create a setter method to set the password*/
public void setPassword( )
{
// Declare a String to hold a password
  
// Declare a scanner object to receive a password from the keyboard
  
// Declare a boolean variable to be set whenever a password meets the settings.
  
// Loop until the user provides a correct password
  
// prompt the user to enter the password , specify the requirements
  

// scan the next line and store in the String holding the password
  
  
/* If the password provided is not equal to the length required,
then print out an error message*/
  
  
/* Else if the password doesn't have the required number of capital letters
then print out a message*/
  
  
/* Else if the password doesn't have the required number of lowercase letters
then print out a message*/
  
  
/* Else if the password doesn't have the required number of symbols
then print out a message*/
  
  
/* If the password doesn't have the required number of digits
then print out a message*/
  
/* Else , password provided is correct
set the global variable password to the new qualified password
set the flag to false, to stop iterations
*/
}
  
  
  
/**
* (10 points)create the main method
*/
public static void main(String[] args) {

//Declare an instance of Password using the default constructor

// print out the password, using the getter method

// What is the default password ?..................
  
// Use the setter method to set a password

// Print out the password using the getter method

  
/*Declare an instance of the password using the overloaded constructor,
the settings for new password object are:
(2 Captial letters,2 Lowercase letters, 2 Symbols , 2 Numbers)*/

// Set the password using the setter method.
  
// Print out the password using the getter method


  
  

}

}

//---------------------------------------------------------------------------------------------------------------------------------------------------------------//

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

NOTE :

I have not removed the comments given in the given code , as it will be helpful to understand the code

There is nothing much for explanation , as all the explanation is already given in comments

please find the screenshot below to find the execution of the code:

(The black color is the system generated strings and green color text is user inputs)

Please find the code below:

--------------------------------------------------------------------------------------

package org.bnymellon.password;

import java.util.Scanner;

public class Password {

   /*
   * (1 point) Create a private static default password variable and set it to
   * Def@u1tPa$$w0rd which meets the standards of accepted password
   */
   private static String defaultPassword = "Def@u1tPa$$w0rd";

//(1 point) Create a private static int length of the password and set to 8.
   private static int length = 8;

// Private settings that should be met for each password instance/objects
//(1 point) Create a private variable to store the number of symbols
   private int numOfSymbols;
//(1 point) Create a private variable to store the number of capital letters
   private int numOfCapitalCaseChars;
//(1 point) Create a private variable to store the number of lower case letters
   private int numOfLowerCaseChars;
//(1 point) Create a private variable to store the number of digits
   private int numOfDigits;
// (1 point)Create a private variable to store the password
   private String password;

   /**
   * (6 points) Create the default constructor, set the default required number
   * for capital and lowercase letters, symbols, digits to 1 set the password
   * variable to the default password
   */
   Password() { // default values
       this.numOfSymbols = 1;
       this.numOfDigits = 1;
       this.numOfCapitalCaseChars = 1;
       this.numOfLowerCaseChars = 1;
       this.password = defaultPassword;
   }

   /**
   * ( 6 points) Create an overloaded constructor ,that takes number of ( symbols
   * , capital letters, small letters, digits) these will be considered settings
   * for initializing an instance of the password set the global private variables
   * (also known as data fields) to the passed in arguments
   */
   Password(int numSymbols, int numCap, int numSmall, int numDigits) {
       this.numOfSymbols = numSymbols;
       this.numOfDigits = numDigits;
       this.numOfCapitalCaseChars = numCap;
       this.numOfLowerCaseChars = numSmall;
   }

   /**
   * (3 points) Create a method that takes a string password and check if it is
   * equal to the length specified then return true, false if not
   */
   public boolean validLength(String pass) {
       if (pass.length() == length) {
           return true;
       } else {
           return false;
       }

   }

   /**
   * (10 points) Create a method that takes a string password , the method checks
   * if the password has at least the required number of symbols and return true,
   * false if not
   *
   *
   * // Declare a counter variable
   *
   * // Declare a boolean to hold the answer
   *
   * // Loop through the length of the password
   *
   * // Once you counted the required number, set answer to true and break
   *
   *
   * // Using the Ascii table, check each index if in the range [32 -47] or
   * [58-64]
   *
   *
   * // increment the count
   *
   *
   * // return the answer
   *
   */

public boolean checkSymbols(String pass) {
int count = 0;
boolean ans;
for (int i = 0; i < pass.length(); i++) {
int acsiiVal = (int) pass.charAt(i);
if ((acsiiVal >= 32 && acsiiVal <= 47) || (acsiiVal >= 58 && acsiiVal <= 64)) {
count++;
}
}
if (count >= this.numOfSymbols) {
ans = true;
} else {
ans = false;
}
return ans;
}

   /**
   * ( 2 points) Create a method that takes a string password , the method checks
   * if the password has at least the required number of digits and return true,
   * false if not the style of this method will be similar to the previous method
   * use the range in the Ascii table [48 -57] for digits
   */
   public boolean checkDigits(String pass) {
       int count = 0;
       for (int i = 0; i < pass.length(); i++) {
           int acsiiVal = (int) pass.charAt(i);
           if ((acsiiVal >= 48 && acsiiVal <= 57)) {
               count++;
           }
       }
       if (count >= this.numOfDigits) {
           return true;
       } else {
           return false;
       }
   }

   /**
   * ( 2 points)Create a method that takes a string password , the method checks
   * if the password has at least the required number of capital letters and
   * return true, false if not the style of this method will be similar to the
   * previous method use the range in the Ascii table [65 -90] for capital letters
   */

   public boolean checkCapitals(String pass) {
       int count = 0;
       for (int i = 0; i < pass.length(); i++) {
           int acsiiVal = (int) pass.charAt(i);
           if ((acsiiVal >= 65 && acsiiVal <= 90)) {
               count++;
           }
       }
       if (count >= this.numOfCapitalCaseChars) {
           return true;
       } else {
           return false;
       }
   }

   /**
   * ( 2 points) Create a method that takes a string password , the method checks
   * if the password has at least the required number of lowercase letters and
   * return true, false if not the style of this method will be similar to the
   * previous method use the range in the Ascii table [97 -122] for lowercase
   * letters
   */

   public boolean checkLowers(String pass) {
       int count = 0;
       for (int i = 0; i < pass.length(); i++) {
           int acsiiVal = (int) pass.charAt(i);
           if ((acsiiVal >= 97 && acsiiVal <= 122)) {
               count++;
           }
       }
       if (count >= this.numOfLowerCaseChars) {
           return true;
       } else {
           return false;
       }
   }

   public String getPassword() {
       return this.password;
   }

   /** (2 points) create a getter method to return the password */

   /** ( 15 points) Create a setter method to set the password */
   public void setPassword() {
       String pass = "";
// Declare a String to hold a password

       Scanner sc = new Scanner(System.in);
// Declare a scanner object to receive a password from the keyboard
       boolean isPassCorrect = true;
// Declare a boolean variable to be set whenever a password meets the settings.

// Loop until the user provides a correct password
       while (isPassCorrect) {
           // prompt the user to enter the password , specify the requirements
           System.out.println("Enter a password : ");
           // scan the next line and store in the String holding the password
           pass = sc.nextLine();

           /*
           * If the password provided is not equal to the length required, then print out
           * an error message
           */
           if (pass.length() != length) {
               System.out.println("Invalid length , please retry");
           }
           /*
           * Else if the password doesn't have the required number of capital letters then
           * print out a message
           */
           else if (!this.checkCapitals(pass)) {
               System.out.println("Not enough capital letters , please retry");
           }

           /*
           * Else if the password doesn't have the required number of lowercase letters
           * then print out a message
           */
           else if (!this.checkLowers(pass)) {
               System.out.println("Not enough lower case characters , please retry");
           }

           /*
           * Else if the password doesn't have the required number of symbols then print
           * out a message
           */
           else if (!this.checkSymbols(pass)) {
               System.out.println("Not enough symbols , please retry");
           }
           /*
           * If the password doesn't have the required number of digits then print out a
           * message
           */
           else if (!this.checkDigits(pass)) {
               System.out.println("Not enough digits , please retry");
           }
           /*
           * Else , password provided is correct set the global variable password to the
           * new qualified password set the flag to false, to stop iterations
           */
           else {
               System.out.println("Password set successfully");
               this.password = pass;
               isPassCorrect = false;
           }

       }

   }

   /**
   * (10 points)create the main method
   */
   public static void main(String[] args) {
       Password myPassword = new Password();
//Declare an instance of Password using the default constructor
       System.out.println(myPassword.getPassword());
// print out the password, using the getter method
       System.out.println(Password.defaultPassword);
// What is the default password ?..................
       myPassword.setPassword();
// Use the setter method to set a password
       System.out.println(myPassword.getPassword());
// Print out the password using the getter method

       Password myCustomizedPassword = new Password(2, 2, 2, 2);

       /*
       * Declare an instance of the password using the overloaded constructor, the
       * settings for new password object are: (2 Captial letters,2 Lowercase letters,
       * 2 Symbols , 2 Numbers)
       */
       myCustomizedPassword.setPassword();
// Set the password using the setter method.
       System.out.println(myCustomizedPassword.getPassword());
// Print out the password using the getter method

   }

}

------------------------------------------------------

To execute the code from command line :

1)Create a file called 'Password.java'

2)Navigate to that directory using command line

3)run "javac Password.java" and "java Password"

To execute using IDEs

1)Just create a class named "Password"

2)Paste the code and run

Def@ultPa$$word Def@ultPa$$word Enter a password: Pranavkulkarni Invalid length, please retry Enter a password: Pranavlk Not enough symbols, please retry Enter a password: Pranavl& Not enough digits, please retry Enter a password: Pranav5& Password set successfully Pranav5& Enter a password: Pranavkulkarni Invalid length, please retry Enter a password: Pranavlk Not enough capital letters, please retry Enter a password: Pranavlk Not enough symbols, please retry Enter a password: PRANAV&* Not enough lower case characters, please retry Enter a password: Pranav&* Not enough digits, please retry Enter a password: PRan12&* Password set successfully PRan12&*

Add a comment
Know the answer?
Add Answer to:
JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE...
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
  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; //...

    Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; // Scanner class to support user input public class TestPetHierarchy { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Variables required for processing */ Scanner input = new Scanner( System.in...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • Help please this is C/C++ code /* * Lab12, the purpose of this lab is to...

    Help please this is C/C++ code /* * Lab12, the purpose of this lab is to improve your skills in handling c strings * with pointers . * use of : strlen ,string concatenation strcat, compare strcmp, * copy strcpy and search strrchr * */ #include <cstdlib> #include <iostream> #include<cstring> using namespace std; /** * Create a method that prompts the user for only lowercase letters to represent * a name. * Start a Label, then prompt the user to...

  • Java Program Please help me with this. It should be pretty basic and easy but I...

    Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...

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