• Post Reply Bookmark Topic Watch Topic
  • New Topic

Password Rule using Wrapper Class  RSS feed

 
Rahza Nassah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

This is my first post here, I hope I am not posting it in the wrong section.

I have to use wrapper class for this assignment. I need to know if my code is more like object oriented or not and am I using the wrapper class properly here? Let me know if I can make this code better.

I also need to know if I can mask this password input (STRING) using NetBeans/Eclipse IDE?

Password rule is as followed : Length of Password 8-12, with no special characters, including minimum one uppercase letter, and only one numeric value.

Here is the code :


Thanks in advance!
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Your program isn't object oriented because it doesn't use objects, which is fine for a short program like this.

A couple of notes:

* Check out String.index(). It will save you several for loops.
* The convention for method names is camelCase
* Your program doesn't do everything in main: good. It uses static methods: not so good. Check out MainIsAPain. Some of it won't apply to your program.
* I'm a big fan of whitespace, but sometimes you use too much, for instance:



This should probably be:



Develop some consistent whitespace rules and use them. In general, I use it to make syntax clear and to divide logical sections.
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the "wrapper class" you think you are using? I don't see any classes being used except String and Scanner.
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing: break long program lines into smaller lines. Strings that post to the screen should be 79 characters or less. And for prompts you can use System.out.print() instead of println().
 
Rahza Nassah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:

Your program isn't object oriented because it doesn't use objects, which is fine for a short program like this.


So if I just put main in other class, create object for it to call the methods, it will make it object oriented?

Knute Snortum wrote:
* Check out String.index(). It will save you several for loops.


I don't get this, I did search but ended up with indexOf(). Can you give me an example, just a chunk of the code?

Thanks!


Paul Clapham wrote:What's the "wrapper class" you think you are using? I don't see any classes being used except String and Scanner.


I have to make this password policy using wrapper class, is what we are asked to do. Now what I studied under wrapper class after boxing, unboxing were static methods in wrapper classes that are useful for string processing. Those character class methods are as following :
-isLetter
-isDigit
-isLetterOrDigit etc

I have to use these methods to create this password policy. I am not doing anything wrong here, am I? We are asked to create this password policy using wrapper classes. So basically its those methods inside wrapper class that we have to use, right?
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have sorted out the long lines (well, some of them), so you can see how it should be done.
Don't use \n even if you found it in a book, unless somebody has told you to produce the LF character. Use printf and the %n tag.
Never write == false or == true, which are poor style and error‑prone is you write = by mistake.
Write if (b)… or if (!b)…
We have some suggestions about indentation and formatting. Avoid blank lines after { and before } for example; they make the code more difficult to read. We ahve some suggestions about text editors which make if much easier to format your code.
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your if statements, you're doing the same thing in the if and the else. That means to me that something isn't conditional.



as an example:


can be refactored:


 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahza Nassah wrote:I have to make this password policy using wrapper class, is what we are asked to do. Now what I studied under wrapper class after boxing, unboxing were static methods in wrapper classes that are useful for string processing. Those character class methods are as following :
-isLetter
-isDigit
-isLetterOrDigit etc

I have to use these methods to create this password policy. I am not doing anything wrong here, am I? We are asked to create this password policy using wrapper classes. So basically its those methods inside wrapper class that we have to use, right?


Those are just static methods of the Character class, you're not using auto-boxing to create a Character object from a char. So I guess technically you're using a "wrapper" class, but I have no idea whether that fulfils your requirement. But frankly I don't understand the requirement anyway. It doesn't say you're supposed to use auto-boxing, does it? But if you don't have to do that, what's the point of using one of the wrapper classes associated with it?

So... sorry, I can't answer that question. I get so tired of seeing beginners being taught bad ideas which they will have to unlearn later.
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahza Nassah wrote:
Knute Snortum wrote:

Your program isn't object oriented because it doesn't use objects, which is fine for a short program like this.


So if I just put main in other class, create object for it to call the methods, it will make it object oriented?


Yes, but there isn't any reason unless you've been told to.


Knute Snortum wrote:
* Check out String.index(). It will save you several for loops.


I don't get this, I did search but ended up with indexOf(). Can you give me an example, just a chunk of the code?

Thanks!


Oops, sorry. Yes, indexOf() is what I was thinking of. This is a minor problem of knowing more than one programming language. You would use it like this:



But now that I think of it, a regex and find() would be better. This is maybe a little more code than I would usually give out, but regexs are tough at the beginning:



 
Rahza Nassah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Those are just static methods of the Character class, you're not using auto-boxing to create a Character object from a char. So I guess technically you're using a "wrapper" class, but I have no idea whether that fulfils your requirement. But frankly I don't understand the requirement anyway. It doesn't say you're supposed to use auto-boxing, does it? But if you don't have to do that, what's the point of using one of the wrapper classes associated with it?

So... sorry, I can't answer that question. I get so tired of seeing beginners being taught bad ideas which they will have to unlearn later.


Nope it doesn't say anything about auto boxing. Maybe I should do it with auto boxing, but no idea how to. Can I get an example of auto boxing to create a Character object from a char in my code?


Thanks a ton guys!
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahza Nassah wrote:Can I get an example of auto boxing to create a Character object from a char in my code?


Sure.



But like I said, you don't need any Character objects to do this assignment. Maybe you ought to speak to the person who told you to do this assignment rather than asking random people on the internet to speculate?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!