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.

Page 2 of 2 FirstFirst 12
Results 26 to 39 of 39

Thread: Program not printing anything

  1. #26
    Member
    Join Date
    Mar 2013
    Posts
    37
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    I will post my whole code again so we're all on the same page lol

    import java.util.Scanner;
     
    public class LetterDriver
    {
      public static void main(String[] args){
     
        System.out.println("Enter lines of text, type two returns in a row to end.");
        Scanner scan = new Scanner(System.in);
        String tScan= " ";
        while(tScan.length() > 0) // while the length of the line is longer than 0
        {
          tScan = scan.nextLine(); // read the next line
        }
     
      LetterProfile k = new LetterProfile();
      k.printResults();
      }
    }

    public class LetterProfile
    {
      int scoreboard[] = new int [26];
      private int index;
      private int next;
      private int largest =0;
      private int largestindex =0;
     
     public void countChars (String s)
      {
        // changes the input text to lower case letters
        s = s.toLowerCase();
        //
        char a = 'a';
        for (int i =0;i < s.length();i++)
        {
          int next = (int)s.charAt(i)-(int) a;
          if ( next<26 && next >= 0)
            scoreboard[next]++;
        }
     }
        public void scoreLine (String line)
        {
          int index = line.length();
          for (int j = 0; j<index; j++)
          {
            scoreboard[j]++;
            System.out.println(j + scoreboard[j]);
          }
        }
        public int largestLength()
        {
          int largest = 0;
          int largestindex = 0;
          for(int a = 0; a<26; a++)
          {
            if(scoreboard[a]>largest)
            largest = scoreboard[a];
            largestindex = a;
          }
          return (char)largestindex;
        }
        public int printResults()
        {
         largestLength();
         return largestLength();
        }
     }


    --- Update ---

    scoreLine is supposed to print out the letter and the number of times that letter appeared.

  2. #27
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    yes i just solved your all problem, you need to change scoreline to have it print out a table(right now it doesnt do anything), and you need to combine all the methods in LetterProfile into one new method
    this is mine

    public void runProg(){
    countChars(query);
    scoreBoard();

    }
    }
    THis is my driver,
    import java.util.Scanner;
    public class LetterDriver{
    public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String tScan = scan.next();
    LetterProfile a = new LetterProfile(tScan);
    a.runProg();
    }
    }

  3. #28
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Program not printing anything

    How does scoreboard get filled?

  4. #29
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    Quote Originally Posted by curmudgeon View Post
    How does scoreboard get filled?
    through countChars

    I used 26 of these for scoreline(mine is named scoreboard)

    System.out.println("a = " + scoreboard[0]);

    then I linked all the methods into a new method, runProg, and put in into the driver

  5. #30
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Program not printing anything

    Quote Originally Posted by MikeIsNotHere View Post
    through countChars
    And where does countChars get called with the String of interest? It is as if the original poster is thinking that the array will be filled mathemagically, and this won't happen unless he *codes* it to happen.

  6. #31
    Member
    Join Date
    Mar 2013
    Posts
    37
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    I tried to do what you suggested without seeing your LetterProfile class, but it isn't working for me.

    --- Update ---

    I don't expect the array to be filled magically. I am just very new to programming and half of what you guys are saying is greek to me.

  7. #32
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    What does the final output look like? I am still very new to java and confused on why its not printing anything. If anybody could show the final working code for the driver and class I'd very much appreciate it. Thanks!

  8. #33
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    Quote Originally Posted by MikeIsNotHere View Post
    yes i just solved your all problem, you need to change scoreline to have it print out a table(right now it doesnt do anything), and you need to combine all the methods in LetterProfile into one new method
    this is mine

    public void runProg(){
    countChars(query);
    scoreBoard();

    }
    }
    THis is my driver,
    import java.util.Scanner;
    public class LetterDriver{
    public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String tScan = scan.next();
    LetterProfile a = new LetterProfile(tScan);
    a.runProg();
    }
    }
    scoreBoard() doesn't work since it's not defined in the driver

  9. #34
    Member
    Join Date
    Mar 2013
    Posts
    37
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    Quote Originally Posted by jabdelgh View Post
    What does the final output look like? I am still very new to java and confused on why its not printing anything. If anybody could show the final working code for the driver and class I'd very much appreciate it. Thanks!
    I am still very confused as well

  10. #35
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program not printing anything

    I am still very confused as well
    I suggest that you put this code aside for a while and work on a very simple program to see how to call a method.

    Write a new class with a main() method and one other method.
    Have the main() method call the other method.
    Have the other method print out a message.
    A Very simple program. When you get that working, then we'll work on adding some features one small step at a time.
    If you don't understand my answer, don't ignore it, ask a question.

  11. The Following 2 Users Say Thank You to Norm For This Useful Post:

    kbrady481 (March 19th, 2013), MikeIsNotHere (March 19th, 2013)

  12. #36
    Member
    Join Date
    Mar 2013
    Posts
    37
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    The program is due tonight. That is why we are so persistent haha.. I really am trying in this class I've been going to tutoring and office hours. I guess programming is just not my thing...

  13. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Program not printing anything

    You need to start with something simpler and build on it and learn the techniques.
    1)How to call a method.
    2)How to pass an arg to a method
    3)How to receive a return value from a method.

    Start with 1) as I suggested in post#35.
    When that works, move to 2)
    When that works, move to 3)
    If you don't understand my answer, don't ignore it, ask a question.

  14. #38
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    I should have gotten help when I was in school now I'm on spring break :/ If you guys could debug the code then show me what was wrong I'd be forever grateful. Thanks.

  15. #39
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Program not printing anything

    Quote Originally Posted by Obliter View Post
    scoreBoard() doesn't work since it's not defined in the driver
    yeah I saw that, I made so many changes that I forgot to update other parts, lol

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 3
    Last Post: December 11th, 2012, 01:28 PM
  2. [SOLVED] Newbie, why is my program printing output twice?
    By VikingCoder in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 2nd, 2012, 07:47 PM
  3. Triangle Printing - Java Program
    By mparthiban in forum Java Programming Tutorials
    Replies: 1
    Last Post: January 5th, 2012, 10:00 AM
  4. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  5. Triangle Printing - Java Program
    By mparthiban in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: January 18th, 2010, 05:35 AM