Hi everyone,
How's everything? Busy in learning
java?
A question is that I can use the equal and to
string methods?
For example:
---------------------------------- | |
| public class Point |
| ------------------------------| |
| private doulbe x,y |
| |
| public Point (double x,y) |
| |
| public double x() |
| public doulbe y() |
| |
| public boolean equal(PointP) |
| |
| public String toString() |
| |
----------------------------------
1. How to write the 'equals() method?
2. How use the toString method that if the Point object had the coordinates(3,4) then the string "(3.0, 4.0)" would be returned.
3. if I need to use the equal() method, what would be the output of the following Java code fragement?
Point p = new Point (2, 3);
println("p.x() = " + p.x() + ", p.y()= " + p.y());
println ("p = " + p);
Point q = new Point (7, 4);
println ("q = " + q);
if (q.equals(p))
println ("q equals p");
else
println ("q does not equal p");
q = new Point (2, 3);
println ("q = " + q);
if (q.equals(p))
println ("q equals p");
else
println ("q does not equal p");
if (q == p)
println ("q == p");
else
println ("q != p");
I think it's a little bit hard ...anyone knows that how to solve that ?
Thanks
Larry