这道java题怎么写啊,,谁能帮我写下来,求帮助 100
1个回答
展开全部
您好,这样呀:
//代码没经过仔细测试,这就靠你了哈
public class MyLine {
private Point px;
private Point py;
public MyLine(float x1,float y1,float x2,float y2){
this.px=new Point();
this.py=new Point();
this.px.setX(x1);
this.px.setY(y1);
this.py.setX(x2);
this.py.setY(y2);
}
public MyLine(Point p1,Point p2){
this.px=p1;
this.py=p2;
}
class Point{
private float x;
private float y;
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
}
/**
* 求线段长
* @return
*/
public float getLineLength(){
try{
float _xl=this.py.getX()-this.px.getX();
float _yl=this.py.getY()-this.px.getY();
//_xl=Math.abs(_xl);
//_yl=Math.abs(_yl);
float _fl=(float)Math.sqrt(_xl*_xl+_yl*_yl);
return _fl;
}catch(Exception e){
return 0;
}
}
/**
* 求中点x
* @return float
*/
public float getCenterPointX(){
return (this.py.getX()+this.px.getX())/2;
}
/**
* 检查是否在一象限
* @return boolean true:yes false:no
*/
public boolean checkArea(){
try {
if(this.px.getX()>0&&this.px.getY()>0&&this.py.getX()>0&&this.py.getY()>0){
return true;
}
} catch (Exception e) {
// TODO: handle exception
}
return false;
}
/**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
MyLine l=new MyLine(2,2,-1,-1);
System.out.println(l.getCenterPointX());
System.out.println(l.getLineLength());
System.out.println(l.checkArea());
}
public Point getPx() {
return px;
}
public void setPx(Point px) {
this.px = px;
}
public Point getPy() {
return py;
}
public void setPy(Point py) {
this.py = py;
}
}
//代码没经过仔细测试,这就靠你了哈
public class MyLine {
private Point px;
private Point py;
public MyLine(float x1,float y1,float x2,float y2){
this.px=new Point();
this.py=new Point();
this.px.setX(x1);
this.px.setY(y1);
this.py.setX(x2);
this.py.setY(y2);
}
public MyLine(Point p1,Point p2){
this.px=p1;
this.py=p2;
}
class Point{
private float x;
private float y;
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
}
/**
* 求线段长
* @return
*/
public float getLineLength(){
try{
float _xl=this.py.getX()-this.px.getX();
float _yl=this.py.getY()-this.px.getY();
//_xl=Math.abs(_xl);
//_yl=Math.abs(_yl);
float _fl=(float)Math.sqrt(_xl*_xl+_yl*_yl);
return _fl;
}catch(Exception e){
return 0;
}
}
/**
* 求中点x
* @return float
*/
public float getCenterPointX(){
return (this.py.getX()+this.px.getX())/2;
}
/**
* 检查是否在一象限
* @return boolean true:yes false:no
*/
public boolean checkArea(){
try {
if(this.px.getX()>0&&this.px.getY()>0&&this.py.getX()>0&&this.py.getY()>0){
return true;
}
} catch (Exception e) {
// TODO: handle exception
}
return false;
}
/**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
MyLine l=new MyLine(2,2,-1,-1);
System.out.println(l.getCenterPointX());
System.out.println(l.getLineLength());
System.out.println(l.checkArea());
}
public Point getPx() {
return px;
}
public void setPx(Point px) {
this.px = px;
}
public Point getPy() {
return py;
}
public void setPy(Point py) {
this.py = py;
}
}
追问
这是什么
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询