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 4 of 4

Thread: please help super new to Java

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help super new to Java

    I am new to Java and to be honest I am kind of lost, please help me figure out what is wrong with my code.
    i have to write a code that prompts the user for a password using 6 to 10 characters using a letter.
    My apologies if I am posting this in the wrong place

    here is what i have so far:
    import java.util.Scanner;
    public class unit8
     
        {
                //main method
    	public static void main (String [] args)
     
    	{
    	  Scanner myScanner = new Scanner (System.in);
     
    	  // create string variables
    	       String password, confirmpassword;
    	       Boolean digit = false;
    	       Boolean letter = false;
    	       char testCharacter;
    	       String length;
     
     
    	// Prompt to use password
    	       System.out.println(" Please enter a possible password");
    	        password = myScanner.next();
     
    	// test password
    	       for(int i = 0; i<password.length(); i++)
     
     
    	{
     
    	        int passwordLength;
    	        if (passwordLength(length <= 6 || length >= 10));
    	        return false;
     
    	        testCharacter = password.charAt(i);
    	        if(Character.isDigit(testCharacter))
    	        digit = true;
    	         if(Character.isLetter(testCharacter))
    	         letter = true;
    	}
     
    	          if (digit && letter)
     
    	{
    	 // Promt to enter password second time
    	          System.out.println("This is a good password");
    	          confirmpassword = myScanner.next();
    	           if (password.equals(confirmpassword))
    	           System.out.println("Your passwords match congratulations " + password);
    	           else
    	           System.out.println("There is an error please try again");
    	}	
    	           else
    	           System.out.println("Your Password is incorect. Password needs one digit one letter, please try again");
     
    	}
    }


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: please help super new to Java

    What's the problem with it? Does it give you error messages? If so, post up the full message text and stack trace if present. Does it do something it shouldn't or not do something it should? If so, explain what that is.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help super new to Java

    thank you for your fast reply. When ruuning the program it is supposed to ask you a password and should be between 6 to 10 characters and have a letter in it. here is my error messages.

    unit8.java:31: operator <= cannot be applied to java.lang.String,int
    if (passwordLength(length <= 6 || length >= 10));
    ^
    unit8.java:31: operator >= cannot be applied to java.lang.String,int
    if (passwordLength(length <= 6 || length >= 10));
    ^
    unit8.java:31: cannot find symbol
    symbol : method passwordLength(boolean)
    location: class unit8
    if (passwordLength(length <= 6 || length >= 10));
    ^
    unit8.java:32: cannot return a value from method whose result type is void
    return false;
    ^
    4 errors

  4. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: please help super new to Java

    OK - I don't know what that code is trying to do, but on line 30 you declare an int called passwordLength, then try to use it in an 'if' expressions as if it was a method... and for method arguments, you're comparing a String called 'length' with two integer literals, 6 and 10.

    You can't use an int as a method (the compiler is complaining it can't find a method called passwordLength), and you can't compare a String with a number. The 'if' statement won't do anything even if you fix it, because you've put a semi-colon ; on the end of it... The last error is because you're trying to return 'false' from a method that's declared 'void' - which means it can't return any value.

    I suggest you forget about the code, and start with a sheet of paper. Then write down how you would solve this problem step by step in English. Decide what number variables you'll need and what text variables (Strings) you'll need, and how you'd use them to do what is needed. Don't worry about Java until you've worked out exactly how to solve the problem on paper. Once you have a detailed solution written down in English (i.e. pseudo code), and you've stepped through it by hand to make sure it works, then try translating it into Java.

    Designing and coding are tricky enough individually - if you try to do both at the same time, you'll only get confused.
    Last edited by dlorde; June 13th, 2011 at 09:02 PM.

Similar Threads

  1. Super Friendly & Nice Java Forum!
    By friendly_jessie21 in forum Member Introductions
    Replies: 2
    Last Post: February 5th, 2011, 03:28 PM
  2. call super method outside of 'this'
    By questionmark in forum Object Oriented Programming
    Replies: 1
    Last Post: January 29th, 2011, 11:29 AM
  3. Replies: 2
    Last Post: January 7th, 2011, 09:10 PM
  4. SUPER SIMPLE QUESTION!!!
    By Options in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 2nd, 2010, 10:21 PM
  5. Super Mario Frustration
    By Bryan in forum The Cafe
    Replies: 2
    Last Post: June 11th, 2010, 03:46 PM