wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Telphone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Telphone" Watch "Telphone" New topic
Author

Telphone

Clay Bartlett
Greenhorn

Joined: Nov 28, 2004
Posts: 4
: Names of files to submit: Phone.java and TestPhone.java

Description: Using JOptionPane.showInputDialog(), prompt the user to type in a word to complete a phone number beginning with 1-800-

Output the actual phone number formatted as 1-800-nnn-nnnn in the message portion of a dialog followed by a prompt for the next word

Allow the user to enter uppercase and/or lowercase characters.

Ignore characters that don't correspond to a phone digit.

If the user types in fewer than 7 characters, process the characters entered.

If the user types in more than 7 valid characters, only process the first 7.

If the user types the word "Quit" (regardless of case), terminate the program.

The letters and digits on the telephone have the following correspondence:
ABC = 2 DEF = 3 GHI = 4 JKL = 5 MNO = 6 PRS = 7 TUV = 8 WXY = 9

Class Phone: has one private instance variable named word of type String,

has one constructor that takes a String parameter and assigns it to word,

has a method named getNumber that takes no parameters and returns a String containing

1-800-nnn-nnnn where the n's are the digits corresponding to the letters in word.

Class TestPhone: displays the first prompt dialog to the user, then repeatedly (until the user enters "quit") gets the string typed in by the user, creates a Phone object passing to the constructor the string typed in by the user, and then issues the next prompt dialog containing the message

The actual phone number is

followed by the number returned by the Phone object's getNumber() method followed on a new line by the prompt for the next string to be processed.

I am having great difficulty in writing this program any help is greatly appreciated
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Try not to be overwhelmed. Step back and find the simplest thing you can make work. Try writing TestPhone like this:

Notice what I left out for now ... no JOptionPane, no "quit", no converting letters to numbers, etc. See if you can make this single test work. If you get stuck, post some code and we'll see how you're doing. Have fun!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Clay Bartlett
Greenhorn

Joined: Nov 28, 2004
Posts: 4
Thanks for the help on the test but my biggest concern is the Telephone.java program im really lost in this language and need big time help.Any assistance is greatly appreciated.
Simon Birch
Greenhorn

Joined: Dec 26, 2003
Posts: 21
There are several tasts you need to perform to write the Phone class. In no particular order
  • Convert a letter to a number
  • Identify each letter of the entered word
  • Add each number to the actual phone number
  • Format the phone number

  • Which part of the program is causing you difficulty? Does breaking it down (e.g. like the above) help?

    You could just try breaking down each of the above until you get to writing code.
    Ernest Friedman-Hill
    author and iconoclast
    Marshal

    Joined: Jul 08, 2003
    Posts: 24187
        
      34

    Clay --

    Stan gave you a big leg-up, really, in introducing you to the concept of test-driven development. Write a tiny test, then write just the code to make it pass. Stan's test is great, but you can actually write an even simpler one:



    That's it. Now if you try to compile this, it will fail, because there's no "Telephone" class. So you can create one:



    and then the TelephoneTest will compile and run without errors! Now modify the test:



    Now it won't compile again, because Telephone doesn't have a constructor that takes a String argument. Add such a constructor, and your test passes again!

    You can then continue by calling getNumber() (which will force you to add such a method) and then by checking that getNumber() returns non-null (which forces you to make getNumber() return something) and then checking that getNumber() returns the exact same string as the constructor was passed (which forces you to add a member variable and remember the constructor argument). Subsequent tests can start checking for the 1-800 part, a little at a time, until you've got the whole problem solved, one baby step at a time.

    Now, if you actually need help compiling your programs and whatnot, the best way to get it is from your teaching assistants or a fellow student -- someone who can lean over your shoulder and see exactly what your computing environment is like. But if you need that kind of help from us, just ask. You'll need to tell us about your computer and what software you're using, of course.


    [Jess in Action][AskingGoodQuestions]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Telphone