permaculture playing cards*
The moose likes Beginning Java and the fly likes how 2 do this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

how 2 do this code

vuthlarhi donald
Ranch Hand

Joined: Jul 31, 2006
Posts: 76
Use your person class to do the following:

Write a class that does the following:
- Creates 10 instances of your person class with all the information filled in (names, email, username, password etc).//I am done with that
- Prompts a user to enter their username and password.// done with that
- if the username/password combination exists for one of your ten users then print out a welcome message as well as all the details of that user.
// how do I determine that
- if the username/password combination fails, allow them to try again.
- if they have filled in the wrong username/password combo for 3 times, display a message informing them of this and quit.
Kevin Cahill
Greenhorn

Joined: Jan 08, 2008
Posts: 9
You could try to determine if the user/pw exists with a case statement. If it finds a match, then print a welcome message. Once you get that working, then add the other 2 requirements. At least that's how I'd begin to approach the problem. Please post a copy or copies of some of the solutions you've tried and we can work through it.


Persistence and determination alone are omnipotent.<br />---Calvin Coolidge
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

How are you storing the 10 instances? Hopefully, you're using an array or some collection. maybe there is an easy way to circle around or through your objects, comparing the names on each one to what the user enters...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
http://faq.javaranch.com/java/ShowSomeEffort
http://faq.javaranch.com/java/CarefullyChooseOneForum
http://faq.javaranch.com/java/UseAMeaningfulSubjectLine
http://faq.javaranch.com/java/DoYourOwnHomework
http://faq.javaranch.com/java/UseRealWords
[ January 09, 2008: Message edited by: Bill Shirley ]

Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Welcome to the Ranch, Kevin Cahill.

Are you sure about a switch-case? You can't pass a String to a switch. See this part of the Java Tutorial. But you are correct that Vuthlarhi Donald ought to post some code, even if it doesn't work.
Kevin Cahill
Greenhorn

Joined: Jan 08, 2008
Posts: 9
Thanks Campbell for straightening me out. I looked over the tutorial you suggested. Sorry for the bad advice, I guess I would have found that detail out rather quickly had I tried to use the case statement with a string. I'm a noob to all of this and thought I could learn some things by trying to answer questions....and I did!! I'll try to be more careful in the future, so as not to confuse other's "like me"....
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

follow-ups here
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how 2 do this code