Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Many companies use telephone numbers like 555-GET-FOOD so the number is easier f

ID: 3775365 • Letter: M

Question

Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: 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 = 9 Design 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-FOOD the program should display 555-438-3662 Can I get JAVASCRIPT CODE for this, not java.

Explanation / Answer

namespace TelephoneNumberTranslator
{
public partial class TelephoneNumberTranslator : Form
{
public TelephoneNumberTranslator()
{
InitializeComponent();
}


// The isValidNumber method accepts a string and returns true if it
// contains 10 digits, or false otherwise.
private bool IsValidNumber(string str)
{
const int VALID_LENGTH = 10; // Length of a valid string
bool valid = true; // Flag to indicate validity

// Check the string's length.
if (str.Length == VALID_LENGTH)
{
valid = true;
}
else
{
valid = false;
}
// Return the status
return valid;
}


// Creates Dictionary to hold values
private readonly Dictionary<int, char[]> keys =
new Dictionary<int, char[]>()
{
{1, new char[] {'1'}},
{2, new[] {'a', 'b', 'c', 'A', 'B', 'C', '2'}},
{3, new[] {'d', 'D', 'E', 'e', 'f', 'F', '3'}},
{4, new[] {'g', 'G', 'H', 'h', 'I', 'i', '4'}},
{5, new[] {'j', 'J', 'K', 'k', 'L','l', '5'}},
{6, new[] {'m', 'M', 'N', 'n', 'O','o', '6'}},
{7, new[] {'p', 'P', 'Q', 'q', 'R', 'r', 'S','s', '7'}},
{8, new[] {'t', 'T', 'U', 'u', 'V','v', '8'}},
{9, new[] {'w', 'W', 'X', 'x', 'Y', 'y', 'z', '9'}},
{0, new[] {' ', '0'}},
};

// Translates strings into numbers

public int[] Translate(string word)
{
return word.Select(c =>
keys.First(k => k.Value.Contains(c)).Key).ToArray();

}

private void numButton_Click(object sender, EventArgs e)
{


string input = numTextBox.Text;



if (IsValidNumber(input))
{


//TelephoneFormat(ref input);
MessageBox.Show(" The number is " + Translate(input)[0] + Translate(input)[1] + Translate(input)[2] + Translate(input)[3] + Translate(input)[4] + Translate(input)[5] + Translate(input)[6] + Translate(input)[7] + Translate(input)[8] + Translate(input)[9]);

}
else
{
MessageBox.Show("Invalid input");
}
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote