Computer Science Canada splitting up input |
Author: | krishon [ Thu Sep 25, 2003 6:10 pm ] |
Post subject: | splitting up input |
i need help with a particular exercise. In the question, i need to read in a users name with a space separating the first and last name (which i can do). However, i'm to split up the first and last name and store them into separate variables. That's the part i have no clue how to do.......ne help will be appreciated |
Author: | Tony [ Thu Sep 25, 2003 7:08 pm ] | ||
Post subject: | |||
cant you just use substring? Edit: new code
|
Author: | krishon [ Thu Sep 25, 2003 7:21 pm ] |
Post subject: | |
ye that's wut i thought tooo, i know to use the substring, i jsut dun't know how to see where the space is....ur idea wuz wut i thought at the start...but the only problem like i said wuz to detect the space |
Author: | rizzix [ Thu Sep 25, 2003 7:25 pm ] |
Post subject: | |
so problem solved right. i mean tony solved it for you. he detected the space and split the string. |
Author: | krishon [ Thu Sep 25, 2003 7:42 pm ] |
Post subject: | |
yah...he did thx tony ![]() |
Author: | rizzix [ Thu Sep 25, 2003 7:53 pm ] | ||
Post subject: | |||
here's an alternate way (lesser code) [wow you've got to love this language]:
works only with 1.4.x^ ( i haven't tested it ) |
Author: | krishon [ Thu Sep 25, 2003 7:54 pm ] |
Post subject: | |
its the string names [] an array (i haven't learned it yet, lol, we're on strings) |
Author: | rizzix [ Thu Sep 25, 2003 7:55 pm ] |
Post subject: | |
Yes!! ... wow you reply fast. |
Author: | Tony [ Thu Sep 25, 2003 7:55 pm ] |
Post subject: | |
![]() but I like the new .split way even more 8) oh man, JAVA pwnz ![]() |
Author: | krishon [ Thu Sep 25, 2003 7:56 pm ] |
Post subject: | |
lol, yah...bout teh fast replyin...having msn on and having it notify can help ![]() |
Author: | krishon [ Thu Sep 25, 2003 7:59 pm ] |
Post subject: | |
lol, tony if i used ur code, my teacher would know someone's helping, cuz i dunno try and catch ![]() |
Author: | krishon [ Thu Sep 25, 2003 8:02 pm ] |
Post subject: | |
hmm....while we're on the topic of java.....can someone write a tutorial about graphics...i dun't expect this if you are too busy, but it'll be great if u can write one ![]() |
Author: | Tony [ Thu Sep 25, 2003 8:03 pm ] |
Post subject: | |
how do you get terminal input then? cuz my IDE doesnt let me use input stream without try/catch block ![]() |
Author: | krishon [ Thu Sep 25, 2003 8:05 pm ] |
Post subject: | |
well our teacher taught us the GUI input....nice and ez, plus unlike turing I CAN GET THE VALUES FROM THE GUI BOX ![]() ![]() |
Author: | rizzix [ Thu Sep 25, 2003 11:33 pm ] |
Post subject: | |
so krishon, what do mean graphics... as in displaying images.. manipulating images... or GUI!! ?? ![]() |
Author: | Tony [ Thu Sep 25, 2003 11:58 pm ] |
Post subject: | |
I think he means .swing actually I wouldn't mind a good explonation of that ether ![]() |
Author: | krishon [ Fri Sep 26, 2003 5:07 pm ] |
Post subject: | |
most displaying and manipulating...my friend and i are think bout doin a fps (first person shooter) for a project....so i just wanna learn about displaying and manipulating...but wut we really need to know is how to make an environment...but yah...a tut on displayin and manipulating would be great! |
Author: | Tony [ Fri Sep 26, 2003 5:12 pm ] |
Post subject: | |
FPS? ![]() |
Author: | krishon [ Fri Sep 26, 2003 5:13 pm ] |
Post subject: | |
i know...that's y i need to start nice and ez...and way b4 we start the fp's |
Author: | krishon [ Sat Sep 27, 2003 9:12 pm ] |
Post subject: | |
tony, may u repost teh first solution u had b4 u editted it? thx |
Author: | Tony [ Sun Sep 28, 2003 1:16 am ] |
Post subject: | |
it was just some preudo code. I didnt remember the exact syntax at that moment and I edited it after I looked it up. it was basically just the text.substring(0,text.indexOf(" ")); line |
Author: | krishon [ Sun Sep 28, 2003 9:29 am ] |
Post subject: | |
kk, thx |
Author: | krishon [ Sun Sep 28, 2003 12:04 pm ] | ||
Post subject: | |||
well heres wut i have so far...it still doesn't compile correctly.... ![]()
|
Author: | rizzix [ Sun Sep 28, 2003 1:09 pm ] | ||
Post subject: | |||
woah! there's something terribly wrong here! 1: the main method is the only method that is called when ur program is executed. so to get ur program to work you have to call the other methods inside the main method, else no method is ever called and the variables fristName, lastName never do get set. 2: the structure and design is completely wrong. don't worry everyone get it wrong the first time with OOP languages. by policy i'm not allowed to do the work for you. but you'll never get it if you don't see the difference between a correctly designed code and one that is relatively incorrect. here's how i'd do it:
As you can see. you were treating the static method main as an instance method. You can't do that. Static methods cannot access (call) instance methods and variables. But instance methods can call and access static methods and variables. Since a static method cannot access an instance method you'll have to treat it as though it was not part of that object. But exists within the reach of that object. In other words, the object can call it etc.. but not the other way round. This is why you need to create an object in the static method. and call it's methods.. etc.. Just compare the classes. You'll see a couple of other errors here and there. NOTE: i haven't tested the class yet. |
Author: | krishon [ Sun Sep 28, 2003 8:31 pm ] |
Post subject: | |
aha....yea.. ![]() |
Author: | krishon [ Mon Sep 29, 2003 4:51 pm ] |
Post subject: | |
one more thing....you know in the code above where you put in result for the parameter, how come it won't work with any other things....does it only work when it says result? |
Author: | rizzix [ Mon Sep 29, 2003 5:20 pm ] |
Post subject: | |
no. you can pass any String object as an argument irrespective of the variable name. |
Author: | krishon [ Tue Sep 30, 2003 5:50 pm ] |
Post subject: | |
k, cuzi put like theName and it didn't work...so yah |
Author: | tlivingston [ Tue Sep 30, 2003 7:59 pm ] |
Post subject: | |
its cause in the notes she has it as CharAt when it should be charAt .... (little c in char)...thats the prob |
Author: | krishon [ Wed Oct 01, 2003 7:40 pm ] |
Post subject: | |
yah...stupid notes, lol |