当前位置: 技术问答>java相关
看一段简单的程序,高分相送.急!!!!!!!!
来源: 互联网 发布时间:2015-09-12
本文导语: 我是新手,下面有两句有错,後面已经标出,但不知为什么。 package myshapes; class Point { public Point() {x=0;y=0; } public Point(double x,double y){ this.x=x;this.y=y; } double distance (point Z){ double a=(this.x-Z.x)...
我是新手,下面有两句有错,後面已经标出,但不知为什么。
package myshapes;
class Point {
public Point() {x=0;y=0;
}
public Point(double x,double y){
this.x=x;this.y=y;
}
double distance (point Z){
double a=(this.x-Z.x)*(this.x-Z.x)+(this.y-Z.y)*(this.y-Z.y);
return Math.sqrt(a);
}
static double distance (point M,point N){
double a=(M.x-N.x)*(M.x-N.x)+(M.y-N.y)*(M.y-N.y);
return Math.sqrt(a);
}
private double x,y;
-------------------------------------------------------------------
package myshapes;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
class Shape {
private double length;
private double area;
}
-------------------------------------------------------------------
package myshapes;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
public interface Shapetools {
double PI=3.14;
void getLength(Shape shape){}
void getArea(Shape shape){}
}
--------------------------------------------------------------------
package myshapes;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
import myshapes.*;
class Circle extends Shape implements Shapetools{
Point A;
double diam;
void Circle(){
this.A=new Point(0,0);
diam=0;
}
void Circle(Point A,double diam){
this.Point A=new Point();
this.A.x=A.x;
this.A.y=A.y;
this.diam=diam;
}
public void getLength(){
length=PI*2*diam;
System.out.printIn("the leng of the circle is"+leng);
}
public void getArea(){
area=PI*diam*diam;
System.out.printIn("the area of the circle is"+area);
}
}
-----------------------------------------------------------------------
package myshapes;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
import myshapes.*;
class Rect extends Shape implements Shapetools{
Point A,B;
void Rect (){
A=new Point(0,0);
B=new Point(1,1);
}
void Rect(Point A,Point B){
this.Point A=new Point();
this.Point B=new Point();
this.A.x=A.x;
this.A.y=A.y;
this.B.x=B.x;
this.B.Y=B.y;
}
public void getLength(){
double a=Math.abs(A.x-B.x);
double b=Math.abs(A.y-B.y);
length=2*(a+b);
System.out.printIn("the length of the rectangle is"+length);
}
public void getArea(){
double a=Math.abs(A.x-B.x);
double b=Math.abs(A.y-B.y);
area=a*b;
System.out.printIn("the area of the rectangle is"+area);
}
}
---------------------------------------------------------------------
package myshapes;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
import myshapes.*;
class Myshapes {
private static Point A=new Point();
private static Point B=new Point(2,2);
public static void main(String Args[]){
InputStreamReader ir;
BufferedReader in;
ir=new InputStreamReader(System.in);
in=new BufferedReader(ir);
System.out.printIn("please input the diam:");
String s=In.readLine();
double diam=Integer.parseInt(s);
Shape myshape[]=new Shape[4];
myshape[0]=new Rect();
myshape[1]=new Rect(A,B);
myshape[2]=new Circle();
myshape[3]=new Circle(A,diam);/*这具有毛病*/
for(int i=0;i
package myshapes;
class Point {
public Point() {x=0;y=0;
}
public Point(double x,double y){
this.x=x;this.y=y;
}
double distance (point Z){
double a=(this.x-Z.x)*(this.x-Z.x)+(this.y-Z.y)*(this.y-Z.y);
return Math.sqrt(a);
}
static double distance (point M,point N){
double a=(M.x-N.x)*(M.x-N.x)+(M.y-N.y)*(M.y-N.y);
return Math.sqrt(a);
}
private double x,y;
-------------------------------------------------------------------
package myshapes;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
class Shape {
private double length;
private double area;
}
-------------------------------------------------------------------
package myshapes;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
public interface Shapetools {
double PI=3.14;
void getLength(Shape shape){}
void getArea(Shape shape){}
}
--------------------------------------------------------------------
package myshapes;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
import myshapes.*;
class Circle extends Shape implements Shapetools{
Point A;
double diam;
void Circle(){
this.A=new Point(0,0);
diam=0;
}
void Circle(Point A,double diam){
this.Point A=new Point();
this.A.x=A.x;
this.A.y=A.y;
this.diam=diam;
}
public void getLength(){
length=PI*2*diam;
System.out.printIn("the leng of the circle is"+leng);
}
public void getArea(){
area=PI*diam*diam;
System.out.printIn("the area of the circle is"+area);
}
}
-----------------------------------------------------------------------
package myshapes;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
import myshapes.*;
class Rect extends Shape implements Shapetools{
Point A,B;
void Rect (){
A=new Point(0,0);
B=new Point(1,1);
}
void Rect(Point A,Point B){
this.Point A=new Point();
this.Point B=new Point();
this.A.x=A.x;
this.A.y=A.y;
this.B.x=B.x;
this.B.Y=B.y;
}
public void getLength(){
double a=Math.abs(A.x-B.x);
double b=Math.abs(A.y-B.y);
length=2*(a+b);
System.out.printIn("the length of the rectangle is"+length);
}
public void getArea(){
double a=Math.abs(A.x-B.x);
double b=Math.abs(A.y-B.y);
area=a*b;
System.out.printIn("the area of the rectangle is"+area);
}
}
---------------------------------------------------------------------
package myshapes;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
import myshapes.*;
class Myshapes {
private static Point A=new Point();
private static Point B=new Point(2,2);
public static void main(String Args[]){
InputStreamReader ir;
BufferedReader in;
ir=new InputStreamReader(System.in);
in=new BufferedReader(ir);
System.out.printIn("please input the diam:");
String s=In.readLine();
double diam=Integer.parseInt(s);
Shape myshape[]=new Shape[4];
myshape[0]=new Rect();
myshape[1]=new Rect(A,B);
myshape[2]=new Circle();
myshape[3]=new Circle(A,diam);/*这具有毛病*/
for(int i=0;i