Java 旨在将短语转换为电话号码的学术课程
所以我必须写这个程序,它想让我读一个短语,比如GET-LOAN,然后把它作为电话号码输出。作为练习,我能够编写一个程序,使用while循环中的嵌套switch语句读取字母并输出每个字母的数字。我正在使用一个GUI输出,只需要将其设置为可以读入短语,使用im假设某种方法,以及将switch语句应用于字符串而不是char的方法 任何建议都将不胜感激 这是密码Java 旨在将短语转换为电话号码的学术课程,java,Java,所以我必须写这个程序,它想让我读一个短语,比如GET-LOAN,然后把它作为电话号码输出。作为练习,我能够编写一个程序,使用while循环中的嵌套switch语句读取字母并输出每个字母的数字。我正在使用一个GUI输出,只需要将其设置为可以读入短语,使用im假设某种方法,以及将switch语句应用于字符串而不是char的方法 任何建议都将不胜感激 这是密码 import java.util.*; import javax.swing.JOptionPane; public class telep
import java.util.*;
import javax.swing.JOptionPane;
public class telephone
{
// instance variables - replace the example below with your own
public static void main(String[]args)
{
//variables
String phrase;
String inputMessage;
String inputString;
String outputMessage;
inputMessage = "Program to convert uppercase "
+"letters to their corresponding "
+"telephone digits. /n"
+"To stop the program enter #./n"
+"Enter a letter:";
inputString =
JOptionPane.showInputDialog(inputMessage);
phrase = inputString.charAt(0);
while (phrase.length() == 8 )
{
outputMessage = "The Phrase you entered is: "
+ phrase + "/n"
+ "The corresponding telephone "
+"digit is: ";
if (phrase) >= 'A' && letter <= 'Z')
{
switch (phrase.charAt(0))
{
case 'A':
case 'B':
case 'C':
outputMessage = outputMessage
+ "2";
break;
case 'D':
case 'E':
case 'F':
outputMessage = outputMessage
+ "3";
break;
case 'G':
case 'H':
case 'I':
outputMessage = outputMessage
+ "4";
break;
case 'J':
case 'K':
case 'L':
outputMessage = outputMessage
+ "5";
break;
case 'M':
case 'N':
case 'O':
outputMessage = outputMessage
+ "6";
break;
case 'P':
case 'Q':
case 'R':
case 'S':
outputMessage = outputMessage
+ "7";
break;
case 'T':
case 'U':
case 'V':
outputMessage = outputMessage
+ "8";
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
outputMessage = outputMessage
+ "9";
}// End of switch
}else{
outputMessage = outputMessage + "Invalid input";
}
JOptionPane.showMessageDialog(null, outputMessage, "Telephone Digit",
JOptionPane.PLAIN_MESSAGE);
InputMessage = "Enter another upeercase letter "
+ "to find its correspoonding "
+ "telphone digit./n"
+ "To stop the program enter #./n"
+ "Enter a letter:";
inputString = JoptionPane.showInputDialog(inputMessage);
phrase = inputString;
}
System.exit(0);
}
}
import java.util.*;
导入javax.swing.JOptionPane;
公共电话
{
//实例变量-将下面的示例替换为您自己的
公共静态void main(字符串[]args)
{
//变数
字符串短语;
字符串输入消息;
字符串输入字符串;
字符串输出消息;
inputMessage=“转换大写字母的程序”
+“给他们相应的人的信”
+“电话号码。/n”
+“要停止程序,请输入#。/n”
+“输入一个字母:”;
inputString=
showInputDialog(inputMessage);
短语=inputString.charAt(0);
while(phrase.length()==8)
{
outputMessage=“您输入的短语是:”
+短语+“/n”
+“相应的电话”
+“数字是:”;
如果(短语)>='A'&&letter您在这里问了几个问题。请编辑您的问题,只关注其中一个。一些一般性建议:您的代码。创建一个将字符转换为数字的方法。创建一个将字符串转换为数字的方法,使用第一个方法。创建一个处理获取用户输入的方法,包括处理错误输入。等等。