wood burning stoves*
The moose likes Beginning Java and the fly likes Suggestions on this code needed. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Suggestions on this code needed." Watch "Suggestions on this code needed." New topic
Author

Suggestions on this code needed.

lakmal padmakumara
Ranch Hand

Joined: Aug 08, 2009
Posts: 47
I saw a question on "YAHOO ANSWERS" and and here is my solution .I just want to get some suggestions to improve my code .Or if I have used some bad programming practices to get to know about them.but I dont know is it ok to post this kind of questions where actually Im not asking a specific question .So My friends if this is post is not suitable please tell me.I won't post this kind of questions again .Im learning java through self studies these days so finding a way to improve my coding abilities.

Question was ---

How to do this java programme?

Q3. Write a program to draw a diamond sign in to the screen with different heights entered by the user. See following example.

http://answers.yahoo.com/question/index?qid=20090925215708AAkjRKl



and here is my answer

[Bsc in Computer Science and Engineering] [SCJP 80%][BCS certificate level]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Did you run your program?? It doesn't produces the same result as in the question...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
lakmal padmakumara
Ranch Hand

Joined: Aug 08, 2009
Posts: 47
Hey Ankit you were dead right !!! actually what had happened was the yahoo page i visited showed the exact output i was trying to get.So as a stupid i didn't read the whole problem,and started coding for the output i saw.(may be an error in loading of that yahoo page )

And after your correction i tried to get that output and here is my code .but there is a error in the shape .I cant point out the error .Please help me on this !!!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

You posted this question in the forum about the SCJP exam, but this doesn't seem to be directly related to the SCJP. I'll move this to a more appropriate forum for you.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
John Sutt
Ranch Hand

Joined: Mar 07, 2008
Posts: 42
* Are you aware that you are only using your static variables height
and state in your main method? I'd suggest to have those variables
be local variables in your main method then.
* Add more comments to your code to make it easier to read what, for example,
the goals of your for-loops are. I (and you after X months) have to completely
figure it out myself. Something like:

* After you've done that, you'll quickly find out that you should not have put your
for-loop for variable k (denoted A above) within your for-loop of variable j (denoted B above).

Good luck finishing up

SCJP 6 (91%), SCJD (91%)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
What does your do loop do? It looks as if it will be confusing to use, and you will not actually get an odd number.
Why have you got so much code in the constructor?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Suggestions on this code needed.