: 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
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
Joined: Nov 28, 2004
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.
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.