Page 1 of 2 12 LastLast
Results 1 to 20 of 24
Like Tree1Likes

Thread: Drawing different shapes with stars.

  1. #1
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Drawing different shapes with stars.

    I'm beginner in Java programming. I'm learning fast, but i currently do not have enough
    knowledge to solely solve this Java problem, which i'm gonna show you after a few lines.
    I'm visiting faculty, where half of the subject are computer-science oriented. I would like
    to get as more points as possible for this Java problem, but as i already said before, i'm
    bad at programming, so i'm writing to you guys. For any help you could offer, i will be very grateful and the
    most important thing -> I will learn something new. Thank you in advance!

    Problem:

    Write a program that in the loop reads data about shapes and then print them out with
    stars. For every single shape, user needs to enter shape number (1 - a rectangle 2 - square, 3 - an isosceles triangle 4 - diamond). After shape numbers, user needs to enter
    information, which is needed for drawing a particular shape (in a rectangle -> sides a and b, in
    isosceles triangle -> length of the lateral side, in a square and diamond -> side a).
    Execution of the program needs to finish, when user for the number of the shape enters 0.

    Here is an example of how the execution of the program should look like. (User inputs are
    underlined because of the better transparency):

    The number of the shape: 1
    Side a: 6
    Side b: 2

    ******
    ******

    The number of the shape: 2
    Side a: 4

    ****
    ****
    ****
    ****

    The number of the shape: 3
    Lateral side: 5

    *
    ***
    *****
    *******
    *********

    The number of the shape: 4
    Side a: 5

    *****
    *****
    *****
    *****
    *****

    The number of the shape: 0
    End
    Last edited by Amazineous; 11-10-2011 at 10:47 PM.

  2. #2
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Drawing different shapes with stars.

    So, you are bad at programming. You have 2 choices: drop the course or study more.

    Then you dump your homework assignment on us. What are we supposed to do? Have you written any code? Then post it. Are you getting any errors? Then post them? Is there a specific problem you have? Then ask a specific question and we can provide a specific answer. As it stands your post is "Here's my assignment. Do it for me"

  3. #3
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default Re: Drawing different shapes with stars.

    Quote Originally Posted by Amazineous View Post
    4 - diamond
    The number of the shape: 4
    Side a: 5
    Java Code:
         *****
        *****
       *****
      *****
     *****
    That is not a diamond.

  4. #4
    javaTurtle is offline Member
    Join Date
    Nov 2011
    Location
    Arizona
    Posts
    10
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    @ Junky - I agree, Amazineous does need to provide a lot more detail about where he/she stands in this project. However, come on...you are very harsh in all of your replies. I don't know if you are a moderator or anyone else in java-forums that is supposed to police these posts. I have read many other posts that you have responded in. Frankly, if you responded to me in this manner and we were in the same room, there would be serious issues that would need to be dealt with.

    If reviewing these posts is too much of a burden for you, stop doing it. Amazineous is looking for help. Amazineous is new. Amazineous may be a first semester programmer student. Amazineous may have lived a very sheltered life and is used to having someone be with him/her every step of the way. Amazineous is a bit timid or reluctant asking for help.

    In short Junky, grow up and grow a backbone. Try asking Amazineous to provide the information you need to help without attacking his/her self-esteem.

    @ Amazineous - Junky does prove a point (vulgar it may be). You need to let the forum know more about where you are at in the project and what issues you are having. If you have been given a task to complete, just start it, even if it outputs nothing but errors. Get used to copy and paste and put those errors and the code you are using to get those errors. If you don't know where to start, start small.

    One feature you need is get input from the user and to see if it works. Try:

    Scanner myScanner = new Scanner(System.in);
    String strNumber = myScanner.nextLine();

    System.out.println(strNumber);

    Start there and see if you can build your program one piece at a time.

  5. #5
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    Hello, thank you for you answer, but isn't the point of forums seeking help if you are bad of something? You do not be so harsh and negative. No, I definitely wasn't trying to put my
    all my homework assignment on you guys. Definitely not. I was just hoping to get some directions in which way to start and which loops to use and so on.

    I have been learning a lot and I have written almost whole code until now. I realized, that this problem really isn't that hard.
    I succecced in creating all the 4 shapes. I created them all with FOR loops. (And sorry, because i misstyped myself, the last shape isn't diamond, it is a rhomb). I created all them as
    methods, which i will call in main. So here comes the problem for me. I would please, if you can give me any instructions, how to create, that if you put a particular number, you get a particular shape.

    My code for the main looks like that ( if you would like i can post the code for shapes also, but in this case, we do not need it)
    //For reading from keyboard you use Scanner, -> we use this BranjePodatkov.preberiInt stuff ....

    public class Shapes{
    public static void main(String[] args){

    System.out.print("The number of the shape: ");
    int number = BranjePodatkov.preberiInt();

    switch (number){
    case 1:
    rectangle();

    case 2:
    square();
    case 3:
    isoscelesTriangle();
    case 4:
    rhomb();
    case 0:
    System.out.print("End");
    break;


    }
    }


    //shapes

    }

    So if i run this -> for the first shape it asks me, to put a number (so everything okay). But then it does not ask me again and print out shapes till the end. So it asks me, to put a number of the shape. If i put 2, it prints out square, then after that it automatically goes to isoscelesTriangle and than to rhomb. So it asks me only the first time, to enter the number of the shape. What can i do, that it will be asking me every time. I know I need to use one or more particular loops more. But at the moment, i really do not know what.
    Thanks for your help guys

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Drawing different shapes with stars.

    Case statements 'fall through', i.e. if one case clause is finished and you don't put a 'break' statement at its end, the next case statement will be executed.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    @ javaTurtle

    Oh when i replied to Junky post, you post wasn't showed here, strange. I saw it moments ago in ma Gmail. So thank you for all of your support and willingness to help. I respect you. Yes in life you need to get used to arrogant with stupid ego like Junky is. In the background, they probably have a lot of troubles, so they act that way with new users, who aren't really good withstuff they used to be. I feel sorry for them! Nevermind. And do not worry, If I'm currently bad at Java, but that doesn't tell anything about me as a person. And i believe, that when some time pasts, i will be very good at this programming language.

    So as you can see, i wrote almost the whole program, i just need to know, how to do that last thing I post i my previous post.
    Any of your help, i would really appreciate.

  8. #8
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    Quote Originally Posted by javaTurtle View Post
    @ Junky - I agree, Amazineous does need to provide a lot more detail about where he/she stands in this project. However, come on...you are very harsh in all of your replies. I don't know if you are a moderator or anyone else in java-forums that is supposed to police these posts. I have read many other posts that you have responded in. Frankly, if you responded to me in this manner and we were in the same room, there would be serious issues that would need to be dealt with.

    If reviewing these posts is too much of a burden for you, stop doing it. Amazineous is looking for help. Amazineous is new. Amazineous may be a first semester programmer student. Amazineous may have lived a very sheltered life and is used to having someone be with him/her every step of the way. Amazineous is a bit timid or reluctant asking for help.

    In short Junky, grow up and grow a backbone. Try asking Amazineous to provide the information you need to help without attacking his/her self-esteem.

    @ Amazineous - Junky does prove a point (vulgar it may be). You need to let the forum know more about where you are at in the project and what issues you are having. If you have been given a task to complete, just start it, even if it outputs nothing but errors. Get used to copy and paste and put those errors and the code you are using to get those errors. If you don't know where to start, start small.

    One feature you need is get input from the user and to see if it works. Try:

    Scanner myScanner = new Scanner(System.in);
    String strNumber = myScanner.nextLine();

    System.out.println(strNumber);

    Start there and see if you can build your program one piece at a time.
    Java turtle, thank you for your post and for your support. If all forum users would be that way you are, the world would be a better place. So i'm used to this arrogant people, with stupid ego and who are full of himself, like Junky is. Maybe they are this way, because in the background they have many weaknesses and troubles. And when some newbie like myself comes into the place, they start to vomit fire all over them. I feel sorry for them. But do not worry about me, if i'm currently bad about Java, that does not tell anything about me as a person. And i believe, that when some time pasts, i will be very good at this programming language.

  9. #9
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    Thank you for your reply Josuah. Yes, i know that if i put break; a the end of every case, that after execution of the particular case, the program will close. So which loop i need to use, that all of the shapes will be exectued when i press particular numbers (1 -> rectangle, 2-> square, 3 - isosceles triangle, 4 -> rhomb.) So if i press 1, the rectangle would show, and after that, it would ask me to put a new shape number. So i would put 2 and the rectangle would print out. And after rectangle is printed, the program would ask me, to put a new shape number. ( if you look at my first post, there is an example for better understanding, what i mean)

    Thanks
    Last edited by Amazineous; 11-13-2011 at 01:59 PM.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Drawing different shapes with stars.

    Quote Originally Posted by Amazineous View Post
    Java turtle, thank you for your post and for your support. If all forum users would be that way you are, the world would be a better place. So i'm used to this arrogant people, with stupid ego and who are full of himself, like Junky is
    If we had to stay polite to everyone who simply dumps their homework here, this forum would become a free homework service; that's not how it works; imagine the answers were spoonfed to you, you'd get a good grade and you get a fine job in the computing industry; suppose you end up sitting next to me; I had to do all your work because you were only spoonfed during your education so you know zilch about the stuff; are you going to hand over your salary to me? If so, there's no problem, otherwise we're not going to do your homework for you and it's you who has to show us some efforts and tell us where you're stuck. Remember, the people who answer questions here, don't get paid for their effforts, we're all volunteers and it's you who has to help us to help you. Calling Junky someone with a 'stupid ego' is a non-sequitur.

    kind regards,

    Jos
    Fubarable likes this.
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: Drawing different shapes with stars.

    Moderator note: since there are two new posters in this thread, several of their posts did not show pending moderator approval. I have "approved" them, and now they all show.

    @Amazinous: And I agree with Jos and Junky: your first post was essentially a "homework dump" and not what this forum is for. Asking questions in a forum is a learned skill that can get better with effort, and so I'm sure your future threads in this forum will be better.
    Last edited by Fubarable; 11-13-2011 at 02:39 PM.

  12. #12
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    Yes I agree with you all. I confess my mistake with posting a thread like this with no signs of my efforts put into problem.

    As I said before, I had no clue with how to start a program. So I post it here because it is Java-help forum and I wasn't thinking of posting it for that reason, that some-one would do the whole work for me. I know that this is not the way how things are done here, or in life. All i wanted was some useful directions in which way to start. So after i post this thread i figured out almost all the things on myself as you can see in my upper post, so like 80% of program now i finished all by myself. I just need some directions on how to finish a program, if anyone is willing to help.

    Thanks

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

    Default Re: Drawing different shapes with stars.

    Quote Originally Posted by Amazineous View Post
    I just need some directions on how to finish a program, if anyone is willing to help.
    Most all of us are more than happy to help. What are your current specific problems?

  14. #14
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    Quote Originally Posted by JosAH View Post
    If we had to stay polite to everyone who simply dumps their homework here, this forum would become a free homework service; that's not how it works; imagine the answers were spoonfed to you, you'd get a good grade and you get a fine job in the computing industry; suppose you end up sitting next to me; I had to do all your work because you were only spoonfed during your education so you know zilch about the stuff; are you going to hand over your salary to me? If so, there's no problem, otherwise we're not going to do your homework for you and it's you who has to show us some efforts and tell us where you're stuck. Remember, the people who answer questions here, don't get paid for their effforts, we're all volunteers and it's you who has to help us to help you. Calling Junky someone with a 'stupid ego' is a non-sequitur.

    kind regards,

    Jos
    Yes i agree with you, so i would like to apologize to Junky. I have no right in judging the people, especially after one post. I finded his post offensive, so all i was doing was standing for myself. But also let's say, that I somehow understand why he replied that way, because my first post in this thread was not on the level. So since I'm new to this forum, in the future i will put in all my efforts to be a better user and to have good relationships with the other users.

  15. #15
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    So in the main, i need to call shapes with numbers. Since now I created all shapes as it's own method. So what i need to do is that if i press number 1, it calls rectangle, then after that it asks me to put a number of the other shape, and lets say that i press 2 and the square is printed out .... it need to look like this :

    The number of the shape: 1
    Side a: 6
    Side b: 2

    ******
    ******

    The number of the shape: 2
    Side a: 4

    ****
    ****
    ****
    ****

    The number of the shape: 3
    Lateral side: 5

    *
    ***
    *****
    *******
    *********

    The number of the shape: 4
    Side a: 5

    *****
    *****
    *****
    *****
    *****

    The number of the shape: 0
    End

    My code for the main looks like that ( if you would like i can post the code for shapes also, but in this case, we do not need it)
    //For reading from keyboard you use Scanner, -> we use this BranjePodatkov.preberiInt stuff ....

    public class Shapes{
    public static void main(String[] args){

    System.out.print("The number of the shape: ");
    int number = BranjePodatkov.preberiInt();

    switch (number){
    case 1:
    rectangle();

    case 2:
    square();
    case 3:
    isoscelesTriangle();
    case 4:
    rhomb();
    case 0:
    System.out.print("End");
    break;


    }
    }


    //shapes

    }

    So if i run this -> for the first shape it asks me, to put a number (so everything okay). But then it does not ask me again and print out shapes till the end. So it asks me, to put a number of the shape. If i put 2, it prints out square, then after that it automatically goes to isoscelesTriangle and than to rhomb. So it asks me only the first time, to enter the number of the shape. What can i do, that it will be asking me every time. I know I need to use one or more particular loops more. But at the moment, i really do not know how to do that. Any direction. I will also try if instead of switch. Or do i need to do nesting loops, so that the "The number of the shape: " will print out and ask me about shape number for let's say 5 times?
    Thanks for your help
    Last edited by Amazineous; 11-13-2011 at 04:42 PM.

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

    Default Re: Drawing different shapes with stars.

    To repeat a bit of code, you'll want to use a loop of some kind -- here most likely a do-while loop since you don't know in advance how many times to loop, and you want the loop to run at least once.

    To have your switch statement work correctly, you'll want to add breaks after each statement. Look at a switch tutorial or your book on this to see how it is properly done.

  17. #17
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    So, thank you for your suggestions Fubarable

    I used Switch statement and infinite For loop outside of that. So it now asks me all the time,to to enter the number of the shape and after i enter the number from 1 to 4 if prints out particular shape. But i still got one little trouble to do. What i need to do, that after I enter the number 0, then it will print out "End" and that will be the end of the program.. My program in main looks like this

    public class Shapes{
    public static void main(String[] args){

    for( ; ; ){
    System.out.print("The number of the shape: ");
    int number = BranjePodatkov.preberiInt();

    switch(number){
    case 1: rectangle(); break;

    case 2: square(); break;

    case 3: isoscelesTriangle(); break;

    case 4: Rhomb(); break;

    }


    }

    }


    //shapes methods


    }

  18. #18
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Drawing different shapes with stars.

    Nowhere in your program do you test number == 0, so your program doesn't do anything when number == 0; the cure is simple: test when the number == 0 (before the switch statement or even as a case clause) and make it do what it has to do.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  19. #19
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    Okay, i did it now. Oh my god, I'm so stupid, moments ago i discovered, that there exists command for ending Java program. So that makes all the stuff a lot more easier. So now finished the whole program. Thank you guys for all your help.
    So the program now looks like this.

    public class Shapes{
    public static void main(String[] args){

    for( ; ; ){
    System.out.print("The number of the shape: ");
    int number = BranjePodatkov.preberiInt(); // At the moment we use this instead of Scanner

    if (number == 0 ){
    System.out.println("End");
    System.exit(0);
    }
    else if (number > 4){
    System.out.println("Type the number of the shape again: ");
    }else{
    switch(number){
    case 1: rectangle(); break;

    case 2: square(); break;

    case 3: isoscelesTriangle(); break;

    case 4: rhomb(); break;

    }
    }

    }

    }



    //here comes all the four shapes like methods, which i call in main



    }

    If anyone still have some better suggestions, please tell them, I'm very willing to listen and I will be very grateful.
    Thanks

  20. #20
    Amazineous is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Re: Drawing different shapes with stars.

    Quote Originally Posted by JosAH View Post
    Nowhere in your program do you test number == 0, so your program doesn't do anything when number == 0; the cure is simple: test when the number == 0 (before the switch statement or even as a case clause) and make it do what it has to do.

    kind regards,

    Jos
    Thank you for your suggestion. Yes i did exactly that, I knew that i need to test 0 like you said, but i was testing it after the FOR loop. So the variable number was not recognized in compiler. So then I used If statement in that way that it is superior to switch statement and now everything works out well. So if i wouldn't figure it out myself, then your advice would save the day, thanks.

Page 1 of 2 12 LastLast

Similar Threads

  1. Drawing simple shapes using loops
    By Quinn in forum New To Java
    Replies: 2
    Last Post: 05-29-2011, 09:05 AM
  2. Drawing shapes with for loops using characters
    By Strawlion in forum New To Java
    Replies: 3
    Last Post: 02-16-2011, 08:32 PM
  3. drawing shapes in java help
    By alphajoseph in forum Java 2D
    Replies: 2
    Last Post: 09-29-2009, 06:35 PM
  4. stars
    By nalinda in forum New To Java
    Replies: 3
    Last Post: 08-25-2009, 11:48 AM
  5. Getting User Input to Drawing Shapes
    By mlfatty in forum AWT / Swing
    Replies: 2
    Last Post: 03-04-2009, 06:36 AM

Posting Permissions

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