am having a lot of errors pop up, and I need the pattern to follow the instructions below. Please don't send me the program that is already in Bartleby, it isn't right. Professor instructions: Write a Java program that prompts the user to enter a security code that matches a specific pattern. Your program must approve the user's entry. The pattern consists of these characters in this sequence: A lower case character, two upper case characters, two or three digits, two lower case characters, an upper case character, 2 or 3 lower case characters, 2 digits.
I am having a lot of errors pop up, and I need the pattern to follow the instructions below. Please don't send me the program that is already in Bartleby, it isn't right.
Professor instructions: Write a Java program that prompts the user to enter a security code that matches a specific pattern. Your program must approve the user's entry. The pattern consists of these characters in this sequence:
A lower case character, two upper case characters, two or three digits, two lower case characters, an upper case character, 2 or 3 lower case characters, 2 digits.
This is the code I have, but errors are poping up:
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the code pattern ");
String s;
s = scan.next();
if (s.length() == 12) {
if (first12(s) && last(s.substring(10)) && middle(s.substring(8,10))) {
System.out.print("Yes, ");
System.out.print(s);
System.out.println("matches the pattern");
}
else{
System.out.print("No, ");
System.out.print(s);
System.out.println(" doen't matches the pattern");
}
}
else if(s.length()==14){
if(first12(s) && last(s.substring(11)) && middle(s.substring(8,11))){
System.out.print("Yes, ");
System.out.print(s);
System.out.println(" matches the pattern");
}
else{
System.out.print("No, ");
System.out.print(s);
System.out.println(" doen't matches the pattern");
}
}
else{
System.out.print("No, ");
System.out.print(s);
System.out.println(" doen't matches the pattern");
}
scan.close();
}
public static Boolean first12(String s){
char c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11;
c0 = s.charAt(0);
c1 = s.charAt(1);
c2 = s.charAt(2);
c3 = s.charAt(3);
c4 = s.charAt(4);
c5 = s.charAt(5);
c6 = s.charAt(6);
c7 = s.charAt(7);
c8 = s.charAt(8);
c9 = s.charAt(9);
c10 = s.charAt(10);
c11 = s.charAt(11);
if(Character.isLowerCase(c0) &&
Character.isUpperCase(c1) &&
Character.isUpperCase(c2) &&
Character.isDigit(c3) &&
Character.isDigit(c4) &&
Character.isLowerCase(c5) &&
Character.isLowerCase(c6) &&
Character.isUpperCase(c7) &&
Character.isLowerCase(c8) &&
Character.isLowerCase(c9) &&
Character.isDigit(c10) &&
Character.isDigit(c11)){
return true;
}
else {
return false;
}
}
public static Boolean last(String s) {
char c0, c1, c2;
c0 = s.charAt(0);
c1 = s.charAt(1);
c2 = s.charAt(2);
if (Character.isLowerCase(c0) && Character.isUpperCase(c1) && Character.isUpperCase(c2)) {
return true;
}
else {
return false;
}
}
public static Boolean middle(String s) {
if (s.length() == 2) {
char c0, c1;
c0 = s.charAt(0);
c1 = s.charAt(1);
if ( Character.isLowerCase(c0) && Character.isUpperCase(c1)) {
return true;
}
else {
return false;
}
}
else {
char c0, c1, c2;
c0 = s.charAt(0);
c1 = s.charAt(1);
c2 = s.charAt(2);
if (Character.isLowerCase(c0) && Character.isUpperCase(c1) && Character.isUpperCase(c2)) {
return true;
}
else {
return false;
}
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images