Results 1 to 11 of 11
- 10-29-2010, 09:00 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
- 10-29-2010, 09:11 PM #2
Why must you have 3 methods?
Sincerely, Joshua Green
Please REP if I help :)
- 10-29-2010, 09:14 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
I'm not sure the reasoning, probably since we are just starting with the stringtokenizer.
This is the exact question I was given:
1. Write a class that uses the StringTokenizer class to identify
the parts of a phone number. Assume that the format of the phone
number is (nnn) nnn-nnnn. Example (860) 222-3344. The class should
have at least three public methods: one returning the area code,
one returning the exchange and one returning the extension.
- 10-29-2010, 09:21 PM #4
Do you know how to set up the 3 methods at least? I'm not sure how much you already know about Java. Also, posting some code you already have would help a lot.
Sincerely, Joshua Green
Please REP if I help :)
- 10-29-2010, 09:24 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
I just really have no clue how to write it. I'm starting at ground zero trying to figure it out.
- 10-29-2010, 09:27 PM #6
This will help get you started with writing the methods: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
I really don't think we can help until you have some sort of code posted that we can look at.Sincerely, Joshua Green
Please REP if I help :)
- 10-29-2010, 09:35 PM #7
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Something like :
StringTokenizer tokenizer = StringTokenizer("() -");
String areaCode = tokenizer.nextToken();
String exchange = tokenizer.nextToken();
String extension = tokenizer.nextToken();
but creating a class for each areacode exchange and extension, so it can be used in other java applications.
- 10-29-2010, 09:44 PM #8
Here is something to get you started. I've made comments in the code for you to take a look at to make sure you understand each part.
Java Code:import java.util.StringTokenizer; public class tokens { public static void main(String[] args) { String phone = "(555) 454-3456"; // The phone number. String areaCode = getAreaCode(phone); // Gets the area code from a method. System.out.print(areaCode); // Prints just the area code to the screen. } public static String getAreaCode(String phone) { // Creates tokenizer for the phone number that grabs // anything in between parenthesis (). Which is what // we want. StringTokenizer areaCode = new StringTokenizer(phone, "()"); return areaCode.nextToken(); // Returns just the area code in // between the parenthesis. } }Sincerely, Joshua Green
Please REP if I help :)
- 10-29-2010, 09:49 PM #9
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
hey thanks a lot, that really got the ball rolling!
- 11-14-2011, 01:17 AM #10
Member
- Join Date
- Nov 2011
- Posts
- 15
- Rep Power
- 0
Re: Phone number stringtokenizer problem
hi i have to write exactly the same class and i'm having a lot of trouble
can someone explain to me how should i do it ?
-
Re: Phone number stringtokenizer problem
Please don't hijack someone else's old thread. Instead go to the New to Java forum and start your own new thread where you can ask this question. Provide pertinent details such as your code and your exact problems including any and all error messages.
And shoot, the answer to the fellow's question is already posted in this thread!
Locking.
Similar Threads
-
number problem
By click66 in forum New To JavaReplies: 7Last Post: 10-11-2010, 03:27 PM -
Phone number Program ..
By Sary in forum New To JavaReplies: 9Last Post: 03-17-2010, 07:15 PM -
Problem with delim in StringTokenizer
By acp26b in forum New To JavaReplies: 2Last Post: 01-15-2009, 02:44 AM -
[SOLVED] Problem hadling number(money) > 214,74,83,647.99
By playwin2 in forum New To JavaReplies: 2Last Post: 10-14-2008, 09:32 PM -
Menu on phone number option of a list
By Poonam in forum CLDC and MIDPReplies: 7Last Post: 01-31-2008, 01:42 PM


LinkBack URL
About LinkBacks


Bookmarks