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

Write a user defined class that would represent a password. The class should hav

ID: 3624184 • Letter: W

Question

Write a user defined class that would represent a password. The class
should have a default constructor (set a random password), nondefault
constructor (user send pwd via argument), mutator/accesor method(s), and a
toString() method. Be sure to use appropriate access modifiers (private,
public).
. All passwords must be at least 6 chars long. What code would you
add to the previous class so that the value of minimum length of could be
accessed without having to create an instance of the class?
. Write a method that would appear in the above class that would
return true if the password was valid. A valid password would be at least
the specified min length and contain no spaces.
. Write a java code segment that would appear in an application class
that would declare and instantiate a default instance of the above class.
. Write a java code segment that would appear in an application class
that would prompt the user to enter a password then display to the console
if the password entered was equal to the instance of the previous password.

In this one I am having problems ensuring that the password passed in by the user has no spaces. Pls I need help. Thanks. Find my code below
import java.util.Scanner;
import java.text.*;
import java.lang.Math;

public class Password
{
private static final String DEFAULT_PWD = "password";
private String pass;
public static final int MIN_PWD_LENGTH = 6;

public Password()//default
{
setPassword(DEFAULT_PWD);
}

public Password(String newPass)//non-default
{
setPassword(newPass);
}

public String getPassword()
{
return pass;
}

public void setPassword(String newPass)
{
for (int i = 0; i< newPass.length(); i++)
{
if((newPass.length()>= MIN_PWD_LENGTH)&& (i!= " "))
pass = newPass ;
else
DEFAULT_PWD = pass;
}
}

public boolean validPass(Password that)
{
if(this.pass == that.pass)
return true;
else
return false;
}

public String toString()
{
return "The password: " + pass +" passed in" + isValid();
}

public void isValid(Password that)
{
if (((this.pass.length() == that.pass.length())) && (this.pass == that.pass))
System.out.println(" Matches the set Password and is thus valid");
else
System.out.println(" Does not match the set Password and not valid");
}
}
My PasswordApp class is also below
import java.util.Scanner;
public class PasswordApp
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
Password attempt1 = new Password();
System.out.println("Enter your password here: ");
input.next();
attempt1.toString();
isValid();
}

}

Explanation / Answer

{ boolean spaceless=true; for (int i = 0; i= MIN_PWD_LENGTH)&&spaceless) pass = newPass ; else pass=DEFAULT_PWD ; }
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