Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Using loops and control statements to draw lines

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using loops and control statements to draw lines

    hey all...i have a homework and really i don't know how to solve this questions ...this is a period of exams and i don't have enough time to do alot of homeworks..please help me..

    Q1) Using loops and control statements to draw lines can lead to many interesting designs.
    a) Create the design in the left screen capture of Fig. 4.21. This design draws lines from
    the top-left corner, fanning out the lines until they cover the upper-left half of the panel.
    One approach is to divide the width and height into an equal number of steps (we found
    15 steps worked well). The first endpoint of a line will always be in the top-left corner
    (0, 0). The second endpoint can be found by starting at the bottom-left corner and
    moving up one vertical step and right one horizontal step. Draw a line between the two
    endpoints. Continue moving up and to the right one step to find each successive end-
    point. The figure should scale accordingly as you resize the window.
    b) Modify your answer in part (a) to have lines fan out from all four corners, as shown in
    the right screen capture of Fig. 4.21. Lines from opposite corners should intersect along
    the middle.

    4.2 Figure 4.22 displays two additional designs created using while loops and drawLine.
    a) Create the design in the left screen capture of Fig. 4.22. Begin by dividing each edge
    into an equal number of increments (we chose 15 again). The first line starts in the top-
    left corner and ends one step right on the bottom edge. For each successive line, move
    down one increment on the left edge and right one increment on the bottom edge. Con-
    tinue drawing lines until you reach the bottom-right corner. The figure should scale as
    you resize the window so that the endpoints always touch the edges.
    b) Modify your answer in part (a) to mirror the design in all four corners, as shown in the
    right screen capture of Fig. 4.22.
    Attached Images Attached Images


  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using loops and control statements to draw lines

    ...edited by moderator
    Last edited by copeg; January 19th, 2012 at 08:50 AM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,105
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Using loops and control statements to draw lines

    @hbaysal
    What is the purpose of the code you posted?
    You have not explained why you have coded it the way that you have.

    Spoonfeeding answers to OPs is discouraged.


    Whoops, missed the age of this thread!!!
    Last edited by Norm; January 19th, 2012 at 08:59 AM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,262
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: Using loops and control statements to draw lines

    @hbaysal,
    1) read the forum rules
    2) read the following: The Problem with Spoon-feeding
    3) Please don't resurrect posts which are over a year old

Similar Threads

  1. help me draw a triangle....
    By beandip408 in forum Object Oriented Programming
    Replies: 10
    Last Post: October 28th, 2010, 05:49 PM
  2. Won't Draw??
    By The_Mexican in forum Java Applets
    Replies: 4
    Last Post: March 13th, 2010, 05:00 PM
  3. lucky draw.. (pls help)
    By amin in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 20th, 2009, 11:30 PM
  4. how do i draw a shape with nested loops?
    By Kilowog in forum Loops & Control Statements
    Replies: 1
    Last Post: September 25th, 2009, 12:14 AM
  5. [SOLVED] Fixing of bug in number guessing game
    By big_c in forum Loops & Control Statements
    Replies: 6
    Last Post: April 16th, 2009, 02:15 AM