?? sphere.java
字號:
import java.util.Observable;
/**
*
* <p>Title: The Model part of Application</p>
* <p>Description: This class represents an observable object,
* or "data" in the model-view paradigm. It can be subclassed to represent
* an object that the application wants to have observed. </p>
* <p>Copyright: Copyright (c) 2005</p>
* @author Smart Lee
* @version 1.1
*/
public class Sphere extends Observable {
// 定義球體半徑
private double sphereRadius;
// 定義球體體積
private double sphereVolume;
// 定義球體表面積
private double sphereSuArea;
/**
* 根據球體半徑值設置球體三個屬性值
* @param sphereRadius double
*/
public void setRadius (double sphereRadius) {
this.sphereRadius = sphereRadius;
this.sphereVolume = 4 * Math.PI * Math.pow(sphereRadius, 3) / 3;
this.sphereSuArea = 4 * Math.PI * Math.pow(sphereRadius, 2);
//變化后通知視圖做相應變化
setChanged();
notifyObservers();
}
/**
* 根據球體體積值設置球體三個屬性值
* @param sphereVolume double
*/
public void setVolume(double sphereVolume) {
this.sphereVolume = sphereVolume;
this.sphereRadius = Math.pow(3 * sphereVolume / (4 * Math.PI), 1 / 3.0);
this.sphereSuArea = 3 * sphereVolume / sphereRadius;
setChanged();
notifyObservers();
}
/**
* 根據球體表面積值設置球體三個屬性值
* @param sphereSuArea double
*/
public void setSuArea(double sphereSuArea) {
this.sphereSuArea = sphereSuArea;
this.sphereRadius = Math.pow(sphereSuArea / (4 * Math.PI), 1 / 2.0);
this.sphereVolume = sphereSuArea * sphereRadius /3;
setChanged();
notifyObservers();
}
/**
* 取得球體半徑值
* @return double
*/
public double getRadius() {
return sphereRadius;
}
/**
* 取得球體體積值
* @return double
*/
public double getVolume() {
return sphereVolume;
}
/**
* 取得球體表面積值
* @return double
*/
public double getSuArea() {
return sphereSuArea;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -