
-----------------------------------
grasshopper
Wed Mar 10, 2004 7:15 pm

if structures with characters
-----------------------------------
heeey everyone.. i`m working on this project.. but i need help! I am making a program.. a quiz.. all i need is to do some descision structures . I was wondering if there was a a way if i can check if the user enters characters when i ask them to enter there name.. here is a bit of my code...code that applies to my question..sorry its not formatted nicely.. its bits and pieces..

String usersName;             
String upperCaseName;    


System.out.print("Please enter your name: ");     //prompt for input 
usersName = TextIO.getln();                       //read from keyboard




        if    i need help here!
        {
            upperCaseName = usersName.toUpperCase();
        }
        else
        {
            System.out.println("Please enter a valid name: ");  //prompt for input
            usersName = TextIO.getln();                         //read from keyboard
        }


i want to say 
if (usersName = char)
orrr
if (usersName= true)

something like that..that i can check what was entered..is there a way i can check if the user entered characters and then if they did, move on and if they didn`t tell them to try again?...sorry if i made this question confusing! i need to know what to put in the if 
thanks for the help!  :D

-----------------------------------
wtd
Wed Mar 10, 2004 7:46 pm


-----------------------------------
import java.lang.*;
import java.io.*;

class Test {
   public static void main(String[] args) {
      BufferedReader keyboard = new BufferedReader(
         new InputStreamReader(System.in));

      String usersName = "";

      do {
         System.out.print("Please enter your name: "); // prompt
         usersName = keyboard.readLine(); // read
         usersName = usersName.trim(); // trim leading and trailing whitespace
      } while (usersName.equals("")); // do it again if the input was empty

      // do something with usersName
   }
}

-----------------------------------
grasshopper
Wed Mar 10, 2004 8:41 pm

thanks!
-----------------------------------
heey.. thanks for your help! but that`s not actually want i needed.. however for future reference, it`s good to know!.. 

i figured out what i needed.. it`s one of those stupid questions asked.. where the code is soo simple but you can`t think of it at that moment..

-----------------------------------
da_foz
Fri Mar 19, 2004 10:16 pm


-----------------------------------
Do a search and see if you can find
SavitchIn
Its the author of the Java book I have, he wrote a whole class thing for getting input, does tons of error checking for you.  Much easier.  You call methods that only let the user input a char or a string or whatever and output an error and repromt if the input is not what you want.

-----------------------------------
grasshopper
Sun Mar 21, 2004 11:30 pm


-----------------------------------
wow i haven`t been on here in liek a week... well thank you very much!.. exactly what i needed! but..do you know what the exact title of the book is orr... because i think i found something online.. but it would be nice to have a copy of the book.. so i was wondering if i`d be able to find it in a bookstore or such.. it`d make searching easier you you had the title. thanks once again!

-----------------------------------
da_foz
Mon Mar 22, 2004 7:52 am


-----------------------------------
Here is a link to the documentation:
http://www.cis.ohio-state.edu/~wagnera/cis201/SavitchIn/SavitchIn.html

Here is a link where you can download the *.java class:
http://people.westminstercollege.edu/faculty/hhu/201/homeworks/homework1.html

Don't have time now, but I'll try to check the name of the text later.

-----------------------------------
grasshopper
Mon Mar 22, 2004 1:02 pm


-----------------------------------
heey. thanks! yeea i found the link to the documentation, when you said to search using SavitchIn.. it worked =).. 

don`t worry about the title.. just take your time

-----------------------------------
da_foz
Tue Mar 23, 2004 8:05 am


-----------------------------------
Java: An Introduction to Computer Science & Programming
Walter Savitch
Second Edition


I could not find the text, but I finally remember where to find the title.  I think there is a new edition out now, not sure.

-----------------------------------
grasshopper
Tue Mar 23, 2004 11:05 pm

coooool
-----------------------------------
okay thanks for your help!
