aspose file tools*
The moose likes Beginning Java and the fly likes crazy lecturers and tricky questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "crazy lecturers and tricky questions" Watch "crazy lecturers and tricky questions" New topic
Author

crazy lecturers and tricky questions

Lydia Su
Greenhorn

Joined: Apr 27, 2001
Posts: 13
another question for everyone *i'm a sorry person i am...*
this is the question :
Write an applet that divides the display area into a checkerboard of 8x8 squares. It should colour the squares with random colours.
and this is my answer so far :

my problem is that the applet outputs only one line of colored squares, i need to make it 8 lines of colored squares...i think there's something wrong with that for loop...? somebody help me please, i've got another 2 questions to finish and a bunch of projects too....!
(edited by Cindy to format code)

[This message has been edited by Cindy Glass (edited July 10, 2001).]
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
why don't you create an applet and switch the layoutmanager to a gridLayout that is 8X8 and populate it with the colored squares you would like. You should probably override the init() as well.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Lydia, your code is missing just one thing: you need to reset x to 0 before you paint the next row of squares. You can do that right after you add 30 to y. Otherwise, your x coordinate just keeps moving 30 pixels to the right.


Junilu - [How to Ask Questions] [How to Answer Questions]
CJ Fleck
Greenhorn

Joined: Jun 26, 2001
Posts: 9
or you could read whatever book your instructor provided and do the homework yourself.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
CJ,
I understand your position, but this IS a forum for beginners. To tell you the truth, when I started studying Java it looked like Greek even AFTER I read the book.
One little suggestion that will probably be remembered for a LONG time is NOT going to get in the way of Lydia's education.
Please be patient.
Cindy


"JavaRanch, where the deer and the Certified play" - David O'Meara
ellen berry
Ranch Hand

Joined: Jun 10, 2001
Posts: 31
Hi,CJ

What you said make the beginner sad? Thinking about youself when you started to learn Java, I do not think you understood whole things at that time.
Ellen
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
No, I don't really understand CJ's position.
For a beginner, or even someone who's done alot of studying in programming, a class with nested for-loops and lots of variables can be a tricky thing to get right. And as you said, Cindy, this is a beginner's forum.
I'm sorry, CJ, but I did not find your post amusing at all...
/Kaspar
Lydia Su
Greenhorn

Joined: Apr 27, 2001
Posts: 13
^_^ okaaay, thanks everyone really for all the help...ikinda solved the problem on my own that morning, by deciding to pull on the sides of the appletviewer and wa laaa...i saw what was my mistake in an instant...
frankly speaking, i'm doing a diploma programme in computing and IT. i've done C AND COBOL programming in 3 months each for my first two semesters...i'm SUPPOSED to learn Java AND basic SQL during my third. you see my problem? and my programming paper tests us on all C, COBOL, and Java... ^_^ it's a sad life...
anyway really thanks everyone!
P/s : i have 6 java books but i can't understand EVERYTHING can I? ^_~

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

OK, barkeep, let's have a round of tolerance for everybody. On me.
I understand and agree with CJ's position, which is merely that students posting in this forum should at least try to make a reasonable effort to complete their assignments on their own.
That said, we all should remember our basic netiquette and be careful about the way we chide others, like someone whom we perceive to be trying to take the easy way out or someone we think is being unreasonable or rude. The written word has to be more precise than the oral since we cannot write down our tone of voice (unless you want to post a .wav file ) CJ's message may have been a little curt but who knows, he may have had a different tone when he wrote it than what you read into it.
Besides, everything worked out for Lydia and we should all be happy for her, right?
Cheers, everyone!

Originally posted by Kaspar Dahlqvist:
No, I don't really understand CJ's position.


[This message has been edited by JUNILU LACAR (edited July 12, 2001).]
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Ok. If the round's on you, then...
I might have overreacted a little. Sorry CJ. How about a beer?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

OK, now that everybody's warm and fuzzy again here's some code I was tempted to post at first but decided to hold off until Lydia worked it out for herself:
<pre>
public void paint (Graphics g)
{
super.paint(g);
for (int i = 0, y = 0; i < 8; i++, y +=30)
{
for (int j = 0, x = 0; j < 8; j++, x += 30)
{
g.setColor( new Color(
(int) (Math.random()* 256),
(int) (Math.random()* 256),
(int) (Math.random()* 256))
);
g.fillRect (x, y, width, height);
}
}
}
</pre>
(Edited out a bug )

[This message has been edited by JUNILU LACAR (edited July 12, 2001).]
karl koch
Ranch Hand

