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

Thread: Mom with a question?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Mom with a question?

    Hi there,

    I was wondering if anyone might be able to explain or provide an example as to what the following might look like? My son is working on a minor project and he's at an impasse with some coding. I, personally, have little to no knowledge on the matter so I figured where better to get an answer than these forums.

    The question he's stuck on is:

    "Write a program that generates three random integers between 0 and 9, inclusive, and prompts the user to enter the sum of those three integers. The program will then report a success message if the user enters the correct value or a failure message otherwise."

    Any help would be much appreciated!

    ~Mom with a question


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

    Default Re: Mom with a question?

    Please read the following: http://www.javaprogrammingforums.com...e-posting.html

    Posting a homework assignment without showing effort is often construed as 'please do this for me' - which we don't do. If however, there is a specific question about code - what has been done, what is wrong - then please ask for specific help regarding this/these questions.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mom with a question?

    Oh, my apologies, I was under the understanding that my son hadn't worked out the coding problem. I'm posting the code below but, as I said, I'm not knowledgeable in this. He's unsure if its correct and is confused on how to compile it using the "cmd" prompt? Perhaps you can look it over and tell us if he's on the right track and if not what could be altered to make it work?


    Son's Code:
    class JavaE801Project1 {
        public static void main(String args[])
        {
            Random rand = new Random();
            Scanner sc = new Scanner(System.in);
            int[] numbers = new int[3];
            int min = 0, max = 9, sum = 0;
     
            for (int i=0; i<3; i++) {
                numbers[i] = rand.nextInt(max - min + 1) + min;
                sum += numbers[i];
            }
     
            System.out.println("What is " + numbers[0] + " + " + numbers[1] + " + " + numbers[2] + "?");
            int userSum = sc.nextInt();
            if (userSum == sum)
                System.out.println("Success!");
            else
                System.out.println("Incorrect. " + numbers[0] + " + " + numbers[1] + " + " + numbers[2] + " = " + sum);
        }
    }
    Last edited by helloworld922; July 1st, 2012 at 03:42 PM.

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mom with a question?

    If he can use the cmd, then he will be able to identify where his errors in the program are and he will have a better idea of what to do. I tried to compile the program, and I found 4 errors. Here's a video that might help with using the cmd: Java Programming Tutorial - 2 - Running a Java Program - YouTube.

  5. #5
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Mom with a question?

    Go to whereever the file JavaE801Project1.java is on your (/his) harddrive: that's the file you posted. "Go" means use the cmd prompt.

    Then try the commands:

    javac -cp . JavaE801Project1.java
    java -cp . JavaE801Project1

    The first command is to compile and the second runs the program. The dash-c-p-space-dot is a bit of magic that tells the java executables where they should look for resources: once you start using packages and third party libraries you will have to understand that part of the commands, but it can be taken on trust until then.

    Either or both of the commands can result in messages and errors. That's OK! If you don't understand them, post them. Likewise if the program runs but "misbehaves" at runtime - fails to acknowledge a correct answer or accepts a false one - post a description of both the actual and the intended behaviour and someone will help you figure out what is happening.

    -----

    I have only glanced at the code, but the approach looks good to me.

  6. #6
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mom with a question?

    Okay,

    So, I had him run the program last night in the 'CMD', following the same procedure that his teacher had given them for an example. We pulled four errors but I'm not sure exactly how to alter? All of them deal with finding a symbol, it looks like. I've provided a screenshot of the CMD screen below:

    javaissue.jpg

  7. #7
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mom with a question?

    Bah. The image loaded too small, so I typed it out below:

    symbol: class Random
    location: class javae801projec
    javae801project.java:4: error: cannot find symbol
    Random rand = new Random ()
    ^
    symbol: class Random
    location: class javae801projec
    javae801project.java:4: error: cannot find symbol
    Random rand = new Random ()
    ^
    symbol: class Random
    location: class javae801projec
    javae801project.java:5: error: cannot find symbol
    Scanner sc = new Scanner (System.in)
    ^
    symbol: class Random
    location: class javae801projec
    javae801project.java:4: error: cannot find symbol
    Scanner sc = new Scanner (System.in)
    ^


    It seems the symbols aren't lining up. The first one sits under the "Random" behind "new Random". The second behind the first "Random" on the next error involving it. Same goes for both scanners typed below as well.
    Last edited by TSCM411; July 3rd, 2012 at 06:25 AM. Reason: Formatting issue.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Mom with a question?

    You have to import classes in order to use them. Check out the basic tutorials: Using Package Members (The Java™ Tutorials > Learning the Java Language > Packages)

    You seem to mean well, and it's great that you're trying to help your son, but I might offer a suggestion. Programming is a lot of research, googling, and consulting the API and the tutorials to figure out what the problem is. That's a crucial part of programming, and it's really hard to teach other than to just force students to do it. So I suggest that by helping too much, you're actually hindering the learning process.

    Think of programming as building a car. During the process of building a car, you're going to encounter pieces that don't exactly line up, unfamiliar part numbers, troubleshooting when something doesn't work, and maybe becoming familiar with components you've never seen before. If your son was trying to learn how to build a car, you wouldn't help by doing all of that legwork for him- that legwork is a huge piece of building a car, maybe just as much as the actual tightening of bolts is.

    I'm using that metaphor because I don't want to come off as rude. But judging from the assignment, I'd say your son is probably in high school, so he should start becoming familiar with the process of googling a compiler error, reading through the basic tutorials, and coming to forums himself.

    The things that you're treating as outside of the realm of programming (fixing errors, basic computer know-how) are actually crucial to learning how to program. And stepping through the process of solving these problems, breaking them down into smaller problems, and basically doing everything covered in the first link Copeg gave you, is maybe even more important than actually writing code. So by trying to fix this stuff for him, you might actually be doing him a disservice.

    Just my $0.02 though.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. The Following User Says Thank You to KevinWorkman For This Useful Post:

    copeg (July 3rd, 2012)

  10. #9
    Junior Member
    Join Date
    Jul 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Mom with a question?

    Hey there,

    This is TSCM411, the son, and I took the advice I've been reading here. Went through a couple of the tutorials and then looked back to my book more intensively. The code I posted earlier was from a template that a friend said I could work my assignment over, but it seems that I did it utterly wrong. So, I started from the ground up, using a template that I've recently used to create a quiz series the teacher wanted.

    I think this is more in line with what I needed:

    import java.util.Scanner;

    public class JavaE801Proj1 {
    public static void main (String[] args) {
    //Generate three random single-digit integers between 0 and 9
    int number1 = (int)(Math.random() * 10);
    int number2 = (int)(Math.random() * 10);
    int number3 = (int)(Math.random() * 10);

    //Prompt the user to answer "What is number1 + number2 + number3?"
    System.out.print
    ("What is" + number1 + "+" + number2 + "+" + number3 + "?");
    Scanner input = new Scanner(Sytem.in);
    int answer = input.nextInt();

    //Grade the answer and display result
    if (number1 + number2 + number3 == answer)
    System.out.println("You are correct!");
    else
    System.out.println("Your answer is wrong\n" + number1 + "+" + number2 + "+"
    + number3 + "should be" + (number1 + number2 + number3));
    }
    }

  11. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Mom with a question?

    When posting code, please use the highlight tags to preserve code formatting.

    At a first glance, it seems reasonable to me. Does it compile and run how you expect it to?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #11
    Junior Member
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1
    Thanked 2 Times in 1 Post

    Default Re: Mom with a question?

    This is Andy, your son's CMIS 141 instructor. Some thoughts on this:

    1. I've stated repeatedly that I am available and encourage all questions. I"ve posted multiple telephone numbers and email addresses. I'm simply baffled that he hasn't contacted me about this.

    2. I've clearly stated, with examples of other cheaters, that posting a privately graded project is cheating and will gain a zero for the assignment. Why I found this project posted to a public forum is beyond me.

    3. Your son is in college and you're doing his homework? Really?

    I don't know who my student is who is allowing this to happen to his grade. This project is simple enough that many will look exactly alike when they're turned in, so your son's grade is safe for this one. Probably. I have what appears to be several people turning in the example from this forum. I may just give a string (not, Java forum citizens, a String, of course, but rather an array of int) of zeros for this assignment.

    Andy

    aseely1 (at) faculty.ed.umuc.edu

  13. The Following 2 Users Say Thank You to cmis141 For This Useful Post:

    copeg (July 4th, 2012), Tjstretch (July 4th, 2012)

  14. #12
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Mom with a question?

    Hi cmis141,

    This thread looks typical of what I see here. The OP (+family/friend/someone they know etc) gets encouragement, and requests to precisely describe the problem. When (or in this case, if) they do that, people weigh in with explanations of what error messages mean or ways the code can be tweaked so that the *cause* of logic errors is made manifest. But spoonfeeding teh codez is discouraged - to the point of offending posts being deleted by the moderators.

    This is about as much you can expect or hope for in a world where your students are connected to thousands of anonymous help givers.

    In that spirit (that of suggesting an approach, not giving the answer), consider:

    * teaching these kids how to read documentation. And supplying them with quality API docs. And demanding they comment their code similarly.
    * teaching and have them practice how to describe problems and ask questions.
    * actively monitoring and participating in the forums used by your students. (Even in a large class my bet would be that there are "fashions", and it would help to *suggest* useful forums.)
    * designing assignments with discussion between students and between students and their huge number of web mediated colleagues in mind. Where an assignment *must* be their own work make that absolutely clear to them. But make such assignments the exception (as they are IRL)

    I'd highlight the second point. You mention "posting a privately graded project is cheating" and what we too often see here is students unable to construct a SSCCE and, as a result, posting code they shouldn't (according to your rules), that isn't helpful (by our lights) and which they later regret (because others copy their work). How much happier we would all be if the (nontrivial and nonintuitive) skills of problem diagnosis and description were consciously taught.

    -----

    I guess there is going to be some residual tension between you (or, better, your institution and its aims) and online forums. Still, neither of us seem to be going away! Will the possibility of zero grades keep your students from asking for help from the sources that exist and are accessible? I've got my answer, but you have to arrive at your own. What I want to say about such "possibilities" being flung about is that what matters is not how justified they are, but how *effective* they will be.

    It would, perhaps, be best to recognise that we are (relatively, if you like) the "good guys". The alternatives range from the bad misinformation sites, to the ugly pay for homework ones.

    -----

    Anyway, thanks for visiting the forum! And I hope you'll stay! I'll pick up my soapbox now, and return the thread to the OP (et al, as we say academically.)

  15. The Following 2 Users Say Thank You to pbrockway2 For This Useful Post:

    copeg (July 4th, 2012), Tjstretch (July 8th, 2012)

  16. #13
    Junior Member
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1
    Thanked 2 Times in 1 Post

    Default Re: Mom with a question?

    Hi pbrockway2 and all,

    Good advice. The new world we're in has all sorts of challenges. I think of my own good ole days of turning in programs on floppies, paperclipped to line-printer code listings picked up from the central printer. And then I remember how my teachers talked about their good ole days of boxes of punch cards, and how good that was compared to the front panel toggle switches of their teachers.

    Our school, UMUC in Europe (University of Maryland University College Europe - UMUC Europe), is very much oriented on adult learners. In ten years teaching I've probably had two dozen 18-22 year old students, so I'm not always in tune with where they're coming from. Sometimes, like this one, I fear for the future of our discipline, if not the human race. But most times I just laugh, shake my head, and wonder how bad my teachers thought I was.

    Thanks for the warm welcome! Time allowing, I'll make myself at home here in your fine forum.

    andy