• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A small question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please use a meaningful subject line when you post a question.
 
Dustin Moorman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow. Thank you So very much.. that did it. =D


And thanks for not tearing me up haha! =D

again. Thank you.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic