A, B, and C = 2
D, E, and F = 3
G, H, and I = 4
J, K, and L = 5
M, N, and O = 6
P, Q, R, and S = 7
T, U, and V = 8
W, X, Y, and Z = 0
Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The program should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-GOOD the application should display 555-438-3663.
import javax.swing.JOptionPane;
public class Telephone
{
public static void main(String[] args)
{
String input;
int phoneNum; //to hold telephone number
int [] letter; // List variables
int [] number; // that you will be using
// in the program.
/*****************************************************************/
//------------------Input the Data---------------------------
input = JOptionPane.showInputDialog("Enter a XXX-XXX-XXXX Telephone Number with Letters or Numbers: ");
phoneNum = input();
I know that my code is wrong. I am having trouble figuring out how to get the input from the JOptionPane to be able to use an array. I think an array is the best was to do this, but I am also unsure if I should be using one array for letter and another for numbers. I just want to make sure that I am on the right track, and a little help in the right direction getting from the JOptionPane to the array would be appreciated.
My problem is that every example I can find in my textbook and online uses the system.out.prntln method and I am struggling to use the JOptionPane method...which is required in the assignment.

New Topic/Question
Reply




MultiQuote







|