Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

point_toa do

/**

* @(#)point.java

*

*

* @author

* @version 1.00 2009/10/23

*/

import javax.swing.JOptionPane;

public class point {

private String tendiem;

private float tungdo;

private float hoanhdo;

/* phuong thuc set*/

public void settendiem(String s){

tendiem=s;

}

public void sethoanhdo(float y){

hoanhdo=y;

}

public void settungdo(float x){

tungdo=x;

}

/* phuong thuc get*/

public String gettendiem(){

return tendiem;

}

public float gethoanhdo(){

return hoanhdo;

}

public float gettungdo(){

return tungdo;

}

/* ham khoi tao mac dinh*/

public point() {

settendiem("A");

sethoanhdo(0);

settungdo(0);

}

/* ham khoi tao 2 tham so*/

public point(float a,float b){

settendiem("noname");

sethoanhdo(a);

settungdo(b);

}

/* ham khoi tao 3 tham so*/

public point(String s,float a,float b){

settendiem(s);

sethoanhdo(a);

settungdo(b);

}

/* ham khoi tao 1 tham so co kieu la doi tuong */

public point(point x){

tendiem=x.tendiem;

hoanhdo=x.hoanhdo;

tungdo=x.tungdo;

}

/* ham nhap */

public void nhap(){

String strs;

float fa;

float fb;

strs=JOptionPane.showInputDialog(" nhap ten diem:");

fa=Float.parseFloat(JOptionPane.showInputDialog(null,"nhap hoanh do:"));

fb=Float.parseFloat(JOptionPane.showInputDialog(null,"nhap tung do:"));

this.tendiem=strs;

this.tungdo=fb;

this.hoanhdo=fa;

}

/* ham hien thi*/

public void show(){

JOptionPane.showMessageDialog(null,"point:"+ gettendiem()+"("+gethoanhdo()+","+gettungdo()+")");

}

/*ham main*/

public static void main(String args[]){

/* mac dinh*/

point obj1=new point();

obj1.show();

/* hai tham so*/

point obj2=new point(2,3);

obj2.show();

/* 3 tham so*/

point obj3=new point("B",2,3);

obj3.show();

/* 1 tham so*/

point obj4=new point("B",5,8);

point obj5=new point(obj4);

obj5.tendiem="B";

obj5.hoanhdo=5;

obj5.tungdo=8;

obj5.show();

point obj6=new point();

obj6.nhap();

obj6.show();

}

}

Bạn đang đọc truyện trên: Truyen247.Pro