Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Task Ask the user for information to draw three circles in a DrawingPanel. Print

ID: 3591926 • Letter: T

Question

Task

Ask the user for information to draw three circles in a DrawingPanel. Print information about the circles. Each item of information should correspond to a different static method.

Similar to previous programs, your program should start by printing Lab 5 written by YOURNAME. The DrawingPanel should be 400x300.

Circles

Ask the user for the center and radius of each circle. Use the fillOval method to draw the circles. Note that the parameters to fillOval (the upper-left corner and the width and height of the bounding box) need to be calculated from the information provided by the user (the center and the radius). Also, fill the circles using three different colors.

Methods

Each of the following items should be performed by a separate static method. Each method might have up to six parameters. Each circle is described by three values: the x and y values of the center, and the radius.

One static method should have parameters for the radiuses of two circles (two parameters), and the method should return -1 if the first circle is smaller, return 0 if the two circles have the same size, or return 1 if the first circle is larger. Based on the return value from this method, the main method should print a line of output like:

Another static method should have parameters for the radiuses and locations of two circles (six paramters), and the method should return 1 if the circles intersect or return 0 if the circles do not intersect (alternatively, you could return true or false). If (x1,y1) and (x2,y2) are the centers of the circles and if r1 and r2 are their radiuses, then the circles intersect if the distance between the centers, the square root of:

is less than or equal to r1 + r2. Based on the return values from this method, the main method should print a line of output like:

(Optional) Given a circle, return 1 if the circle is completely within the window, return 0 if the circle is partially within the window, or return -1 if the circle is completely outside the window. The program should print something appropriate.

Note that each method needs to be called three times. If your circles are blue, green, and red, then the first method needs to be called for three pairs: blue and green, blue and red, and green and red.

If you find it is more convenient to return values other than -1, 0, and 1, you are free to do so. However, your methods must return values that your main method uses to print the results. You are also free to implement any additional methods that you like. Remember to put the results of the print statements into a file named CirclesOutput.txt.

Explanation / Answer

import java.awt.*;
import javax.swing.*;

public class Circles extends JFrame
{

private int screen = 160;

public Circles ()
    {
      super("Three Circles")
      setSize( 400, 300 );
      setVisible( true );
     }

public void paint( Graphics g )
    {
     super.paint( g );
  
     for ( int i = 1; i <= 3; i++ )
        {

         int origin = screent + 80 - i * 10;
         g.drawOval( origin, origin, i * 20, i * 20);
         }
    }

public static void main( String[] args)
      {
       Circles c = new Circles ();
       c.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote