UNB/ CS/ David Bremner/ teaching/ java/ Intersect.java
```import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JOptionPane;

public class Intersect extends Applet
{  public void init()
{  String input
= JOptionPane.showInputDialog("x:");
x = Integer.parseInt(input);
}

public void paint(Graphics g)
{  Graphics2D g2 = (Graphics2D)g;

double r = 100; // the radius of the circle

// draw the circle

Ellipse2D.Double circle
= new Ellipse2D.Double(0, 0, 2 * r, 2 * r);
g2.draw(circle);

// draw the vertical line

Line2D.Double line
= new Line2D.Double(x, 0, x, 2 * r);
g2.draw(line);

// compute the intersection points

double a = r;
double b = r;

double root = Math.sqrt(r * r - (x - a) * (x - a));
double y1 = b + root;
double y2 = b - root;

// draw the intersection points

Ellipse2D.Double circle1 = new Ellipse2D.Double(
Ellipse2D.Double circle2 = new Ellipse2D.Double(

g2.draw(circle1);
g2.draw(circle2);

// label the intersection points

String label1 = "" + y1;
String label2 = "" + y2;

g2.drawString(label1, (float)x, (float)y1);
g2.drawString(label2, (float)x, (float)y2);
}

private double x;
}
```