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

I cant get this to run without error here is the question and the code. I have t

ID: 3623352 • Letter: I

Question

I cant get this to run without error here is the question and the code. I have to write a program that works with a user's password.
The program will prompt the user for a possible password. The program should check to be sure this
is a 'good' password. Specifically, a good password is one that will have to be



must be between 6 and 10 characters long

must contain at least one letter

must contain at least one digit



Continue to prompt the user for a password until these criteria are met. Once the user enters a 'good' password, prompt them to enter it again until the two passwords match.

Please note the way you'll write this program, the user will be able to see the characters that they type. While you wouldn't want to do this in practice, it's ok for this project here.

Be sure your program demonstrates good programming style. please include appropriate comments, identifier names, and indenting. Be sure to submit all source and project workspace files used in your solution....

import javax.swing.JOptionPane;

public class PassWord {

private String password;
private int count;

public PassWord(String aPassword) {
this.password = aPassword;
}


public void checkPassword() {
int countUpperCase = 0;


for (char c : password.toCharArray()) {
if (Character.isLetter(c) && Character.isUpperCase(c)) {
countUpperCase++;
}
}

while ((password.length() < 6) || (password.length() > 10) || (countUpperCase > 1)
|| (checkDigit(password) > 1) || (checkDigit(password) < 1)) {

JOptionPane.showMessageDialog(null, " Not a good password ");
password = JOptionPane.showInputDialog("Enter Password: ");
}

JOptionPane.showMessageDialog(null, "Password is 'GOOD' ReEnter again");

matchPasswords(password);
}

private int checkDigit(String passString) {

int[] array = new int[10];

for (int i = 0; i < passString.length(); i++) {
for (char j = '0'; j <= '9'; j++) {
if (passString.charAt(i) == j) {
count++;
array[Character.digit(j, 10)] = count;
}
}
}
return count;
}


public void matchPasswords(String checkPassword) {
String newPassword = "";

while (!checkPassword.contentEquals(newPassword)) {

JOptionPane.showMessageDialog(null, " Not a good password ");
newPassword = JOptionPane.showInputDialog("Enter Password: ");
}

JOptionPane.showMessageDialog(null, "Passwords Match Password: " + newPassword);
}
}































Explanation / Answer

please rate - thanks

hope you don't mind I started from scratch

import javax.swing.*;
public class Password
{ public static void main(String[] args)
   { String input,input2;
    boolean good;
     input = JOptionPane.showInputDialog("Enter a password.");
    good=PasswordChecker.isGood(input);
     while(!good)
        { JOptionPane.showMessageDialog(null,"Invalid password.");
         input = JOptionPane.showInputDialog("Enter a password.");
          good=PasswordChecker.isGood(input);
         }
        JOptionPane.showMessageDialog(null,"good password.");
        input2=JOptionPane.showInputDialog("re enter your password.");
        while(!(input2.compareTo(input)==0))
        { JOptionPane.showMessageDialog(null,"passwords don't match");
         input2 = JOptionPane.showInputDialog("renter");
          }

   }
}

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

public class PasswordChecker
{   public static boolean isGood(String s)
   {if (s.length()>=6&&s.length()<=10 && upper(s)&&lower(s)&&number(s))
         return true;
      else
         return false;
   }
private static boolean upper(String s)
   {int i;
    for(i=0;i<s.length();i++)
      if (Character.isUpperCase(s.charAt(i)))
            return true;
      return false;
   }

private static boolean lower(String s)
   {int i;
    for(i=0;i<s.length();i++)
      if (Character.isLowerCase(s.charAt(i)))
            return true;
      return false;
   }
private static boolean number(String s)
   {int i;
    for(i=0;i<s.length();i++)
      if (Character.isDigit(s.charAt(i)))
            return true;
      return false;
}
}

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