| CSCI A201/A597Lab Notes 11 Spring 2000 |
Make sure you log into QuizSite and complete the survey for your instructors.
Your feedback is important to us!
Here are solutions for 6 and 7.
Study these programs with your AIs and turn them into procedures.
This program starts from two points, and computes the midpoint.
It then draw them all, solid circles for endpoints, empty circle for the midpoint.
import element.*;
public class P6 {
public static void main(String[] args) {
Pt p = new Pt(30, 40);
Pt q = new Pt(120, 160);
Pt m = new Pt((p.x() + q.x()) / 2, (p.y() + q.y()) / 2);
DrawingWindow d = new DrawingWindow();
Circle cp = new Circle(p, 3);
Circle cq = new Circle(q, 3);
Circle cm = new Circle(m, 3);
d.fill(cp);
d.draw(cq);
d.fill(cm);
}
}
This program starts from three points, and computes the center of mass. It draws solid circles for the vertices, and an empty one for the center of mass.
import element.*;
public class P7 {
public static void main(String[] args) {
Pt p = new Pt(30, 40);
Pt q = new Pt(120, 160);
Pt r = new Pt(160, 50);
Pt m = new Pt((p.x() + q.x()) / 2, (p.y() + q.y()) / 2);
Pt cM = new Pt(m.x() + (r.x() - m.x())/3, m.y() + (r.y() - m.y())/3);
DrawingWindow d = new DrawingWindow();
Circle cp = new Circle(p, 3);
Circle cq = new Circle(q, 3);
Circle cr = new Circle(r, 3);
d.fill(cp);
d.fill(cq);
d.fill(cr);
Circle ccM = new Circle(cM, 3);
d.draw(ccM);
}
}
Let me know if you need more help. Also, check lab notes again for the steps you need to take when you develop a procedure.