Project #26442 - intro to java

Question 1
Write a class called MyPoint to represent a point with x- and y-coordinates The class must contain:

  • Two data fields x and y of type double.

  • Getter methods for the x and y data fields.

  • A constructor that constructs a point with specified coordinates.

  • A no-argument constructor that creates the point (0, 0) – this constructor must call your previous constructor.

  • A (non-static) method double distance(MyPoint p) that returns the distance from this point to the point p.

    Write a test program that creates two points (0, 0) and (10, 30.5) and displays the distance between them.

     

    Question 2

    Consider the following code,

    MyPoint p = new MyPoint(4, 5); Carefully explain how the point p is constructed.

    Draw pictures showing the stages of object construction (as I did in class), describe how the constructor is chosen, what this refers to, and finally what p refers to.

     

    Question 3

    Consider the following code,

    MyPoint p = new MyPoint();

page1image11392 page1image11552 page1image11712

Carefully explain how the point p is constructed.
Draw pictures showing the stages of object construction (as I did in class), describe how the constructor

is chosen, what this refers to, and finally what p refers to.

 

Question 4

Consider the following code,

MyPoint p = new MyPoint(5, 6); MyPoint q = new MyPoint(1, 1); double d = p.distance(q);

Carefully explain how the distance method is called.
Draw pictures for
p and q, show what this refers to during the call, what the parameters of distance

refer to, etc. 

Subject Computer
Due By (Pacific Time) 04/02/2014 05:30 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy