⑴ java定义一个点类Point, 具备坐标系中的横坐标x, 和纵坐标y, 并实现如下功能:
Point类
publicclassPoint{
privatefloatx;
privatefloaty;
publicPoint(floatx,floaty){
this.x=x;
this.y=y;
}
publicfloatgetX(){
returnx;
}
publicvoidsetX(floatx){
this.x=x;
}
publicfloatgetY(){
returny;
}
publicvoidsetY(floaty){
this.y=y;
}
publicfloatdistanceToOrigin(){
return(float)Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2));
}
publicfloatdistanceToOther(intx,inty){
return(float)Math.sqrt(Math.pow(this.x-x,2)+Math.pow(this.y-y,2));
}
publicfloatdistanceToOther(Pointpoint){
return(float)Math.sqrt(Math.pow(this.x-point.x,2)+Math.pow(this.y-point.y,2));
}
}
测试类
publicclassTestPoint{
publicstaticvoidmain(String[]args){
Pointp1=newPoint(3,5);
Pointp2=newPoint(7,8);
System.out.println(p1.distanceToOrigin());
System.out.println(p2.distanceToOrigin());
System.out.println(p1.distanceToOther(20,30));
System.out.println(p2.distanceToOther(20,30));
System.out.println(p1.distanceToOther(p2));
}
}
⑵ 用JAVA定义一个描述点的point类.它有两个成员变量:横坐标x,纵坐标y
实现思路就是有一个类Point,之后这个类有两个私有成员变量,之后可以通过set和get方法进行赋值和数值读取:
public
class
Point
{
private
String
x;
private
String
y;
/**
*
默认构造函数
*/
public
Point(){
}
/**
*有x和y的构造方法。
*/
public
Point(String
x,String
y){
this.x=x;
this.y=y;
}
public
String
getX()
{
return
x;
}
public
void
setX(String
x)
{
this.x
=
x;
}
public
String
getY()
{
return
y;
}
public
void
setY(String
y)
{
this.y
=
y;
}
}
⑶ 定义一个Java类Point,用来描述平面直角坐标系中点的坐标。
需要两个类,一个Point,一个Test.这两个类,是调用和被调用的关系,Point被Test调用.
关系说好了,就是类具体实现的问题.
Point.java
这个类近似于常说的工具类或者辅助类.这里面既然对坐标操作就应该定义全局的x,y变量.其他的就是
方法.
public void setXY(double x,double y){
this.x = x;
this.y = y;
}
set方法就是类似于这样,把传过来的值赋给定义的全局.而get方法里面很显然就是return.
而测试类就是调用Point的过程.
⑷ java,设计一个点类Point,
publicclassPoint{
privateintx;
privateinty;
publicvoidsetX(intx){
this.x=x;
}
publicvoidsetY(inty){
this.y=y;
}
publicintgetX(){
returnx;
}
publicintgetY(){
returny;
}
publicStringtoString(){
return"["+x+","+y+"]";
}
}
⑸ java编写一个表示坐标点的类(Point),其中包含x和y两个坐标点的值,并且包含一个打印出该点坐标的方法
publicclassPoint{
privateintx;
privateinty;
publicgetX(){returnx;}
publicgetY(){returny;}
publicsetX(intx){this.x=x;}
publicsetY(inty){this.y=y;}
publicPoint(intx,inty){
this.x=x;
this.y=y;
}
publicdisplayPoint(){
//输出坐标
System.out.println("x:"+x+",y:"+y);
}
publicstaticdistancePoint(Pointp1,Pointp2){
//计算坐标距离
inta=p1.getX()-p2.getX();
intb=p1.getY()-p2.getY();
returnMath.sqrt(a*a+b*b);
}
}
⑹ Java要求设计一个“坐标点”类(Point)
public class Point {
double x1,x2,y1,y2;
double d,x3,y3;
Point(double x1,double y1,double x2,double y2){//构造方法
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
void TestPoint(){//求距离和中点坐标
x3 = (x1 + x2)/2;
y3 = (y1 + y2)/2;
d = Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
System.out.println("(" + x3 + ","+ y3 + ")");
System.out.println(d);
}
public static void main(String[] args) {
Point p = new Point(1,1,2,2);
p.TestPoint();
}
}
⑺ JAVA写设计一个Point类,私有成员变量pointX,pointY公有成员函数void se
你好,按照描述,个人认为要的是如下
"
public class Point{
// 封装属性
private int pointX;
private int pointY;
public void setPointX(int pointx){
this.pointX = pointX;
}
// 暴露公共方法访问私有属性
public int getPointX(){
return this.pointX;
}
public void setPointY(int pointY){
this.pointY = pointY;
}
public int getPointY(){
return this.pointY;
}
}
"
效果图
⑻ java定义一个点类(point),包含x,y坐标数据成员,显示函数(show)和计算面积(getarea)的函数成员
import java.lang.Math.*;
class point {
int x;
int y;
void show()
{
//don't know the purpose for this one.
}
double getarea()
{
return Math.sqrt(y*y + x*x);
}
}
class circirl extends point
{
int r;
double getarea(int r)
{
return (3.14*r*r);
}
}
public class line {
point point1;
point point2;
int getarea(point point1, point point2)
{
int length = point1.x - point2.x;
int width = point1.y - point2.y;
return Math.abs(width)*Math.abs(length);
}
double length(point point1, point point2)
{
int length = point1.x - point2.x;
int width = point1.y - point2.y;
double leng_point = Math.sqrt(length*length + width*width);
return leng_point;
}
public static void main(String[] args) {
line line =new line();
// circirl circirl = new circirl();
line.point1 = new point();
line.point1.x= 40;
line.point1.y= 40;
line.point2 = new point();
line.point2.x= 70;
line.point2.y= 90;
int len = line.getarea(line.point1,line.point2);
System.out.println("the len for the two point is "+len);
double sqre = line.length(line.point1,line.point2);
System.out.println("the squre for the two point is "+sqre);
}
}