Results 1 to 3 of 3
  1. #1
    afisher300 is offline Member
    Join Date
    Mar 2008
    Rep Power

    Default need help with do/while loop inc wrapper classes

    I hope someone can help.. All of my code, is quite long, so I am hoping I can send what i need to. My main program is I have to test passwords that people enter to ensure the length, if they have a lower and uppercase letter, and a digit. I have boolean variables for all al of these, then i have it where it goes through each characther in the password. So I was thinking I had to do this as a do while instead of a for loop (the for loop is still there just commented out), because if I did that then it would just keep switching back and forth?? It compiles but it wont even let me enter the passwords which happens in the 2nd method. if anybody has any ideas. Also if they have time my last method report Validity is where i am supposed to print the out come of the passowrds but it just prints the first password and then prints **too short then it shows as 2nd password and same thing, it wont go through all the passwords. I am so lost. If anybody has anything oiut there for me thank you very much in advance. ( of course now the last couple of methods dont word I commented them out, I was jusst trying to get each method to work so I do know that reason

    Java Code:
    import javax.swing.*;  //to use JOptionPane
    import java.util.Scanner; // use for Scanner
    public class PasswordTest1
      private static String passwordsBeingEntered; // the passwords that are being entered
      private static String testPlansAuthor;// name of the author who is testing their passwords
      private static String reportString; // this is the output string
      private static String inputLine; // this will help determine th case of rhe charactewrs
      private static int numberOfPasswords; // total number of passwords
      private static int validPassword;  //  how many of the passwards that have been entered are good
      private static int invalidPassword;  //how many of the passwords that have been entered are bad
      private static final int PASSWORD_LENGTH = 6; // minimum number of password there are supposed to be
      private static boolean length = false; // checks to see if the length is 6 or over
      private static boolean lowercase = false; // checks to see if password has a lowercase letter
      private static boolean uppercase = false; // checks to see if password has a uppercase letter
      private static boolean digit = false; // checks to see if the password has a digit in it
      private static char ch; // a character used for methods
      static Scanner keyboard = new Scanner(;
      public static void main(String[] args)
        PasswordTest mypassword = new PasswordTest();
    	 for (int index = 0; index < numberOfPasswords; index++)
    //		 mypassword.checkUppercase();
    //		 mypassword.checkDigit();
    //		 mypassword.reportValidity();
    	 }// end of for loop
    	}//end of main 
       public static void startPasswordChecker()
           System.out.println("Please welcome to the Password Checker Program" +
      								"\n\nThis prgram asks the user how many passwords they choose to check" +  
    								"\n and the computer will determine how many of the passwords " +
    								"\nare valid and how many are bad");
    		 numberOfPasswords = Integer.parseInt(JOptionPane.showInputDialog("Please enter how many " +
    	                        "passwords you would like to check?"));
    		 testPlansAuthor = (JOptionPane.showInputDialog("Please enter your name?"));
    		 // this string is the beginning of the output string showing the number
    		 // showing the program name, programmers name, name of the person testing
    		 // the passwors and how many passwords
           reportString = ("Password Checker" + "\t by Amy Fisher" + 
    									"\nTest plan Author" + testPlansAuthor +
    									"\nPasswords checked:" + numberOfPasswords);
       }// end of startPasswordChecker method
       //This method allows the user to input the passwords using the scanner option
    	//and the input of the passwords that will be tested
       public static void inputPassword()
         System.out.print("Please enter the password that you would like tested? ");
    	    passwordsBeingEntered = keyboard.nextLine();
       }//end of inputPasswordMethod
       // This method checks the length of all passwords submitted to make sure they meed the
       // length required
       public static void checkLength()
         if (passwordsBeingEntered.length() > PASSWORD_LENGTH)
    		     length = false;
    			  System.out.print(passwordsBeingEntered.length() + " " + length);
    		      length = true;
    				System.out.print(passwordsBeingEntered.length() + " " + length);
    	 }   // end of checkLength Method
      //This method checks to make sure the password that is being checked has a at 
      // least one lowercase letter in the password.
       public static void checkLowercase()
    	{int i = 0;
        while (Character.isLowerCase(ch)); 
    	 {// int i = 0;
    	  // ch=passwordsBeingEntered.charAt(i);
    	   lowercase = true;
    		System.out.println("lowercase  " + lowercase);
    //	 System.out.println(lowercase
    //	 for (int i = 0; i < numberOfPasswords; i++) 
    //	 { ch = passwordsBeingEntered.charAt(i);
    //	   if (Character.isLowerCase(ch))
    //	    {  
    //		    lowercase = false;
    //			 System.out.println("lowercase and " + lowercase);
    //		 }	 
    //	   else
    //		 {
    //		   lowercase = true;
    //			System.out.println("not lowercase and " + lowercase);
    //		 }
    //	  }// end of for loop
    	 } // of of checkLowercase Method
    	 //This method checks to make sure the password that is being checked has at  
    	 //least one uppercase letter in the password.
    	  public static void checkUppercase()
    	   for (int index=0; index < numberOfPasswords; index++)
    		 { ch = passwordsBeingEntered.charAt(index);
    		   if (Character.isUpperCase(ch))
    			    uppercase = true;	 
    			    uppercase = false;
    		  }// end of for loop
    		}//end of checkUppercase Method
      	 // This method checks to make sure the password that is being checked has a at 
        // least one lowercase letter in the password.
        public static void checkDigit()
         for (int i = 0; i < numberOfPasswords; i++) 
    	   { ch = passwordsBeingEntered.charAt(i);
    	     if (Character.isDigit(ch))
    			   digit = true;
    			   digit = false;
    		 }// end of for loop	 
    	  }// end of checkDigit Method
    	  // This method helps gather the information that will be needed to be placed into the 
    	  // reportString to show the user how many passwords are correct or not, and the reason
    	  // why they are not correct.
    	  public static void reportValidity()
    	    for (int i = 1; i <= numberOfPasswords; i++)
    		   System.out.print(i + ". " + passwordsBeingEntered);//(i) + "  ");
    			if (length = true)
    				{	System.out.print("**too short  ");
    			else if (lowercase = true)
    			     {  System.out.print("** no lowercase  ");	
    			else if (uppercase = true)
    			     {  System.out.print("** no uppercase  ");
    			else if (digit = true)
    				  {  System.out.print("**no digit  ");
    				  {  System.out.print("  valid password");
    	  }// end of reportValidity Method*/ 
    }// end of class PasswordTest

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Rep Power


    One small Suggestion.
    Before writing the code dirctly,start with pseudocode.
    It helps you to go ahead with the logic without confusion.

    Please start with pseudocode and if you face any problems,I will help you out.


  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power

Similar Threads

  1. pointers and wrapper classes
    By becky in forum New To Java
    Replies: 11
    Last Post: 02-07-2009, 03:59 AM
  2. What are wrapper classes?
    By maheshkanda in forum New To Java
    Replies: 1
    Last Post: 02-06-2009, 04:39 PM
  3. Secure FTP Wrapper 3.0.3
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-23-2008, 01:56 PM
  4. wrapper classes
    By sireesha in forum New To Java
    Replies: 5
    Last Post: 12-11-2007, 09:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts