Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Graphics Expert

Drawing and Comparing Circles
The Circles Class
Objectives

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

Hand-in Requirements

All projects and laboratories will be submitted electronically through Blackboard. Zip up your entire lab directory to submit as the source. (Right click on the lab folder and follow Send To > Compressed (zipped) Folder or 7-Zip > Add to "lab2.zip".) The lab folder should include the following:

Circles.java
DrawingPanel.java
CirclesOutput.txt

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 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 find outd 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:

The green circle is smaller than the red circle.

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:

(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.

(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.
Rubric

Your program should compile without any errors. A program with more than one or two compile errors will likely get a zero for the whole assignment.

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 [...]".
Your submission was a Zip file named lab5.zip containing a folder named lab5, which contains the other files.
If your Java program was in a file named Circles.java.
If the output of your Java program was in a file named CirclesOutput.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 inputs the values for three circles from the user.
 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. 

Computer Graphics, Computer Science

  • Category:- Computer Graphics
  • Reference No.:- M988524

Have any Question?


Related Questions in Computer Graphics

The saffir-simpson hurricane scale classifies hurricanes

The Saffir-Simpson Hurricane Scale classifies hurricanes into five categories numbered 1 through 5. Write an application named Hurricane that outputs a hurricane's category based on the user's input of the wind speed. CA ...

Question a describe the architecture of simple raster

Question : a) Describe the architecture of simple raster graphics system? b) Explain raster scan display processor?

The problemyou are to search a bitmap in rgb format and

The problem: You are to search a bitmap in RGB format and count the number of pixels which match a set of colors. The bitmap will be 1024 by 1024 pixels for the purposes of explaining this problem. The set of colors will ...

The problemsit is strongly recommended that you tackle the

The problems: It is strongly recommended that you tackle the following tasks in a modular way -- a separate standalone function for each task. Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polyg ...

Please read my question if you post copy and pasted code

Please read my question if you post copy and pasted code you will get a negative review. This is java In this graphical program, you are going to simulate arcade car racing game. You need a single player that is movable ...

You have a program draw a rectangle on the screen and allow

You have a program draw a rectangle on the screen and allow the user to change the color/size of the rectangle. The program will store in the browser the settings of the color/size so that upon revisiting the page, the v ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As