Hello everyone, I am taking an introduction to programming class. Due to how i schedule my classes and the course nature, i had taken the accelerated course. My second programming assignment is to write a program that converts sequences of numbers from the keyboard to text strings based on the usual multi-tap coding used with cell phones.
The professor provided a starting code which will show the character's number. The programming assignment is pretty hard for me and I really don't know where to start.
Please help me out on how to start the programming assignment. We haven't learn array yet but the professor had given us a sample code with array and switch statement code/** This program is an example of reading characters from the keyboard. It reads what ever is input and increments a count for each key read and outputs the numeric code for the key, until it gets the end of file indication, which for a UNIX system is indicated from the keyboard with d. The program then outputs the number of characters read and exits. Note the operating system echos each key hit and buffers the input until a '\n' is entered at which time the system sends the buffer including the '\n' to the program. */ class KeyboardRead { public static void main(String[] args) throws java.io.IOException { int count = 0; int nextChar = System.in.read(); while ( nextChar != -1) { count++; System.out.println(nextChar); nextChar = System.in.read(); } System.out.println("The number of characters read was: " + count); } }
andimport java.util.*; class StateMach { public static void main(String[] args){ Scanner in = new Scanner(System.in); boolean done = false; int state = 0; while (!done) { switch (state) { case 0: printStateNum(0); state = in.nextInt(); break; case 1: printStateNum(1); state = in.nextInt(); done = true; break; case 2: printStateNum(2); state = in.nextInt(); break; } } } static void printStateNum(int n){ System.out.println("in state " + n); }
public static char numToLetter(int num, int count) { char[][] code = {{'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}, {'j', 'k', 'l'}, {'m', 'n', 'o'}, {'p', 'q', 'r', 's'}, {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'}}; if (num > '1') num = num - '0'; //convert codepoint to number return code[num - 2][count - 1]; }