Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: programming assignment help

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default programming assignment help

    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.
    /**
    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);
    }
    }
    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
    import 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);
    }
    and
    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];
    }
    Last edited by copeg; October 20th, 2010 at 02:44 PM. Reason: Code tags


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: programming assignment help

    For future reference, please wrap your code within the [highlight=java][/highlight] tags. Here are some tutorials to help you out with arrays and switch statements
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    The switch Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. Help with assignment
    By NPVinny in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 3rd, 2010, 05:31 PM
  2. please help me in my assignment :(
    By asdfg in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 18th, 2010, 07:59 AM
  3. need help on an assignment :(
    By gamfreak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 23rd, 2010, 04:20 PM
  4. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  5. Need help with assignment
    By TonyL in forum Loops & Control Statements
    Replies: 2
    Last Post: February 20th, 2010, 09:44 PM