Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3406306
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:36:42+00:00 2026-05-18T05:36:42+00:00

This is what I want to accomplish for homework: Design and implement a program

  • 0

This is what I want to accomplish for homework:
Design and implement a program that draws circles, with the radius and location of each circle determined at random. If a circle does not overlap with any othe rcircle, draw that circle in black. If a circle overlaps one or more circles, draw it in cyan. Use an array to store a representation of each circle, then determine the color of each crcle. Two circles overlap if the distance betwen their center points is less than the sum of their radii.

Here is the code that I have so far:

import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import java.math.*;

public class RandomCircles extends JPanel
{
    private int[] sizeArray = new int [4];  // radius of each circle
    private int[] xArray = new int [4]; //array to store x coordinates of circles
    private int[] yArray = new int [4]; //array to store y coordinates of circles


    public RandomCircles()
    {
        Random r = new Random();

        for (int i = 0; i<xArray.length; i++){
            //random numbers from 1 to 20;
            xArray[i] = r.nextInt(200) + 1;
        }
        for (int i = 0; i<yArray.length; i++){
            yArray[i] = r.nextInt(200) + 1;
        }
        for (int i = 0; i<sizeArray.length; i++){
            sizeArray[i] = r.nextInt(100) +1;
        }

        setBackground (Color.white);
        setPreferredSize (new Dimension(300, 200));
    }

    //  Draws all of the circles stored in the array.

    public void paintComponent (Graphics page)
    {
        super.paintComponent(page);
        for (int i = 0 ;i<xArray.length; i++) //this is an iterator that draws the circles and checks for overlapping radii
        {
            for (math.sqrt((x1-x2)*((x1-x2))-((y1-y2)*(y1-y2));
            {//math.sqrt((x1-x2)*(x1-x2)-(y1-y2)*(y1-y2)), go back and read chapter 7
                page.fillOval(xArray[i], yArray[i], sizeArray[i], sizeArray[i]);
            }
        }
    }
    public static void main (String[] args)
    {
        JFrame frame = new JFrame ("Circles");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

        frame.getContentPane().add (new RandomCircles());

        frame.pack();
        frame.setVisible(true);
    }
}

After taking the advice that I received and trying to go through this step by step, I made a lot of progress. I am stuck on the last bit of the project, which is to compare the center points of the circles to the sum of their radii to determine if the circles overlap. I think that I can use the math.sqrt function to compare them, but I’m not sure how to implement it correctly. I know that once I figure out how to check, if they are overlapping (a boolean is true) then I will paint that circle in Cyan. If anyone has any input I would be really appreciative, but I understand if not, I know that asking for too much help is not good. Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:36:43+00:00Added an answer on May 18, 2026 at 5:36 am

    I am lost on how to generate random numbers for the radii of the circles….

    First, write the code to create one circle with a fixed position and radius.

    Then expand on that: Call randomGenerator.nextInt() a couple of times to get random values for the position and radius.

    Next step: Put that into a 10-times loop

    Next step: Run the loop N times where you get N from randomGenerator.nextInt() again

    Recipe: Always start with the most simple example (how do I draw circles anyway?). Then expand it step by tiny step. Avoid “I can do everything at once.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure how to approach this: I want a TreeView that will display
I have a class that contains an array. I want this array to be
Here's a simple (hopefully) L10N question: Do all locales want this format: Sunday, Nov
I have this div: <div class=inauguration-image> I do not want this text to display,
My Invoice model has an address_id attribute, and I don't want this address_id to
This is similar to my previous posting. But this time I want to call
Perhaps I am not asking or searching for this correctly: I want to have
What logging library or approach would you recommend for this case: We want to
can ASP.NET controls be used with generics? Never seen this done and want a
I want to do this: //*fu which returns all nodes whose name ends in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.