Results 1 to 4 of 4
  1. #1
    Johnny2009 is offline Member
    Join Date
    Nov 2011
    Posts
    22
    Rep Power
    0

    Default Stuck, need help please

    Hi, i'm doing this program, and im currently stuck.

    For this assignment you are to print a table that gives frequencies of the digits 0 through 9 in a typed English text. To keep things simple and concrete, your job will be to print the digit frequencies for multiple lines of text you enter from the keyboard. More specifically, you program should continue entering lines of text until you type two Returns in a row. Here is some sample interaction:


    Enter lines of text. Type two Returns in a row to end
    [DrJava Input Box]124 people applied for the job 007
    [DrJava Input Box]in the new Bond movie. But only 94 or 96 out of the 124 were really possible
    [DrJava Input Box]

    Digit Frequencies
    -----------------------------
    0 2
    -----------------------------
    1 2
    -----------------------------
    2 2
    -----------------------------
    3 0
    -----------------------------
    4 3
    -----------------------------
    5 0
    -----------------------------
    6 1
    -----------------------------
    7 1
    -----------------------------
    8 0
    -----------------------------
    9 2
    -----------------------------

    Tips/Further Qualifications

    Use the input style that appears in Program Backwards in Chapter 7. (It accepts multiple lines of text).
    You MUST do this assignment with two classes: a driver, which includes main and handles the input, and is called DigitDriver; and a principal processing class, called DigitCounter. Objects in the DigitCounter class are responsible for handling the character processing. DigitCounter must have an array instance variable which acts as a scoreboard, tallying digits when they are encountered in the entered text.
    Remember that if someDigit is a char variable that holds a digit, then (someDigit-'0') gives the numerical position of someDigit among all digits. Thus if someDigit holds a 4, then (someDigit - '0') = 4. Use this fact to drive your array indexing.
    Use the static method isDigit from the Character class to determine when you've come across a digit.
    Your DigitCounter code must include and make use of a method called processString, which is passed a string as a parameter - a typed line of input - and which is responsible for finding and then tallying occurrences of digits in the parameter.
    Be sure to comment your code.


    This is what i have so far
    main

    Java Code:
    import java.util.Scanner;
    
    public class DigitDriver{
      public static void main(String[] args){
        String[] stringArray = new String[100]; // setting string
        
        System.out.println("Enter text. Type two Returns in a row to end"); // Screen promt
        Scanner scan = new Scanner(System.in); // enable input from keyboard
        int pos = 0;
        String d = " ";
        while(d.length()>0){
          d=scan.nextLine();
          stringArray[pos]=d;
          pos++;
        } // get input from keyboard
        
        DigitCounter myDigit = new DigitCounter(countArray);
        countArray.processString(); 
        
        System.out.println("Digit Frequencies");
        for(int i=0; i<=9; i++){
          System.out.println("-------------");
          System.out.println(i + " " + countArray[i]);
        } // print the table
      }
    }
    and here's the class

    Java Code:
    public class DigitCounter{
      char[] d;
      private String digit;
      
      public DigitCounter(char d){
         this.d = new someDigit[digit];
         
      }
        
        
      
    
      public String processString(String digit){
        
        for(int j=0; j<=9; j++){
          someDigit[j]=0;
        }
        for(int k=0; k<someDigit.length(); k++){
          if(Character.isDigit(someDigit.charAt(k))){
           
            someDigit[digit]++;
      return digit;}
       } 
      }
    I'm stuck and I'm not sure if what I have is even right or on the right path. Help would be great, Thanks

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: Stuck, need help please

    Search this forum (top right corner) for a thread titled "digit counter"; this problem was posted (and solved) here before.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Johnny2009 is offline Member
    Join Date
    Nov 2011
    Posts
    22
    Rep Power
    0

    Default Re: Stuck, need help please

    I saw the thread, but I didn't see how it was solved. There were still errors.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Stuck, need help please

    Oh boo hoo!

    Nobody posted perfect code that you could copy. I'm sure someone (probably Jos) offered plenty of suggestions and help that would allow you to solve the problem on your own. Any code that was posted might partially solve your problem. It would still be upto you to take that code and rework it so that it did fully solve your problem. Remember it is your work not ours.

Similar Threads

  1. Really stuck need help
    By B_Tank88 in forum New To Java
    Replies: 45
    Last Post: 07-18-2011, 07:52 PM
  2. I'm stuck help!!!
    By nobody58 in forum Advanced Java
    Replies: 2
    Last Post: 03-18-2010, 02:52 PM
  3. Stuck in sea
    By programmer_007 in forum JDBC
    Replies: 1
    Last Post: 09-17-2009, 04:00 AM
  4. really stuck now..
    By shongo in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2008, 02:56 AM
  5. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 02:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •