Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
Like Tree1Likes

Thread: Drawing different shapes with stars.

  1. #21
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default Re: Drawing different shapes with stars.

    Quote Originally Posted by Amazineous View Post
    If anyone still have some better suggestions, please tell them, I'm very willing to listen and I will be very grateful.
    why not do all your tests in the switch statement? e.g.

    Java Code:
    switch (number) {
       case 0: quit();
       case 1: rectangle(); break;
       case 2: square(); break;
       case 3: isoscelesTriangle(); break;
       case 4: rhomb(); break;
       default: System.out.println("incorrect choice");
    }
    the quit() method does a System.exit(0) so it never returns.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: Drawing different shapes with stars.

    Yes even i do not know why i was complicating things. Maybe, because that if statement came on the top of my head and so I automatically thought, that it needs to be done that way. Next time i need to ask myself if maybe there exists more simple solution.

    So i created quit() method which calls the exit of the program, and so i did all tests in my Switch statement like you suggested and everything works exactly the same as before, but with difference. And the difference is, that the program looks much nicer and simplier than before, thanks to you Josah.

  3. #23
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default Re: Drawing different shapes with stars.

    If you ever find Amazon.com: Refactoring: Improving the Design of Existing Code (9780201485677): Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts: Books, buy it; it's about improving your own code in small, organized steps; the result will be better, neater, often faster and generally better code.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: Drawing different shapes with stars.

    So as for you suggestion about this book about Refactoring: Improving The Design of Existing Code .... since my hard-drives contains a lot of different stuff about a lot of things I searched for it and i find out, that I already have this book on my computer. So i'mreally looking forward of reading it and so become better in writing code every day.
    Thanks

Page 2 of 2 FirstFirst 12

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
  •