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

Specifications 1.To be valid, a password must contain at least one uppercase let

ID: 2246747 • Letter: S

Question

Specifications

1.To be valid, a password must contain at least one uppercase letter, one lowercase letter, and one digit. In addition, its length must be at least five characters. All characters except space, tab, and return are allowed.

2.Input. The program reads passwords from the user. During development, use your own test data, then test your final version against your test data, my test data, and classmates’ test data.

3.Output. The program initially outputs results to the screen, in the following format: password, validity, and errors if not valid. Sample output:

password: Happy888, valid

password: cat, invalid

   -- no uppercase letter

   -- no digit

   -- too short (minimum of 5 characters)

Once your program is complete and correct, change output to go to a report file, in the same format, plus a report heading with your name, and the assignment name.

4.The program will have one class, named Password, and the following methods: main, default constructor if needed, greetUser (brief explanation of the program, written to the screen), readPasswordFromUser, checkCase, checkLength, checkValidty, printPasswordValidity (one password as above, with password, validity result, and error messages), addToReport (concatenates result of checking the current password to the report variable), and printReport (to file). You may use additional methods as needed.

5.Variables. With few exceptions, all variables should be at the instance level; do not use static. Main will contain an object variable of Password type to call the other methods.

6.Logic. You may use methods from the String and Character classes as needed. Do not use any built-in methods that do a substantial part of this project.

Explanation / Answer

import java.util.*;

public class Password

{

String pwd;

Scanner sc;

String report;

Password()

{

pwd="";

report="";

}

public void readPasswordFromUser()

{

System.out.println("Enter the password ");

sc=new Scanner(System.in);

pwd=sc.next();

System.out.println(pwd);

}

public boolean checkLength()

{

if(this.pwd.length() < 5)

return false;

return true;

}

public boolean checkCase()

{

int i;

for(i=0;i<this.pwd.length();i++)

{

int temp=(int)this.pwd.charAt(i);

if(temp>=65 && temp<=90)

return true;

}

return false;

}

public boolean checkDigit()

{

int i;

for(i=0;i<this.pwd.length();i++)

{

int temp=(int)this.pwd.charAt(i);

if(temp>=48 && temp<=57)

return true;

}

return false;

}

public boolean checkValidty()

{

if(checkCase()==false || checkLength()==false || checkDigit()==false)

return false;

return true;

}

public void printPasswordValidity()

{

String str = "password: "+pwd+" ";

if(checkValidty()==true)

str+="valid ";

else

str+="invalid ";

if(checkDigit()!=true)

str+=" -- no digit ";

if(checkLength()!=true)

str+=" -- too short (minimum of 5 characters) ";

if(checkCase()!=true)

str+=" -- no uppercase letter ";

System.out.println(str);

}

public void addToReport()

{

String str = "password: "+pwd+" ";

if(checkValidty()==true)

str+="valid ";

else

str+="invalid ";

if(checkDigit()!=true)

str+=" -- no digit ";

if(checkLength()!=true)

str+=" -- too short (minimum of 5 characters) ";

if(checkCase()!=true)

str+=" -- no uppercase letter ";

report= report + str;

}

public static void main(String[] args)

{

Password ob = new Password();

ob.readPasswordFromUser();

ob.printPasswordValidity();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote