Question 1 Draw a Circle 50 points Before starting this ques

Question 1: Draw a Circle (50 points) Before starting this question, we strongly recommend that you complete the last two warm- up exercises if you have not already done so. These warm-up questions will be the best way to start the assignment. For this question, you will write a program called circle that displays a circle in the upper right quadrant of the Cartesian plane. To do so, write (at a minimum) the following three methods: A. A method called oncircle that takes as input five ints. The first three parameters represen (in order) the radius and x,y coordinates of the centre of the circle. The last two parameters represent an x,y position on the grid. This method determines whether or not the circle should be drawn at the grid coordinates given by the method\'s parameters. To get the appropriate thickness for the circle, return whether the following formula holds or not: radius 2 s (ar a (vm- b) s radius2 1 In the above formula, a and b are the coordinates of the centre of the circle, and x and y are the grid coordinates. B. A method called verifyInput that takes as input three ints representing the radius and centre coor dinates of the circle, and returns nothing. This method should throw an IllegalArgumentException and display a helpful error message if either the circle does not fit in the upper right quadrant, or if the radius is non-positive. Otherwise, the method will not print anything. As a hint, the circle does not fit in the upper-right quadrant if it is too close to the axes C. A method called drawcircle that takes as input an int representing the radius of the circle, another int representing the x coordinate of the centre of the circle, and a third int representing the y

Solution

package circleSquarePackage;

import javax.swing.JComponent;

import java.awt.geom.Ellipse2D;

import java.awt.geom.Ellipse2D.Double;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.color;

import java.awt.Dimension;

public class drawingcircle extends JComponent{

private Ellipse2D.Double sphere;

private int radii;

double circum,area;

public circle(){

sphere=new Ellipse2D.Double();

}

public void setSphere(Ellipse2D.Double sphere){

this.sphere=sphere;

}

public circle(int xAxis,int yAxis,int rad)

{

sphere=new Ellipse2D.Double(xax,yax,ra,ra);

}

public double calcarea()

{

return area=math.pi*ra*a;

}

public void inpx(){

int x=Integer.parseInt(JOptionPane.showInputDialog(null,Enter x-coordiante\");

double y=sphere.y;

Ellipse2D.Double newSphere= new Ellipse2D.Double(x,y,size,size);

setSphere(newSphere);

}

public void inpy(){

int y=Integer.parseInt(JOptionPane.showInputDialog(null,Enter x-coordiante\");

double x=sphere.x;

Ellipse2D.Double newSphere= new Ellipse2D.Double(x,y,size,size);

setSphere(newSphere);

}

public void inpRadi(){

int r=Integer.parseInt(JOptionPane.showInputDialog(null,\'enter radius\");

int size=r*2;

Ellise2D.Double newSphere = new Ellise2D.Double(x,y,size,size)

setSphere(newSphere); }

public void paintComponent(Graphics g){

super.paintComponent(g);

Graphics2D g22 = (Graphics2D) g;

g22.draw(sphere);

}

}

write all import statements:-

public class CircleTester{

int x=Integer.parseInt(JOptionPane.showInputDialog(null,Enter x-coordiante\");

int y=Integer.parseInt(JOptionPane.showInputDialog(null,Enter y-coordiante\");

int rad=Integer.parseInt(JOptionPane.showInputDialog(null,Enter rad-coordiante\");

int si=rad*2;

return new Ellipse2D.Double(x,y,si,si);}

public static void main(string[] args){

SwingUtilities.invokeLater(new Runnable(){

public void run(){

Jframe fr= new JFrame();

fr.setVisible(true);

}

});

}}

 Question 1: Draw a Circle (50 points) Before starting this question, we strongly recommend that you complete the last two warm- up exercises if you have not al
 Question 1: Draw a Circle (50 points) Before starting this question, we strongly recommend that you complete the last two warm- up exercises if you have not al
 Question 1: Draw a Circle (50 points) Before starting this question, we strongly recommend that you complete the last two warm- up exercises if you have not al

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site