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 10 of 10

Thread: Completely New to Java/Netbeans

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Completely New to Java/Netbeans

    So I'm taking a class requiring the use of Netbeans which I've never touched before. Never had any java programming experience either. My instructor has already said that if you aren't familiar with Java already that this class will be very difficult....

    That said I'm NOT looking for someone to do my homework. My problem is that I understand some of the concepts of what's required but not how to code it. The reading ends up meaning nothing to me and I seem to get maybe one fuzzy concept out of an entire chapter of reading. So in other words "help".

    My assignment is as follows:
    • Create a console program that prompts the user to enter the name and address of their employer and position they hold or the name and address of their favorite restaurant and their favorite meal.
    • Display this information on the screen, each on a separate line.
    • Run your modified program and take a screenshot of the results.

    Here's what I understand from this:
    - a scanner would have to be loaded to allow user input and should look something like this:
    1 // Fig. 2.7: Addition.java
    2 // Addition program that displays the sum of two numbers.
    3 import java.util.Scanner; // program uses class Scanner
    4
    5 public class Addition
    6 {
    7 // main method begins execution of Java application
    8 public static void main( String[] args )


    The text I have (Java How to Program: Late Objects Version, Eighth Edition) only seems to point out how to do this with int values. I'm not finding anything that instructs me on how to code when I want to use characters other than numbers (though I think I'm referring to strings, I'm not sure).

    I'm fairly confident if I could properly code the scanner that I could manage to get the required inputs (name & address of employer etc...) figured out. I'm also in the dark about how to get the outputs to print to multiple lines but I think I get the general idea of printing (system.out.print ?).


    If it sounds horrible I apologize but my brain is fried and I just spent 5 hours listening to live chats that led nowhere and reading a book that might as well be written in Japanese if you're a newbie to Java code.


    Any and all help will be greatly appreciated but you're gonna have to dumb it down for me.



    Thanks in advance.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,290
    My Mood
    Mellow
    Thanks
    191
    Thanked 668 Times in 655 Posts

    Default Re: Completely New to Java/Netbeans

    Welcome to the forum!

    Finish the code you've started, and post it correctly when you've gotten it working. From there we can show you how to ask for a String and send it back to the screen.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Completely New to Java/Netbeans

    Hi Greg,

    I appreciate your quick reply but you're assuming that I know how to finish the code . And the answer is ...I don't. Also what do you mean by post it correctly? If I could get the darn thing working I wouldn't be so stressed out right now...lol

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,307
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Completely New to Java/Netbeans

    Also what do you mean by post it correctly?
    There is a post at the top of every form entitled Welcome! If it's your first time here, please read and follow these rules and guidelines. that has useful information for newcomers.

    As to your problem, I recommend reading the API for the Scanner class. It describes how this class can be used in different contexts. Play around with its methods to see which works best to meet the needs of you requirements.

  5. The Following User Says Thank You to copeg For This Useful Post:

    Sonny1975 (February 15th, 2014)

  6. #5
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Completely New to Java/Netbeans

    I suggest looking here:
    Scanner (Java Platform SE 7 )

    You are on the right track with system.out.print, there is another method similar to print except it prints on a line and moves the cursor to the next line. As for when you post code you should use make sure it is within code tags.
    so it looks like this

    EDIT: copeg beat me to it

  7. The Following User Says Thank You to KucerakJM For This Useful Post:

    Sonny1975 (February 15th, 2014)

  8. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,290
    My Mood
    Mellow
    Thanks
    191
    Thanked 668 Times in 655 Posts

    Default Re: Completely New to Java/Netbeans

    . . . you're assuming that I know how to finish the code . And the answer is ...I don't.
    Oh, I thought you were copying something out of a book labeled Fig. 2.7.

    I have "How to Program," 9th Edition, and Fig. 2.7 clearly has the full source code that accepts two integers from the user, adds them, and outputs the results. That's the program I suggested you finish, offering to help you modify it to suit your needs when done. If you're unable to type that program into Netbeans successfully so that it compiles and runs, then I'm not sure what we can do for you.

  9. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Completely New to Java/Netbeans

    Hi Greg,

    I understand what you're saying now. I didn't think you wanted me to just finish the code straight from the book because it works for integers but not scripts as it is (right?)? I can however finish putting it as is into netbeans and will brush up on how to properly post code. Also wanna check out the link mentioned in the above thread traffic. Sorry for the confusion, I truly appreciate the help and should have the follow up post done soon (first thing in the morning at the latest).


    Thanks

    --- Update ---

    Ok spent some time hunting for other resources and between all of the info here plus the new stuff I found I think I'm close. Here's what I have so far. The only thing that I'm noticing is that I can't figure out how to have the user input all the information first before the application spits it back out. So here's what I have:

     // my pathetic attempt at coding 
    import java.util.Scanner;
     
    class week1ip{
        public static void main (String args []) {
            Scanner employrestaurant = new Scanner (System.in);
            System.out.println ("Please enter the name of your employer or name and address of your favorite restaurant");
            System.out.println (employrestaurant.nextLine ());
            Scanner positionmeal = new Scanner (System.in);
            System.out.println ("Please enter your job position or the name of your favorite meal");
            System.out.println (positionmeal.nextLine ());
        }
     
    }

    What I was actually hoping for would have flowed like this:
    User is prompted with: Please enter the name of your employer or name and address of your favorite restaurant
    User is prompted with: Please enter your job position or the name of your favorite meal
    Input information is then output on separate lines.

    I've also tried to appropriately post code per the link referred to above (I'm dead tired so please be patient if I didn't get something quite right with that).

    Comments, advice and corrections are welcome and appreciated


    Thanks

  10. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,290
    My Mood
    Mellow
    Thanks
    191
    Thanked 668 Times in 655 Posts

    Default Re: Completely New to Java/Netbeans

    Look how far you've come. Excellent!

    You only need one Scanner object that can be used multiple times. This is an early example of the use and usefulness of objects. So give your Scanner object a more generic, multi-purpose name, something like 'input'. If you haven't, you should check out the Scanner API page to see all of the methods you can call on a Scanner object. You don't have to memorize them, but you should have an appreciation for the wide variety of methods available.

    As for what your program does versus what you had in mind, that's totally under your control. you might rewrite your code, adding the flow you described at the end of your post, and then fill in with the code from above or new, as needed. Something like:
    // the best program I've ever written by myself 
    import java.util.Scanner;
     
    public class StrongLip
    {
        public static void main( String[] args )
        {
        	// create a multi-purpose Scanner object
     
        	// User is prompted with: Please enter the name of your employer
        	// or name and address of your favorite restaurant
     
     
        	// User is prompted with: Please enter your job position 
        	// or the name of your favorite meal
     
     
        	// Input information is then output on separate lines.
     
     
        } // end method main()
     
    } // end class StrongLip
    Note that Java class names begin with capital letters and while "String args[]" is acceptable, "String[] args" is preferred.

    Here's a life lesson, not a Java lesson. A large part of being successful at anything is attitude. If you want to be a failure, tell everyone that you're a failure. Go out of your way to appear helpless and pathetic. Have T-shirts made that say, "I suck," "I am a failure at everything I try," and "I will never learn to program," and it will all come true. People will help you be successful at being a failure, because that's what they think you want. OR, you can project the opposite attitude, not arrogantly or unreasonably, but in a way that projects confidence in yourself and your ability to succeed; always while making your best effort, proud of it, and owning it completely. Perhaps that's what you meant by taking a risk earlier. You decide which approach is better for you, but we're not interested in helping people fail. If that's your choice, take it somewhere else.

    Keep coding, and be well.

  11. #9
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Completely New to Java/Netbeans

    Thanks for the Java information. Up until now I had assumed that such // text was really just the equivalent of adding notes for the sake of those reading your coding. If I understand correctly you're implying that actual instructional code can be achieved that way...I'll play with it more later.

    As for "String args []" vs. "String[] args" is there any specific reason that the latter is preferred?

    As for your life lesson, I'm going to assume that my "// my pathetic attempt at coding" line is what caused your mini-rant. The reality is that while I do take some things very seriously, I've never been someone that was unable to poke fun at myself. While you may not agree with my personality, sense of humor, or (highly developed) sense of sarcasm there is something you should realize before venturing into life lessons on my behalf: your significance to me begins and ends with Java. That said, I'll admit that my first reaction was to sink to a much lower level then what I've just displayed. I had a passing thought of coming back here and writing out important bits of my history, what I've achieved, who I've helped, things I've done for myself, my family, my country etc... Then a very simple reality kicked in, even if all that irrelevant information about myself somehow swayed your view, what would it matter? I don't want your respect. I don't care what you (or most people besides my wife and a few very close friends and family members) think of me. Your endorsement or rejection of my projected attitude is not a prerequisite for anything that matters to me, nor does it remotely come close to gauging my successes or failures in life.

    Now I understand that I'll probably get booted from the forum for back-talking a moderator, but with admittedly luke-warm intentions I'll try to present a slightly different view. My life lesson for you ( I mean since we're apparently slinging such stuff around willy-nilly): Never assume that the knowledge and experiences you've accumulated about life qualify you to teach anyone on the subject. While nothing you said in your life lesson is technically wrong (at least in my opinion) all you accomplished (again just my opinion) was to make yourself seem passive-aggressive, overbearing, and preachy (not sure if that's really a word but you get the drift). On the topic of life the wisest people I've ever known were the first ones to admit that ultimately they don't know jack-sh...

    (wrapping this up soon...I promise) Now you spoke in plural toward the end of the lesson. I'm going to assume that you (perhaps rightly) feel that you speak for the large (if not total) portion of your members here. If that's true then you're correct in at least one regard - I could never fit into a group that would so smugly respond to an earnest request for help, even if it was framed in (admittedly bad) humor. Seems like even if I'm not banned for life all I'd accomplish here is either drawing ridicule or more blessed "oil & water" interactions with you. So perhaps you're right that I should be taking it somewhere else, just flawed in your reasoning as to why.

    Hugs and kisses on a very special Post-Valentine's Day....here endeth the lesson.

  12. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,290
    My Mood
    Mellow
    Thanks
    191
    Thanked 668 Times in 655 Posts

    Default Re: Completely New to Java/Netbeans

    // comments can be used for anything you'd like
    Those in my example are too wordy and probably wouldn't make the final version of the program, but they're fine to document your ideas on how the program should flow, what goes where, etc.

    Array notation preference, found here:
    You can also place the brackets after the array's name:

    // this form is discouraged
    float anArrayOfFloats[];

    However, convention discourages this form; the brackets identify the array type and should appear with the type designation.
    Though not stated specifically, I believe the preferred notation is considered more clear, associating the type with the array.

    And I should have added: Use Fig 2.7 in your book as an example of how to use the Scanner object tot assign the results to variables which will change.

    Advice and opinions, anything said by anyone, especially by people you barely know, can be rejected or accepted anyway you choose. I think kisses and hugs at this point are a bit much.

Similar Threads

  1. [SOLVED] Completely clueless as to how to do this assignment.
    By Disruption in forum What's Wrong With My Code?
    Replies: 15
    Last Post: November 11th, 2013, 09:39 AM
  2. Help!, newbie, interested in Java, Very simple code, completely stuck!
    By munkybunky in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 30th, 2011, 07:25 AM
  3. Creating a Gun in Java, I'm completely lost.
    By Pryde in forum Java Theory & Questions
    Replies: 1
    Last Post: March 21st, 2011, 08:13 AM
  4. School java project, completely stuck
    By John1818 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 18th, 2010, 03:10 AM
  5. Completely New to Java
    By slimshadie in forum Java Theory & Questions
    Replies: 7
    Last Post: September 6th, 2009, 01:55 PM