Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Stuck, and i need this to be solved within 2 days.

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Stuck, and i need this to be solved within 2 days.

    SO i was given this mini project but im stuck. (manage to get an extension for another three days)
    (To run in command prompt only)

    Ive searched high and low for the codes and tips but i could seem to find any useful ones. even if i did, i wont know how and where to apply them.



    these are the criteria needed the this user and pass :
    (completed)--> User id should be at least 6 characters long, no digit is allowed.

    (incomplete)--> User’s password should be at least 6 alphanumeric long and contains at least one uppercase and at least one lowercase letter.(using if (Charcter.isLetter(yourCharacter)) and if(Character.isDigit(yourCharacter)))

    (Completed)--> User’s password should have at least one digit number but password shouldn’t be started up with digit.(using if(Character.isLowerCase(yourCharacter)) and if(Character.isUpperCase(yourCharacter)))

    MY problem
    --> i have no idea where to insert those codes at all. It my first "mini project" with such little knowledge that i have.


    SO far, this is what i got...: (could anyone help me out here?)

    import java.util.Scanner;
     
    public class Assign3{
    public static void main (String [] args){
     Scanner input = new Scanner(System.in);
     
    	//call the method
     
    		System.out.println("Welcome to Amazon.com");
    		System.out.println("\nPress ENTER to continue");
    		String letters = input.nextLine();
     
     
    		System.out.println("Criteria");
    		System.out.println();
    		System.out.println("Criteria For ID: \n1.must be at least 6 characters long. \n2.in alphabets only.");
    		System.out.println();
    		System.out.println("Criteria For Password: \n1.at least 6 alphanumeric long and contains at least one uppercase and at least one lowercase letter. \n2.at least one digit number but password shouldn’t be started up with digit.");
    		System.out.println();
     
     
    	//ID 
    		String user_id = enterUserID();
    		while(!checkUserID(user_id)){
    		System.out.println("ID does not matches the criteria.Please re-enter");
    		user_id = enterUserID();
    		}
     
    	//Pass
    		String user_pa = enterUserPA();
    		while(!checkUserPA(user_pa)){
    		System.out.println("PASSWORD does not matches the criteria.Please re-enter");
    		user_pa = enterUserPA();
    		}
     
    	//Accept
    		System.out.println("ID and PASSWORD is accepted.");
    		}
     
    	//Entering userID
    		public static String enterUserID(){
            String user_id;
            Scanner input = new Scanner(System.in);
            System.out.print("ID: ");
            user_id = input.nextLine();
            return user_id;
            }
     
    	//Entering userPA
    		public static String enterUserPA(){
            String user_pa;
            Scanner input = new Scanner(System.in);
            System.out.print("Password: ");
            user_pa = input.nextLine();
            return user_pa;
            }
     
     
    	//ID check
    		 public static boolean checkUserID(String user_id){
            int length;
            length = user_id.length();
                if (length < 6 || length > 99999){
                return false;
                }
            for (int i = 0; i < user_id.length();i++){
                if (!Character.isLetter(user_id.charAt(i)))
                return false;
            }
            return true;
            }
     
    	//PA check
    		 public static boolean checkUserPA(String user_pa){
            int length;
     
            length = user_pa.length();
                if (length < 6 || length > 99999){
                return false;
                }
           for(int i = 0; i < user_pa.length();i++){
     for(int i = 0; i < user_pa.length();i++){
    	   if(Character.isDigit(user_pa.charAt(0)))
    		if(!Character.isLetter(user_pa.charAt(i)))
    		if(Character.isUpperCase(user_pa.charAt(0)))
    		if(Character.isLowerCase(user_pa.charAt(0)))
                return false;
            }
            return true;
            }
    		}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    Please explain what your problem is. What does the code do now? What is wrong with what it does?
    Post the input and output and add some comments describing what is wrong.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    So your code works except for the password check. It is close but has some inherit errors. I've worked through it on my end and will help you along. I would suggest deleting that for loop in the checkUserPA function and starting over on it. Go step by step on what you need to check and make sure each piece is returning the right value.
    Writing code is your job, helping you fix and understand it is mine.

    <-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    You give us things we don't need: a due date, you give us some requirements and some code (unformatted), but you don't ask a specific answerable question, one that tells us where you're stuck exactly. Please fix this so we can help you better.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    okay. done =)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    Pleae edit the post and fix the formatting for the code. The indentations are all messed up making it very hard to read and understand the code.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    You have to check the ID and password for case and alphanumeric:

    A useful Java method isLetterOrDigit
    Character (Java Platform SE 7 )

    Some people prefer regex, which searches for a particular pattern.

    There's also one in the Character class called isLowerCase()

    Always try and check the API in case there is something already available.

  8. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    thanks for having a look at my thread and using that time that you have to help me out.
    as you can see, i have very little knowledge on java. Im more of a visual learner. So if you could give examples on how the codes are suppose to look like, then there is a high possibility i could get this done.

    especially this last part. I just couldn't get it right.
     for(int i = 0; i < user_pa.length();i++){
    	   if(Character.isDigit(user_pa.charAt(0)))
    		if(!Character.isLetter(user_pa.charAt(i)))
    		if(Character.isUpperCase(user_pa.charAt(0)))
    		if(Character.isLowerCase(user_pa.charAt(0)))
                return false;
            }
            return true;
            }
    		}


    --- Update ---

    Quote Originally Posted by Starstreak View Post
    You have to check the ID and password for case and alphanumeric:

    A useful Java method isLetterOrDigit
    Character (Java Platform SE 7 )

    Some people prefer regex, which searches for a particular pattern.

    There's also one in the Character class called isLowerCase()

    Always try and check the API in case there is something already available.

    Thank you for using what little time you have to take a look at my thread. REally appreciate that help. by the way I just need it to be able to run in command prompt without any errors. thats all. im a novice at JAVA.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    examples on how the codes are suppose to look like
    Most of the code posted on the forum ends up being properly formatted. Look at some of the other threads
    or look at the code in the tutorial:
    The Really Big Index
    Code Conventions for the Java Programming Language: Contents
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    Quote Originally Posted by Chris.Brown.SPE View Post
    So your code works except for the password check. It is close but has some inherit errors. I've worked through it on my end and will help you along. I would suggest deleting that for loop in the checkUserPA function and starting over on it. Go step by step on what you need to check and make sure each piece is returning the right value.
    this is the latest update i have for the PA check section. i still cant get it right especially for the arrays for alphanumeric and at least one uppercase and one lowercase letter.
    //PA check
    		 public static boolean checkUserPA(String user_pa){
            int length;
    		char [] chr = user_pa.toCharArray();
     
            length = user_pa.length();
     
                if (length < 6 || length > 99999){
                return false;
                }
           for(int i = 0; i < user_pa.length();i++){
    	   if(Character.isDigit(user_pa.charAt(0)))
    		if(!Character.isLetter(user_pa.charAt(i)))
    		 if(!Character.isUpperCase(user_pa.charAt(chr)))
                return false;
            }
            return true;
            }
    		}

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Stuck, and i need this to be solved within 2 days.

    The first three lines of the method should look like this:
         //PA check
         public static boolean checkUserPA(String user_pa){
             int length;
    	 char [] chr = user_pa.toCharArray();

    Always use {}s with if statements to show clearly what statements are included inside the if statement.

    at least one uppercase and one lowercase letter.
    The method should scan the whole String and set a boolean true when it finds each of the required types of characters. At the end of the method return all the booleans ANDed together. For example:
       return hasType1 && hasType2 && hasType3;
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. 12 days of xmas??? not showing
    By chonch in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2011, 09:45 PM
  2. Calculating Business days in java
    By narranil2 in forum Algorithms & Recursion
    Replies: 2
    Last Post: August 17th, 2010, 12:08 PM
  3. how do i get only the workig days for a certain month
    By anonimus83 in forum Algorithms & Recursion
    Replies: 2
    Last Post: January 11th, 2010, 11:13 AM
  4. Replies: 24
    Last Post: April 14th, 2009, 03:43 PM

Tags for this Thread