Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

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;
            }
        }
    }

}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY