aspose file tools*
The moose likes Beginning Java and the fly likes A small question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A small question" Watch "A small question" New topic
Author

A small question

Dustin Moorman
Greenhorn

Joined: Oct 06, 2008
Posts: 2
Hey guys, I'm learning java right now, and I would like some input on this code. What it is, is a login if/else statement. I'm trying to get the user to have an option to make his/her own login active and able to flow with the program as normal.. Hold on, it's probably easier to show you.. here you go:

//an excerpt from my program.
System.out.println();

do{
System.out.println("Imput your UserID or Say 'New User' to register a New name.");
System.out.println();
System.out.println("UserID: ");
String usID=input.readLine();


if (usID.equals("New User")||(usID.equals("New user"))||(usID.equals("new user"))){


System.out.println();
System.out.println("Please imput your new UserID: ");
String NewUID=input.readLine();
System.out.println();
System.out.println("Thank you. Now Enter your new password.");
String NewUPass=input.readLine();
System.out.println();
System.out.println("Thank you. This process is complete.");
Util.skip(2);
System.out.println("Your Username is: "+NewUID);
System.out.println("And your password is: "+NewUPass);
//----------------------------------------------------------------
Util.skip(2);
System.out.println("We're sorry. This feature is currently Disabled.");
System.out.println("Please login as 'Guest' using the password 'Guest'.");
System.out.println("\t\t\t\t- Phobos Team ::");

Util.skip(3);
loop1='n';
}//end register new user.

//**********************************************************************
else if (usID.equals("dmz")||(usID.equals("Guest"))||(usID.equals("guest"))||(usID.equals(NewUID)))




The problem I'm Actually having is with the last if.. it says "Cannot find symbol variable NewUID" however, it's declared as user input by putting

String NewUID=input.readLine();

etc...


Can anyone please help? some insight? tips? =] This is my first forum post, and I'm really new to java.. I'm attending a High School computer science class.. so I'm really having to just study this by myself... However, I'll be taking the online courses in Jan. So please go easy on me! =D If it cant be done, just tell me and I'll be quiet. =] but if it can, I will Definately Appreciate the help.. =]



Thanks. Dustin Moorman.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

The problem I'm Actually having is with the last if.. it says "Cannot find symbol variable NewUID" however, it's declared as user input by putting

String NewUID=input.readLine();

etc...


The NewUID variable is declared in the body of the first "if" block. By having the declaration at this scope, it can only be accessed by the first "if" block. In the later "if" statement, it is out of scope.

If you want that variable accessed by both "if" conditions, you might want to move the declaration to a larger scope -- say to the top of the method, which will make it accessable by everything in the method.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

Welcome to JavaRanch. Please use a meaningful subject line when you post a question.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Dustin Moorman
Greenhorn

Joined: Oct 06, 2008
Posts: 2
Wow. Thank you So very much.. that did it. =D


And thanks for not tearing me up haha! =D

again. Thank you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
Originally posted by Dustin Moorman:
And thanks for not tearing me up haha! =D
That's only because I wasn't around at the time Mwaaaahaaaaaahaaaaahaaa.


By the way: if you find the String#equalsIgnoreCase method you can pass "new user" "New User" or "nEw uSeR" and they will all work without needing the || operator. But it is still dependent on spelling; "new Usher" won't work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A small question