# sol5 - 1.124J Foundations of Software Engineering Problem...

This preview shows pages 1–6. Sign up to view the full content.

1.124J Foundations of Software Engineering Problem Set 5 - Solution Due Date: Tuesday 10/24/00 Problem 1:[30%] The provided solution uses AWT Applet . However, use of Swing JApplet is also an option, probably a better one that someone could have used. MyPoint.java class MyPoint { double x; double y; static int numberMyPoints=0; MyPoint() { x = 0.0 ; y = 0.0 ; numberMyPoints++; } MyPoint(double x, double y) { this.x = x; this.y = y ; numberMyPoints++; } void move(double dx, double dy) { x += dx;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
y += dy ; } public String toString() { return ("(x,y) = (" + x + " , " + y + ")"); } } ps5_1a.java class ps5_1a { static MyPoint p1, p2; public static void main(String args[]) { System.out.println("\n Number of MyPoint objects = " + MyPoint.numberMyPoints); p1 = new MyPoint(); System.out.println("\n Number of MyPoint objects = " +MyPoint.numberMyPoints); System.out.println("\n p1: " + p1); p2 = new MyPoint(-4.6,9.5); System.out.println("\n Number of MyPoint objects = " + MyPoint.numberMyPoints); System.out.println("\n p2 = " + p2); p1.move(4.5, 0.7); System.out.println("\n p1: " + p1); } } ps5_1b.java import java.applet.Applet; import java.awt.Graphics;
public class ps5_1b extends Applet { MyPoint p1, p2; public void init() { p1 = new MyPoint(); p1.move(4.5, 0.7); p2 = new MyPoint(-4.6, 9.5); } public void paint(Graphics g) { g.drawString("Number of MyPoint objects = " + MyPoint.numberMyPoints, 40,50); g.drawString(" p1: " + p1 , 40, 100); g.drawString(" p2: " + p2 , 40, 150); } } ps5_1b.html <HTML> <HEAD> <TITLE> Problem set 5: problem 1c</TITLE> </HEAD> <BODY> <h1> Problem Set 5: Problem 1c <APPLET CODE="ps5_1c.class" WIDTH=300 HEIGHT=200 align=center> </APPLET> </BODY> </HTML> ps5_1c.java

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
import java.applet.Applet; import java.awt.Graphics; public class ps5_1c extends Applet { static MyPoint p1, p2; public void init() { p1 = new MyPoint(); p2 = new MyPoint(-4.6, 9.5); p1.move(4.5, 0.7); } public void paint(Graphics g) { g.drawString("Number of MyPoint objects = " + MyPoint.numberMyPoints, 40,50); g.drawString(" p1: " + p1 , 40, 100); g.drawString(" p2: " + p2 , 40, 150); } public static void main(String args[]) { System.out.println("\n Number of MyPoint objects = " + MyPoint.numberMyPoints); p1 = new MyPoint(); System.out.println("\n Number of MyPoint objects = " +MyPoint.numberMyPoints); System.out.println("\n p1: " + p1); p2 = new MyPoint(-4.6,9.5); System.out.println("\n Number of MyPoint objects = " + MyPoint.numberMyPoints); System.out.println("\n p2 = " + p2); p1.move(4.5, 0.7); System.out.println("\n p1: " + p1); } }
ps5_1c.html <HTML> <HEAD> <TITLE> Problem set 5: problem 1c</TITLE> </HEAD> <BODY> <h1> Problem Set 5: Problem 1c <APPLET CODE="ps5_1c.class" WIDTH=300 HEIGHT=200 align=center> </APPLET> </BODY> </HTML> Problem 2:[35%] ps5_2.java class ps5_2 { static final int SIZE = 100; static Shape shapes[]; public static void main(String args[]) { System.out.print("\n Reading the shapes. .."); readShapes(); System.out.print("\n Printing the shapes. .."); printShapes(); System.out.print("\n Cleaning-up the shapes. .."); cleanUpShapes(); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

sol5 - 1.124J Foundations of Software Engineering Problem...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online