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 6 of 6

Thread: Would appreciate help (Beginner programmer)

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    31
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Would appreciate help (Beginner programmer)

    Hello everyone,

    Im new to java programming and especially new to this forum. Im taking my first college computer science course. I did very well on my first exam (loops, methods, keyboard input, types, etc). However, this question seriously has me stumped. How do I make the quarter circle/square? I attached a picture of the question.

    Heres what I know:

    - I know I will need a loop

    - Need to declare Random integer- how do I do this?

    - I have no idea where to start


    Code for program:

     
    import java.util.Random;
     
    class Dogs
     
    {
     
        public static void main (String[] args)
     
        {
     
              Random integer r = new Random     // Completely wrong probably.




    Any help or suggestions will be greatly appreciated. Thank you in advance.
    Attached Images Attached Images


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Would appreciate help (Beginner programmer)

    Not random integer, random double as specified by the problem. Read carefully. To accomplish, you can use the Math.random() method or a method of the Random class. Review the APIs for both and decide which you prefer for this assignment.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    TSSF44 (October 17th, 2013)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Would appreciate help (Beginner programmer)

    How do I make the quarter circle/square?
    Not sure what you are asking. Are you trying to draw an arc inside a square where the center of the circle is at one of the corners and the radius of the circle equals the length of a side of the square?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Would appreciate help (Beginner programmer)

    I agree the directions are a bit confusing. You really don't make a geometric shape of any kind, though it would be helpful to your understanding if you drew the dartboard and the quarter circle as described.

    The coordinates randomly generated are used to describe the dart's location on the dartboard with (0, 0) specified as the lower left corner of the dartboard, x increases across the dartboard, and y increases UP the dartboard, therefore for (x, y):

    (0, 0) is lower left corner of the dartboard
    (1, 0) is the lower right corner of the dartboard
    (0, 1) is the upper left corner of the dartboard, and
    (1, 1) is the upper right corner of the dartboard.

    Throws inside the described quarter circle with a radius <= 1 are "hits." Throws outside are "misses." To determine the radius of each throw (the distance from the origin), use the formula

    r = sqrt( x^2 + y^2 )

    Let us know if you have questions.

  6. The Following User Says Thank You to GregBrannon For This Useful Post:

    TSSF44 (October 17th, 2013)

  7. #5
    Member
    Join Date
    Oct 2013
    Posts
    31
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Would appreciate help (Beginner programmer)

    Thanks for the help guys. It's coming along... slowly but surely

    import java.util.Random;
     
    class Dogs
     
    {
     
        public static void main (String[] args)
     
        {
     
              Random r = new Random();    
     
     
     
     	  int c = 1;
     
    	  while (c <= 1000000)
    	  {
     
    	     double x = r.nextDouble();
    	     System.out.println(x);
    	     double y = r.nextDouble();
    	     System.out.println(y);
    	     if (x*x + y*y <= 1)
      	     c++;
     
     
    	  }
     
     
    	  double p = Math.PI;
    	  System.out.println(p);
     
        }
     
     
     
     
    }

  8. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Would appreciate help (Beginner programmer)

    Please learn to post your code in code tags. Read the Announcement topic at the top of the sub-forum.

    Yes, you're making progress. Compare your if statement to the equation I gave earlier.

Similar Threads

  1. Hello Community - Beginner Java Programmer
    By Dream Hacked in forum Member Introductions
    Replies: 1
    Last Post: July 25th, 2013, 04:12 PM
  2. Beginner programmer looking for time estimates
    By Xenoz in forum Java Theory & Questions
    Replies: 1
    Last Post: December 19th, 2012, 09:33 AM
  3. tips for beginner programmer
    By Syahdeini in forum The Cafe
    Replies: 1
    Last Post: July 11th, 2012, 09:31 PM
  4. beginner programmer trouble
    By scottey313 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 30th, 2011, 01:41 PM
  5. Beginner java programmer!
    By chrisivey1980 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: April 23rd, 2011, 03:06 AM