Results 1 to 18 of 18
  1. #1
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default Need Help With VERY Simple Program -- Newbie!!!

    Hey all,

    I am not a Java programmer and as part of a job application I'm being asked to do a simple (not!) Java program. Can anyone help me with the following exercise? Thanks!

    You are to create a console application that accepts exactly one command-line argument. If it doesn’t receive the argument, the application must display an error message and exit. The application must parse the text input and output the number of times each letter of the alphabet occurs in the text. Case sensitivity is not required.

    For example, if the command-line argument is “baaad” the displayed result must be:

    There are 3 A's
    There are 1 B's
    There are 0 C's
    There are 1 D's
    There are 0 E's
    There are 0 F's
    etc...

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default hhhmmm... probably not

    I do appriciate your honesty... but nobody here is going to give you code so you can pass it off as your own and get a job where you need java programming skills that you don't have. If you want to post your code and ask questions about doubts/problems, then there is plenty of help to be given.

    With that said, some suggestions:


    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    somethingfast, study loops. Besides that... if you can't do this, why even bother applying for a programming job?
    I die a little on the inside...
    Every time I get shot.

  4. #4
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    Actually, the job is not for Java. It's for a .NET training program but you have to demonstrate programming skills in narrow range of options (Java, VB, and C++), none of which I have. My background is in SQL/Access/SAP. I REALLY need this training which translates into a job. I totally understand your position and am only asking because I'm desperate and I know that I won't actually be programming in Java. I would be eternally grateful for help :o

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    At least, did you put some effort on this. CJSLMAN give a link for the tutorial. Go to that tutorial and search on the loops, first of all. And try to find number of each characters in a string as you said. Just forget all command lines arguments.

    Try something first of all lol. :)

  6. #6
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    I'll give it a shot. Thanks guys. The tutorial didn't have a "loops" section that I could find. This should be like 20 lines of code max, right?

  7. #7
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    One more question as I begin to tackle this. I assume by loop you mean an if-then or for statement is involved? And what is the mechanism by which the characters in the word entered are counted and converted to integer values for output? I REALLY appreciate your tips/help!

  8. #8
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    I'm going to tell you what you need to use to do this but you have to figure out how to get it work.

    The String api contains a charAt() method(or possibly toCharArray() ) ;
    use a for loop to iterate through your word.
    an int counter variable for each letter.

    Now that you've been given that write up some code and post it if you get stuck.

    P.S. ya your looking at about 20 lines. The loop logic will be the majority of your code.

  9. #9
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    ^ you rock! thanks, i will put together something with spit and duct tape and post back here lol

  10. #10
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Tutorial loop section

    It's in the "Control Flow" section of the tutorials:

    Control Flow Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    Here you can find the if-else, while loop, for loop, etc

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  11. #11
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    I appreciate all the help, folks. Can you tell me if I'm on the right track with this start to get the word and determine length of word? Thanks...

    public class CountWordLetters {
    public static void main(String[] args) {
    String InputWord = JOptionPane.showInputDialog("Please enter a string: ");
    int len = InputWord.length();
    char[] tempCharArray = new char[len];
    char[] charArray = new char[len];


    for (int i = 0; i < len; i++) {
    tempCharArray[i] = InputWord.charAt(i);
    }

  12. #12
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Is it working?

    • Does it compile?
    • If yes, does it run?
    • If yes, does it produce the expected output ?


    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  13. #13
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    I don't have any ability to compile unless there is something on the average Windows desktop that I'm unaware of.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by somethingfast View Post
    I don't have any ability to compile unless there is something on the average Windows desktop that I'm unaware of.
    Amazing, you don't have install Java(JDK version) in your machine? Are you working on Notepad that above code?

  15. #15
    somethingfast is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    yeah, just notepad

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Either go to the Java download page and download the JDK or give up. Simple as that.

  17. #17
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Amazing...

    I really don't believe it ...
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by somethingfast View Post
    yeah, just notepad
    First of all, download the latest JDK version and install it in your PC. What the point that you are going to test a Java application, since even you don't have setup the required environment in your PC.

Similar Threads

  1. Stuck - simple program
    By dirtycash in forum New To Java
    Replies: 4
    Last Post: 11-24-2008, 07:44 PM
  2. Not able to debug simple hello world program
    By amit123solanki in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 03:41 PM
  3. Simple newbie problem: import 3rd party jar
    By jodyflorian in forum Eclipse
    Replies: 5
    Last Post: 05-30-2008, 04:02 AM
  4. help with simple program in java
    By katie in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 PM
  5. help with simple java program
    By leonard in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 09:40 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
  •