The program is supposed to accept a new password, but it needs to be at least 6 chars long and contain at least one number and one letter. The requirements do not say anything about special chars, so I assume they are not allowed. Unfortunately, the syntax seems sound, but the methods return an error: "illegal start of expression". public and static are pointed out. Otherwise, the rest of the code seems fine, so far. Any ideas? I'm new to Java, so I'm practicing with char and string manipulation and searching.
I am using jGrasp to compile. Here is my code so far. I am not too concerned about someone "stealing" my code as it's a project from a book, so I'm sending the whole thing. The error returned is "PasswordDahl.j ava:78: cannot find symbol
symbol : class string
location: class PasswordDahl
public static void TestLength(stri ng password)
^
1 error"
I am using jGrasp to compile. Here is my code so far. I am not too concerned about someone "stealing" my code as it's a project from a book, so I'm sending the whole thing. The error returned is "PasswordDahl.j ava:78: cannot find symbol
symbol : class string
location: class PasswordDahl
public static void TestLength(stri ng password)
^
1 error"
Code:
import javax.swing.*;
public class PasswordDahl{
public static void main(String[] args){
String password = JOptionPane.showInputDialog(null, "Enter a password between " +
"6 and 10 characters long using at least one number and one letter.");
TestLength(password);
}
public static void TestDigits(String password){
int i = 0;
char p;
boolean good;
while(i <= password.length()){
if(Character.isLetterOrDigit(i)){
good = true;
if(Character.isDigit(i)){
good = true;
}
else if(Character.isLetter(i)){
good = true;
i = password.length();
}
else{
good = false;
JOptionPane.showInputDialog(null, "Be sure to include "
+ "\nat least one number and one letter. \nPlease try again.");
}
++i;
}
}
}
public static void TestLength(string password){
boolean good;
if(password.length() < (6) || password.length() > (10)){
JOptionPane.showInputDialog(null, "Your password is of insufficient length."
+ "\nIt must be between 6 and 10 characters long.\nPlease try again.");
}
else{
good = true;
TestDigits(password);
}
}
}
Comment