12 Replies - 292 Views - Last Post: 25 September 2012 - 01:14 PM Rate Topic: -----

#1 JavaBonckers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 12

Error with logic? It will not verify.

Posted 25 September 2012 - 08:12 AM

import javax.swing.*;

	public class Password

	{

		public static void main(String[] args)

		{

			String password ="";
			
			String passwordRepeat ="";

				char charChecked = '\n';
				boolean letterPresent = false;
				boolean digitPressent = false;
				int len = password.length();
				
			password = JOptionPane.showInputDialog("Please enter a possible password: \n It must be 6 to 10 characters long \n It also must contain at least one letter and one number");
				while((len < 6 ||len > 10)||!
					(Character.isLetterOrDigit(password.charAt(0))))
{
			password = JOptionPane.showInputDialog("Invalid password \n Please re-enter password");
}
	if((len >= 6 || len <= 10)|| Character.isLetterOrDigit(password.charAt(0)))
	do
{
			passwordRepeat =JOptionPane.showInputDialog("Please reenter password.");
}
	while (!(password.equals(passwordRepeat)));
	if(password.equals(passwordRepeat))
{
	JOptionPane.showMessageDialog(null, "Congratulations! Your password has been set.");
		}
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Error with logic? It will not verify.

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2780
  • View blog
  • Posts: 11,765
  • Joined: 20-September 08

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 08:24 AM

Probably easiest to make a validation method to test in a loop:

static boolean isValid(String password) {
  int length = password.length();
  return length >= 6 && length <= 10 && password.matches(".*\\d.*") && password.matches(".*[A-Za-z].*);
}

This post has been edited by g00se: 25 September 2012 - 08:24 AM

Was This Post Helpful? 0
  • +
  • -

#3 JavaBonckers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 12

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 08:45 AM

View Postg00se, on 25 September 2012 - 03:24 PM, said:

Probably easiest to make a validation method to test in a loop:

static boolean isValid(String password) {
  int length = password.length();
  return length >= 6 && length <= 10 && password.matches(".*\\d.*") && password.matches(".*[A-Za-z].*);
}

Please forgive me but I am trying to understand if I plug this statement in with the if and while or take them out?
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2780
  • View blog
  • Posts: 11,765
  • Joined: 20-September 08

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 09:20 AM

Paste the method into your own class and you can do

import javax.swing.JOptionPane;


public class Password {
    public static void main(String[] args) {
        while (!Password.isValid(JOptionPane.showInputDialog(
                        "Please enter a possible password: \n It must be 6 to 10 characters long \n It also must contain at least one letter and one number")))
            ;
    }

    static boolean isValid(String password) {
        int length = password.length();

        return (length >= 6) && (length <= 10) && password.matches(".*\\d.*") &&
        password.matches(".*[A-Za-z].*");
    }
}


Was This Post Helpful? 0
  • +
  • -

#5 JavaBonckers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 12

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 10:07 AM

Quote

It is now telling me it cannot find symbol


import javax.swing.JOptionPane;
 
	public class Passwordtest {

	   public static void main(String[] args) {

 	     while (!Password.isValid(JOptionPane.showInputDialog
		  ("Please enter a possible password: \n It must be 6 to 10 characters long \n It also must contain at least one letter and one number")));
   }
 
    static boolean isValid(String password) {

    int length = password.length();

    return (length >= 6) && (length <= 10) && password.matches(".*\\d.*") &&

    password.matches(".*[A-Za-z].*");

	if((len >= 6 || len <= 10)|| Character.isLetterOrDigit(password.charAt(0)))
	do
{
			passwordRepeat =JOptionPane.showInputDialog("Please reenter password.");
}
	while (!(password.equals(passwordRepeat)));
	if(password.equals(passwordRepeat))
	
{
	JOptionPane.showMessageDialog(null, "Congratulations! Your password has been set.");
		}
	}
}

Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 11:34 AM

Which symbol ?
Please, when you have an error (compilation or run time) please the complete error displayed to you
Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2780
  • View blog
  • Posts: 11,765
  • Joined: 20-September 08

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 11:59 AM

That's NOT the code i posted
Was This Post Helpful? 0
  • +
  • -

#8 JavaBonckers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 12

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 12:19 PM

[quote name='g00se' date='25 September 2012 - 06:59 PM' timestamp='1348599554' post='1709350']
That's NOT the code i posted

Quote

That is your code infused with my code as you requested

 ----jGRASP exec: javac -g Passwordtest.java

Passwordtest.java:7: cannot find symbol
symbol  : method isValid(java.lang.String)
location: class Password
 	     while (!Password.isValid(JOptionPane.showInputDialog
                             ^
Passwordtest.java:19: cannot find symbol
symbol  : variable len
location: class Passwordtest
	if((len >= 6 || len <= 10)|| Character.isLetterOrDigit(password.charAt(0)))
            ^
Passwordtest.java:19: cannot find symbol
symbol  : variable len
location: class Passwordtest
	if((len >= 6 || len <= 10)|| Character.isLetterOrDigit(password.charAt(0)))
                        ^
Passwordtest.java:22: cannot find symbol
symbol  : variable passwordRepeat
location: class Passwordtest
			passwordRepeat =JOptionPane.showInputDialog("Please reenter password.");
                        ^
Passwordtest.java:24: cannot find symbol
symbol  : variable passwordRepeat
location: class Passwordtest
	while (!(password.equals(passwordRepeat)));
                                 ^
Passwordtest.java:25: cannot find symbol
symbol  : variable passwordRepeat
location: class Passwordtest
	if(password.equals(passwordRepeat))
                           ^
6 errors

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.



[quote name='pbl' date='25 September 2012 - 06:34 PM' timestamp='1348598058' post='1709327']
Which symbol ?
Please, when you have an error (compilation or run time) please the complete error displayed to you

Quote

I'm new to this ok, below is the jGRASP error

Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2780
  • View blog
  • Posts: 11,765
  • Joined: 20-September 08

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 12:20 PM

Sorry - my comment was misleading. I originally intended you to integrate it but actually did it for you
Was This Post Helpful? 0
  • +
  • -

#10 JavaBonckers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 12

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 12:22 PM

[quote name='JavaBonckers' date='25 September 2012 - 07:19 PM' timestamp='1348600748' post='1709356']
[quote name='g00se' date='25 September 2012 - 06:59 PM' timestamp='1348599554' post='1709350']
That's NOT the code i posted

Quote

That is your code infused with my code as you requested

 ----jGRASP exec: javac -g Passwordtest.java

Passwordtest.java:7: cannot find symbol
symbol  : method isValid(java.lang.String)
location: class Password
 	     while (!Password.isValid(JOptionPane.showInputDialog
                             ^
Passwordtest.java:19: cannot find symbol
symbol  : variable len
location: class Passwordtest
	if((len >= 6 || len <= 10)|| Character.isLetterOrDigit(password.charAt(0)))
            ^
Passwordtest.java:19: cannot find symbol
symbol  : variable len
location: class Passwordtest
	if((len >= 6 || len <= 10)|| Character.isLetterOrDigit(password.charAt(0)))
                        ^
Passwordtest.java:22: cannot find symbol
symbol  : variable passwordRepeat
location: class Passwordtest
			passwordRepeat =JOptionPane.showInputDialog("Please reenter password.");
                        ^
Passwordtest.java:24: cannot find symbol
symbol  : variable passwordRepeat
location: class Passwordtest
	while (!(password.equals(passwordRepeat)));
                                 ^
Passwordtest.java:25: cannot find symbol
symbol  : variable passwordRepeat
location: class Passwordtest
	if(password.equals(passwordRepeat))
                           ^
6 errors

 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.



[quote name='pbl' date='25 September 2012 - 06:34 PM' timestamp='1348598058' post='1709327']
Which symbol ?
Please, when you have an error (compilation or run time) please the complete error displayed to you

Quote

I'm new to this ok, below is the jGRASP error

Quote

or above

Was This Post Helpful? 0
  • +
  • -

#11 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2780
  • View blog
  • Posts: 11,765
  • Joined: 20-September 08

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 12:25 PM

See my last comment
Was This Post Helpful? 1
  • +
  • -

#12 JavaBonckers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 25-September 12

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 12:47 PM

[quote name='g00se' date='25 September 2012 - 07:25 PM' timestamp='1348601102' post='1709365']
See my last comment

Quote

That will get me started, thanks. I have to add more but I think I'm on track thanks to you. :bananaman:

Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Error with logic? It will not verify.

Posted 25 September 2012 - 01:14 PM

Quote

That's NOT the code i posted

so post your updated code that match the jgrasp errors
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1