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

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1.124J Foundations of Software Engineering Problem Set 5 Due Date: Tuesday 10/24/00 Reference Readings: From Java Tutorial Getting Started: Lessons 1-3 Learning the Java Language: Lessons 4-7 o 4. Object-Oriented Programming Concepts o 5. The Nuts and Bolts of the Java Language o 6. Objects and Classes in Java o 7. More Features of the Java Language Problem 1: [30%] This problem consists of 3 small parts. In the first part, you need to provide a java application, then in the second part you must write a java applet, and, finally, at the third part you need to provide, in one file, a class which can be executed both as an applet and as an application. For all 3 parts you need to provide a class for Point objects named MyPoint . The data members of the class should be the following: two doubles, named x and y , to store the x and y coordinates of the point. one static int, named numberMyPoints to keep truck of the number of points that have been created The class should be called MyPoint and should be provided in a file MyPoint.java . It should have two constructors: a non-argument constructor which should install zero values to both x and y a constructor which has two double as arguments by the names x and y . The constructors should take care of increasing accordingly the number of MyPoint objects that are created using the static member data numberMyPoints . The class should also provide a toString method which should return a string consisting of the string "(x,y) =" and the values of x and y enclosed in parentheses and separated with a comma e.g.: (x,y) = (-4.6 , 9.5)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Finally, the class MyPoint should have a member function named move which have two parameters named dx and dy of type double . The function move() should add the dx and dy to the values of the member data x and y, respectively. Part A: In this part you need to provide an application, i.e. which can be executed from a console (e.g. an xterm), in a file named ps5_1a.java . The main function should print out the number of the MyPoint objects (which initially should be set to zero, since no objects would have been created). Then, it should create (using new ) an object named p1 using the non-argument constructor (which gives zero values). Then, the number of MyPoint objects should be printed again out, using the corresponding static variable. The p1 object should also be printed out making use of the toString() function. Then, MyPoint object, named p2 , should be created and given the values -4.6 and 9.5, for x and the y , respectively, using the other constructor. Then, the number of MyPoint objects should be printed, again, out followed by the printing of the object p2 making use of the toString() function. Finally, move the point
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/04/2011 for the course ESD 1.124 taught by Professor Kevinamaratunga during the Fall '00 term at MIT.

Page1 / 13

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online