⑴ 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);
}
}