Hey, everybody. Could you take a look at this program for my introductory Java class at the community college? I'm just wondering if there are any fixes I can make to make the program better. I am a beginning programmer, and this program uses most of my skills, so no super-technical jargon, please. Help reviewing basic program for class

 

 

import java.util.Scanner;

 

 

public class PasswordChecker {

        public static void main(String[] args) {

                System.out.println("Enter a password: ");

                Scanner input = new Scanner(System.in);

                String password = input.next();

                float score = 0;

                char c;

                int cap = 0;

                int low = 0;

                int numbers = 0;

                int chars = 0;

                boolean check = false;

                if(password.length() >= 6)

                        score++;

                //System.out.println(score + " length");

 

 

                char[] caps = {'A', 'B', 'C', 'D', 'E', 'F', 'G',

                                'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',

                                'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',

                                'X', 'Y', 'Z'};

                char[] lows = {'a', 'b', 'c', 'd', 'e', 'f', 'g',

                                'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',

                                'p', 'q', 'r', 's', 't', 'u', 'v', 'q',

                                'x', 'y', 'z'};

 

 

                char[] ints = {'0', '1', '2', '3', '4', '5', '6',

                                '7', '8', '9'};

               

                String[] passwords = {"password", "123456", "12345678",

                "qwerty", "baseball", "football", "letmein",

                "111111", "superman", "master", "harley",

                "drowssap", "654321", "87654321", "ytrewq",

                "llabesab", "llabtoof", "niemtel", "111111",

                "namrepus", "retsam", "yelrah"};

 

 

                for(int i = 0; i < password.length(); i++) {

                        c = password.charAt(i);

                        for(int j = 0; j < 26; j++) {

                                if(c == caps[j])

                                     cap++;

                        }

                }

                if(cap != 0)

                        score ++;

               

                //System.out.println(score + " caps " + cap);

               

                for(int i = 0; i < password.length(); i++) {

                c = password.charAt(i);

                for(int j = 0; j < 26; j++) {

                if(c == lows[j]) {

                low++;

                }

                }   

                }

            if(low != 0)

                score ++;

           

            //System.out.println(score + " lows " + low);

           

            for(int i = 0; i < password.length(); i++) {

            c = password.charAt(i);

            for(int j = 0; j < 10; j++) {

            if(c == ints[j])

            numbers++;

            }

            }

            if(numbers != 0)

            score ++;

               

               // System.out.println(score + " numbers " + numbers);

               

                for(int i = 0; i < passwords.length; i++) {

                String p = passwords[i];

                if(password.equals(p))

                score -= 5;

                }

 

 

                chars = (password.length() - (low + cap + numbers));

                if(chars != 0)

                score ++;

               

               // System.out.println(score + " chars " + chars);

               

                System.out.println();

                System.out.println("Your score is " + score);

                System.out.println();

                System.out.println("Total characters: " + password.length());

                System.out.println("CAPITAL LETTERS: " + cap);

                System.out.println("lowercase letters: " + low);

                System.out.println("Nu4483r5: " + numbers);

                System.out.println("$|>3(|/-\\| ([-]/-\\|^/-\\(+3|^$: " +

                chars);

                input.close();

        }

}

FacebookTwitterLinkedin
Pin It
Joomla Tutorials for Beginners