Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Question First ever Java Program: HELP

    If you want to get straight to the problem, just ignore this paragraph, it's not really important, but before I continue, I just want to say that I'm a newbie in pretty much every aspect of programming, so bear with me. I have 0 previous experience (I'm only 14) with any language, and I'm learning Java more for fun than for any actual practical purpose. Java may not be the best for a newbie, but I have already invested quite a few hours, so I'll try to push on for now. I'm also new to forums, so sorry if I'm breaking any rules (written or unwritten) by posting here. I'm not really a hardcore geek, so I'd sort of appreciate if you guys used layman's terms as much as possible (though I'd love to learn some new terms, so an explanation would be fine).

    OK, if you weren't completely disgusted/repelled by the above paragraph, let's get on to the questions. I'm learning Java with Stanford's free course online (Stanford School of Engineering - Stanford Engineering Everywhere). Mehran Sahami is a great teacher, but oftentimes he makes it look too easy in the lectures and then I get to the actual programming and my brain goes blank. After fiddling with Karel the Robot, I'm finally on to my first Java problem and can't figure it out. He're's the PDF (http://see.stanford.edu/materials/ic...imple-java.pdf). There are 6 problems, I'm only on the first!!! Eeek!

    Questions:
    1. How do I centre the pyramid at the bottom if 0,0 is at the top left corner? If I resize the window, it should still stay centred, I think.
    2. What is wrong with this:
    Java Code:
    for (int i = BRICKS_IN_BASE, i > 0, i--) {
    			add(brick);
    		}
    It says there's a bug, but I can't see it for the life of me.
    Elsewhere there's this:
    Java Code:
    private static final int BRICKS_IN_BASE = 14;
    but Eclipse doesn't seem to recognise that the two BRICKS_IN_BASE are the same constant integer.
    3. This is kind of related to Question 1, but how do you put a brick at the bottom of the window to start off the pyramid, and then how would you put down bricks in relation to that brick?

    I hope my math skills aren't to blame. I am above average in class in Math, but it's definitely not CS standard. I also hope I don't sound too clueless, but I really am a newbie, and any help would be appreciated even if it's just for one of these questions.

    Hope I didn't waste anybody's time with this post/rant, but I kind of need help. I'd like to finish this course, but I guess if I don't I could just take a proper CS course when I get to university.

    Thanks in advance,
    Anonymous_Muggle

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

    Default Re: First ever Java Program: HELP

    Quote Originally Posted by Anonymous_Muggle View Post
    ... I just want to say that I'm a newbie in pretty much every aspect of programming, so bear with me. I have 0 previous experience (I'm only 14) with any language, and I'm learning Java more for fun than for any actual practical purpose. Java may not be the best for a newbie, but I have already invested quite a few hours, so I'll try to push on for now. I'm also new to forums...
    Let me start by welcoming you to the java-forums.org!


    2. What is wrong with this:
    Java Code:
    for (int i = BRICKS_IN_BASE, i > 0, i--) {
    			add(brick);
    		}
    It says there's a bug, but I can't see it for the life of me.
    For future reference, post the actual error messages, if any, that you've received. As for the bug, remember that compilers are very picky and will complain for any spelling, capitalization or symbol error, any. And this is good since a program will do anything you tell it to, you don't want to try to run a program that doesn't make sense. Your problem is that you're confusing commas with semicolons. Check an example of a for loop and you'll see exactly what I mean.


    Elsewhere there's this:
    Java Code:
    private static final int BRICKS_IN_BASE = 14;
    but Eclipse doesn't seem to recognise that the two BRICKS_IN_BASE are the same constant integer.
    Again, what is the exact error message? Are you trying to re-declare the BRICKS_IN_BASE constant? I'm not sure.


    3. This is kind of related to Question 1, but how do you put a brick at the bottom of the window to start off the pyramid, and then how would you put down bricks in relation to that brick?
    I haven't clicked on your links (many of us here don't do that, so you'll want your questions here to be complete as possible but not overwhelming), but console programs start printing at the top and then print the next lines sequentially down. So you'll want to figure out the math involved on paper first so that your program will do this. The key is to try something anything and to adjust and play with your code to see if you can tweak the result to what you want. The more you play with it, the better you get at it.

    Again, best of luck with your Java education and welcome to our corner of the Java forum world!

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: First ever Java Program: HELP

    remember that compilers are very picky and will complain for any spelling, capitalization or symbol error
    That goes for missing underscores as well: BRICKS_IN_BASE the compiler will like, BRICKS IN BASE it will not.

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

    Default Re: First ever Java Program: HELP

    Quote Originally Posted by pbrockway2 View Post
    That goes for missing underscores as well: BRICKS_IN_BASE the compiler will like, BRICKS IN BASE it will not.
    Peter, I'm not sure that they are missing here. They look like they are, and I was going to mention it, but copy and paste the offending code, and you might see underscores. I know that I do.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: First ever Java Program: HELP

    Ah! OK. Another victory for the forum's code highlighting CSS! I did wonder why you didn't mention it...

  6. #6
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: First ever Java Program: HELP

    Thanks for the help guys, I can't believe I didn't see it before, because I must have compared my for loop with one on the internet at least ten times, and every time it seemed right. The Graphics Problem is still quite hard (I think they put the hard ones first) so I'll do a Math Problem first, and get back to this later. I'll definitely try to write it on paper first.

    Anyway, just want to say thanks, this forum is pretty great in terms of helpfulness!
    Anonymous_Muggle

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

    Default Re: First ever Java Program: HELP

    Glad you're moving forward! Please let us know how it goes, and certainly come on back if you have any more "bumps" in the road.

Similar Threads

  1. Call one Java Program from another Java Program
    By rajpalparyani in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 05:13 AM
  2. Replies: 4
    Last Post: 07-30-2010, 01:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 06:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Tags for this Thread

Posting Permissions

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