Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 if structures with characters
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
grasshopper




PostPosted: Wed Mar 10, 2004 7:15 pm   Post subject: 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! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Mar 10, 2004 7:46 pm   Post subject: (No subject)

code:
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




PostPosted: Wed Mar 10, 2004 8:41 pm   Post subject: 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




PostPosted: Fri Mar 19, 2004 10:16 pm   Post subject: (No subject)

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




PostPosted: Sun Mar 21, 2004 11:30 pm   Post subject: (No subject)

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




PostPosted: Mon Mar 22, 2004 7:52 am   Post subject: (No subject)

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




PostPosted: Mon Mar 22, 2004 1:02 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 23, 2004 8:05 am   Post subject: (No subject)

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.
Sponsor
Sponsor
Sponsor
sponsor
grasshopper




PostPosted: Tue Mar 23, 2004 11:05 pm   Post subject: coooool

okay thanks for your help!
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: