关于一道JAVA作业,麻烦各位帮忙看看,很急!!!谢谢
import javax.swing.JOptionPane;
import java.util.Date;
/**
* A3Q2:Compound Interest
*
* COURSE: COMP 1010 SECTION: DE
* INSTRUCTOR: Mr. Victor Balogun
* ASSIGNMENT: 3 QUESTION: 2
* @author GuanNan Zhang, 7606172
* @version date of completion
*/
public class poin
{
double x,y;
public poin(){}
public poin(double x,double y)
{
this.x=x;
this.y=y;
}
public double distanceTo(double x,double y)
{
double distance;
distance = Math.sqrt((Math.pow(this.x,2))+(Math.pow(this.y,2)));
return distance;
}
public int getQuadrant()
{
int quadrant=0;
if (this.x>0)
{
if (this.y>0)
quadrant=1;
else
quadrant=4;
}
if(this.x<0)
{
if(this.y>0)
quadrant=2;
else
quadrant=3;
}
return quadrant;
}
public void translate(double dx, double dy)
{
double newx;
double newy;
newx=this.x+dx;
newy=this.y+dy;
System.out.println("p.toString(): Point[ x="+newx+",y="+newy+"]");
return;
}
public String toString()
{
}
public boolean isOrigin()
{
boolean origin=false;
if(this.x!=0&&this.y!=0)
origin=false;
else
origin=true;
return origin;
}
public static void main(String[] args)
{
String input;
double x;
double y;
double dx;
double dy;
input=JOptionPane.showInputDialog("please input the x");
x=Double.parseDouble(input);
input=JOptionPane.showInputDialog("please input the y");
y=Double.parseDouble(input);
input=JOptionPane.showInputDialog("please input the dx");
dx=Double.parseDouble(input);
input=JOptionPane.showInputDialog("please input the dy");
dy=Double.parseDouble(input);
poin a=new poin(x,y);
System.out.println(a.distanceTo(x,y));
System.out.println("Creating Point object, origin");
System.out.println("origin = new Point(): Point[x=0.0, y=0.0]");
System.out.println("Creating new Point object, p:");
System.out.println("p = new Point("+x+","+y+"): Point[ x="+x+",y="+y+"]");
System.out.println("p.getX(): "+x);
System.out.println("p.gety(): "+y);
System.out.println("p.translate("+dx+","+dy);
System.out.println("p.distanceTo(origin): "+a.distanceTo(x,y));
System.out.println("p.getQuadrant(): "+a.getQuadrant());
System.out.println("p.isOrigin(): "+a.isOrigin());
System.out.println("End of processing.");
}
}
现在需要在public String toString()这里来调用public void translate(double dx, double dy)
,来输出public void translate(double dx, double dy)里面计算出来的newx和newy,而且public void translate(double dx, double dy)这里的dx和dy是在public static void main(String[] args)来输入的,如何把这3者联系起来,现在我不清楚该怎样在main函数来输入dx和dy,并且在main函数调用tostring的输出newx和newy,麻烦各位帮忙把这段程序完整下,马上要交作业了,谢谢谢谢各位了