Results 1 to 7 of 7
Thread: First ever Java Program: HELP
- 02-04-2012, 04:16 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
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:
It says there's a bug, but I can't see it for the life of me.Java Code:for (int i = BRICKS_IN_BASE, i > 0, i--) { add(brick); }
Elsewhere there's this:
but Eclipse doesn't seem to recognise that the two BRICKS_IN_BASE are the same constant integer.Java Code:private static final int BRICKS_IN_BASE = 14;
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
-
Re: First ever Java Program: HELP
Let me start by welcoming you to the java-forums.org!
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.2. What is wrong with this:
It says there's a bug, but I can't see it for the life of me.Java Code:for (int i = BRICKS_IN_BASE, i > 0, i--) { add(brick); }
Again, what is the exact error message? Are you trying to re-declare the BRICKS_IN_BASE constant? I'm not sure.Elsewhere there's this:
but Eclipse doesn't seem to recognise that the two BRICKS_IN_BASE are the same constant integer.Java Code:private static final int BRICKS_IN_BASE = 14;
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.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?
Again, best of luck with your Java education and welcome to our corner of the Java forum world!
- 02-04-2012, 05:16 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,560
- Rep Power
- 11
Re: First ever Java Program: HELP
That goes for missing underscores as well: BRICKS_IN_BASE the compiler will like, BRICKS IN BASE it will not.remember that compilers are very picky and will complain for any spelling, capitalization or symbol error
-
Re: First ever Java Program: HELP
- 02-04-2012, 05:33 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,560
- Rep Power
- 11
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...
- 02-04-2012, 05:46 PM #6
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
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
-
Similar Threads
-
Call one Java Program from another Java Program
By rajpalparyani in forum New To JavaReplies: 3Last Post: 02-14-2011, 04:13 AM -
Is There A Way To Call Another Java Program Within A Java Program
By SwissR in forum New To JavaReplies: 4Last Post: 07-30-2010, 12:25 PM -
execute java program within java program
By popey in forum New To JavaReplies: 2Last Post: 10-22-2009, 05:32 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks