導航:首頁 > 編程語言 > java點類

java點類

發布時間:2023-06-05 21:31:21

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點類相關的資料

熱點內容
情人節網站源碼 瀏覽:305
設備管理命令行 瀏覽:726
吃哺乳期的電影 瀏覽:190
把加密zip變成文件夾 瀏覽:213
linuxrecv阻塞 瀏覽:46
java模擬cookie 瀏覽:175
主角變身女收女的變百小說 瀏覽:758
粉筆教育app從哪裡看做過的題 瀏覽:391
app數據包在哪裡找到 瀏覽:923
百煉成仙綠帽改編1-11 瀏覽:109
女主和一對雙胞胎兄弟 瀏覽:437
刀劍神域小說TXT 瀏覽:1000
php獲取文件地址 瀏覽:578
linuxsed替換字元 瀏覽:413
如何填寫國家反詐中心app注冊使用 瀏覽:792
日本影視網站 瀏覽:933
伺服器點亮埠以後有什麼特徵 瀏覽:980
51單片機定時器pwm 瀏覽:685
民國修真 瀏覽:386
php數組作為參數傳遞 瀏覽:991