Joined: May 25, 2001
Posts: 388
junilu,
why do you have the i and j in the loops ?
how about just droping them ?
for (int x = 0; x < 240; x+=30) {.....
or
for (int x = 0; x < 8*30; x+=30) {... // this is a bit better to understand whats going on.

karl
CJ Fleck
Greenhorn

Joined: Jun 26, 2001
Posts: 9
ok, i'll admit it. i came across a bit more rash than i intended. yes i also understand that people can't learn everything about java in 2 days. my reply wasn't in response to the question or its difficulty. it was directed towards the fact that this is someone's actual homework. i've been ragged on for asking question because people THINK they are homework when in reality they are not. while i am pretty confident that a lot of the questions posted here are in fact homework problems, i appreciate the effort most people make to hide that fact. when it comes down to it, if you are having problems with something like this on homework, odds are good you don't fully understand it. that is you probably need more help with it than a couple of joes at the saloon can offer. perhaps the best idea would be to talk to a professor or someone else who can help with more with the big picture. just getting through the assignment doesn't help anyone.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Originally posted by karl koch:

why do you have the i and j in the loops ?
how about just droping them ?

Sorry, that message was incomplete. I got pulled into a meeting
You're right karl, the loop control is more complex than it needs to be and that's the point I was trying to make. There are a lot of "creative" things you can do with for loops that may seem slick but will actually make your program hard to understand. Also, the first few versions of code you write will often not be the best you can do, so always try to see if you can refactor your code after you get it to run. Refactoring is kind of an "advanced" topic but there is a forum here on the ranch where it is discussed.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

There are some people that post here that obviously have simply not tried hard enough. or at All!!

But I don't find any problem whatsoever in posting 'homework' help type questions.

This is a community of developers. We are all here to give and receive help.

I am being paid by my company in real money for the work I do, and I don't see any problems with asking the Forum for an ocassional helping hand. If someone is willing to spend some time helping me with my job function, then I in return, will come here in my spare time and help others.

Someone else might be 'only' a student, and instead of $$ they are being paid in a grade or GPA, but there is really no difference.

If I need the Ranch as a crutch for my job, I will eventually be fired, or not get lots of $$ or raises, or whatever.

If a student uses the Ranch as a crutch, it will all come out in the end as a poor final exam. And even passing that, they will not be gainfully employed very long until their employer finds out their true level of ability.

To address what CJ said:
when it comes down to it, if you are having problems with something like this on homework, odds are good you don't fully understand it.
Well yes. That's why people ask for help.

that is you probably need more help with it than a couple of joes at the saloon can offer.
I totally disagree. Sometimes the answer is so obvious because ranchers have been doing this for years, and all someone needs is a little nudge in the right direction. This stuff is so easy for many of the ranch hands and bar tenders, only because we forget what it was like being frustrated beyond measure by a stupid little ; at the end of a for loop.

perhaps the best idea would be to talk to a professor or someone else who can help with more with the big picture.
I don't know about your college/university, but talking with my profs only resulted in more headaches. Sometimes they or the books they select are the problem!

Ok, back to my real job now.
CJ Fleck
Greenhorn

Joined: Jun 26, 2001
Posts: 9
i have no problem in being "only" a student because i am one myself. and maybe i am just lucky that the profs at my school are helpful and will take the time to sit down and explain certain aspects to me when i need help. or perhaps i just ask. you seem bitter. why?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Of course many of the questions here that sound like homework are questions from the end of a chapter that the person is reading on their own. When I started studying Java there WERE no professors around for me to ask, just a bunch of mainframe programmers whose eyes crossed if I even mentioned "Object Oriented".
There is NO WAY that I could begin to sort out who is in a formal class, and who is studying on their own.
Plus, I also think that working together IS often a better learning method than toughing it out on your own with the book - EVEN if it is a formal assignment. Soooooooo . . I think all questions are fair game.
Course I didn't even HEAR about javaranch until after I got my certification (I always do stuff backwards )
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Originally posted by Cindy Glass:
Course I didn't even HEAR about javaranch until after I got my certification (I always do stuff backwards )

Same here I sometimes wonder if I could have done better than 83% (well, I know I could have gotten at least 86% if I had just stuck with my first hunch on a couple of questions). In the end though, I just used my SCJP credentials as a way to get my foot in the door of a Java project. To really prove your capabilities, you need to show that you can actually apply the knowledge and technology well.
Jyotsna Clarkin
Ranch Hand

Joined: Jan 26, 2001
Posts: 158
Originally posted by Cindy Glass:

Plus, I also think that working together IS often a better learning method than toughing it out on your own with the book - EVEN if it is a formal assignment. Soooooooo . . I think all questions are fair game.

I agree. I love the Ranch - the environment of patience, tolerance and camraderieand the fact that you can ask dimwitted questions (as I have done) with impunity is one that should exist in ALL learning centres.
But not ALL students clearly distinguish between the plan (do some reading,lots of coding, complete assignments, quizzes and the objective (learn the language, attempt to put the theory into practice, build on the foundation).
We encourage students to discuss their assignments. Except quite a number of them just want to get the assignment DONE without having LEARNED the stuff (i.e made the mistakes) - then problem is the they often run into difficulties on the exams. They are unable to write algorithms, trace code and predict output, design a class. As a teachers I often get frustrated -because the assignments (our tool to gauge the student's progress) were quite good.
The above comment is NOT directed at Lydia
regards,
Jyotsna

[This message has been edited by Jyotsna Clarkin (edited July 12, 2001).]
 
Consider Paul's rocket mass heater.
 
subject: crazy lecturers and tricky questions