Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Helpppp Objectives Call methods with parameters and return values. Use the DrawingPanel and Graphics classes. Use if statements to control return values and print

JAVA Helpppp

Objectives

Call methods with parameters and return values. Use the DrawingPanel and Graphics classes. Use if statements to control return values and print statements.

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

Details

The DrawingPanel should be 512 x 512.

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.

1. A static method named compareSizes(...) should have parameters for the radii 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:

The green circle is smaller than the red circle.

2.Another static method named doesIntersect(...) should have parameters for the radii and locations of two circles (six parameters), 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 radii, then the circles intersect if the distance between the centers, the square root of:

(x1 - x2)2 + (y1 - y2)2

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:

The blue circle intersects the red circle.

3.(Optional) Given a circle, return 1if 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.

Rubric

Your program should compile without any errors. The following criteria will also be used to determine the grade for this assignment:

If your submission includes the following: The main method prints "Lab 5 written by [...]". If your Java program was in a file named Lab4.java.

If your program contains a comment that describes what the program does and contains a comment describing each method. If your program is indented properly.

If the main method correctly draws the three circles in a DrawingPanel with three different colors. If the main method calls a method to compare the sizes of two circles. This method should have two parameters, should return the correct value, and should NOT print anything. The main method should call this method three times.

If the main method calls a method to determine if two circles intersect. This method should have six parameters, should return the correct value, and should NOT print anything. The main method should call this method three times. If the program correctly prints out the results of the above two methods based on their return values.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions