• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program not working how I think it should  RSS feed

 
John Sing
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I need to make an addition to my program so the user can pick if they want to exit it or not. I thought I figured out a way to do this and it seems to work in my head but it does not actually work in the program. When the user clicks the yes button then the program is supposed to start over, but instead it ignores my new password input inside the program and instead uses the old password over and over. How can I fix this? Here is my code

 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally speaking, on this type of problem it is done with a while loop:
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 26 you get the encrypted password but you haven't prompted for a password yet. I'm presuming you get back the encryption of an empty String (?).

On line 34 you prompt for a password but throw the return value away.
 
John Sing
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:On line 26 you get the encrypted password but you haven't prompted for a password yet. I'm presuming you get back the encryption of an empty String (?).

On line 34 you prompt for a password but throw the return value away.


Well I was trying to call the method like I call the main method. So how would I do that? Here is my new code



If I can somehow call the getPassword method again and get it to accept the new value of password I put in everything should work. But how would I do about doing this?
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you passing your 'password' variable to UserInfo ?
 
Steffe Wilson
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An identical question was asked earlier today, with almost identical code, so the answers may help..
http://www.coderanch.com/t/661890/java/java/program-start#3073758
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String concatenation:
When you have two String constants being concatenated you can edit your code to make them one String.
Example
"Congratulations" + " " + Name + " " + "your encrypted password is" + " " + passwordPrint + " " + "good luck remembering that..."
becomes
"Congratulations " + Name + " your encrypted password is " + passwordPrint + " good luck remembering that..."
 
John Sing
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Where are you passing your 'password' variable to UserInfo ?


Here is my UserInfo code
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Where are you passing your 'password' variable to UserInfo ?

You haven't answered the question.

Do you know how to pass values into a method or constructor?

One of the features of OO programming is encapsulation. The ability to use classes without necessarily needing to understand how they work. Responsibilities should be clear and distinct.

You have failed to encapsulate your two classes in two ways:
  • Your UserInfo reaches back to the Driver class to call getPassword(). UserInfo should not have anything to do with user input. That is the responsibility of the Driver class.
  • Your Driver class calls a set of UserInfo methods (e.g. callMethods.removeWhiteSpaceAndConvertToUpper()). These are helper methods in UserInfo and the Driver class shouldn't even know that they exist.
  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!