Results 1 to 2 of 2
  1. #1
    Plex66 is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Help with two tricky methods??? Please?

    I am writing a Java program, and I need to be able to call these two methods, but I'm kind of confused.
    These methods need to be able to match the following data:

    This would be a sample input if what I am checking...

    LASTNAME "Rosemont" #
    LASTNAME "Rose Mont" #
    USERNAME "jRose!" #
    USERNAME "Rose55!" #

    So LASTNAME or USERNAME would be the field, the stuff btwn "" is the content, and the # finishes off a valid entry...

    checkLastname
    A: Must start with an uppercase letter
    B: Must only contain letters and spaces
    C: Any letter after a space must be capitalized
    D: Must be no longer than 20 characters
    E: Must be at least one character

    checkUsername
    A: Must use at least half of the same unique characters as the last LASTNAME read in (you may assume that some LASTNAME appears before any USERNAME)
    B: Cannot contain the character & twice consecutively
    C: Cannot contain the character | twice consecutively
    D: Must be at least five characters long, and no more than 15
    E: Cannot contain the , character
    F: Must be made up of either letters, numbers, or the following list of characters: !,@,#,$,%,^,&,*,(,),_,-,+,<,>,?,:

    This is what I have so far...don't laugh!!!

    Java Code:
    private static void checkLastname(String line, String field, String content) {
    		// TODO Auto-generated method stub
    		{// last name
    			if(field.equals("LASTNAME")){
    				if(content.matches("[^[A-Z][A-Za-z ]*\\s*$]*")){
    					System.out.println("VALID " + line);
    					if(!content.matches("[^[A-Z][A-Za-z ]*\\s*$]*")){
    						if(!content.matches("[^[A-Z][A-Za-z ]*\\s*$]*")){
    							System.out.println("XXXXX " + line
    									+ ", MALFORMED STRING");
    						}
    					}
    				}
    
    				System.out.println("XXXXX " + line
    						+ ", UNRECOGNIZED FIELD");
    			}
    		}
    	}// end Lastname
    Java Code:
    private static void checkUsername(String line, String field, String content) {
    		// TODO Auto-generated method stub
    		{ // Username 
    			if (field.equals("USERNAME")){
    				if (content.matches(" ")) {
    					System.out.println("VALID " + line);
    					//} else {
    					if (!content.matches(" ")) {
    						System.out.println("XXXXX " + line
    								+ ", MALFORMED STRING");
    					}
    				}
    				//} else {
    				System.out.println("XXXXX " + line
    						+ ", UNRECOGNIZED FIELD");
    			}
    		}
    
    	}// end Username
    So, I'm not sure how to get Lastname to be no more than 20 characters and also ensure that the next character after and space is capitalized, and so for Username to have to rely on Lastname is super confusing!!! Tips? Advice? Pleeease!!!

  2. #2
    DiamondSoul is offline Member
    Join Date
    Oct 2011
    Posts
    83
    Rep Power
    0

    Default Re: Help with two tricky methods??? Please?

    I haven't read through the code thoroughly, but the first thing I notice is that you have superfluous curly braces, which would cause a build error.

    Java Code:
    private static void checkUsername(String line, String field, String content) {
            // TODO Auto-generated method stub
            { // Username //OMIT THIS CURLY BRACE
                if (field.equals("USERNAME")){
                    if (content.matches(" ")) {
                        System.out.println("VALID " + line);
                        //} else {
                        if (!content.matches(" ")) {
                            System.out.println("XXXXX " + line
                                    + ", MALFORMED STRING");
                        }
                    }
                    //} else {
                    System.out.println("XXXXX " + line
                            + ", UNRECOGNIZED FIELD");
                }
            } //OMIT THIS CURLY BRACE
     
        }// end Username
    Same thing in the other method.

Similar Threads

  1. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  2. Need some help with tricky program
    By CGHMN in forum New To Java
    Replies: 32
    Last Post: 06-20-2011, 09:46 AM
  3. tricky initial value problem
    By Black_Eye in forum New To Java
    Replies: 4
    Last Post: 10-19-2010, 10:02 AM
  4. Tricky but very interesting problem
    By ravjot28 in forum New To Java
    Replies: 4
    Last Post: 06-26-2008, 02:43 PM
  5. tricky indexOf implementation -- Help!!
    By definewebsites in forum New To Java
    Replies: 3
    Last Post: 12-10-2007, 01:48 AM

Posting Permissions

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