首先两个大字:莫慌
你题目的需求,我都一对一的写在注释中了,请参考~
代码如下:
package com.ch11;
//圆环类Ruanhuan 不应该是Yuanhuan么?
public class Ruanhuan {
private double nR; //内半径nR
private double wR; //外半径wR
public double getnR() {
return nR;
}
public void setnR(double nR) {
this.nR = nR;
}
public double getwR() {
return wR;
}
public void setwR(double wR) {
this.wR = wR;
}
@Override
public String toString() {
return "Ruanhuan(圆环) [nR(内半径)=" + nR + ", wR(外半径)=" + wR + "]";
}
//构造方法Ruanhuan(double nr,double wr)
public Ruanhuan(double nr,double wr){
this.nR = nr;
this.wR = wr;
}
public static void main(String[] args) {
// /在main()方法中构造圆环对象
Ruanhuan rh = new Ruanhuan(3, 6);
//并显示输出getNr()、getWr()、toString()的调用结果
System.out.println("内环是:"+rh.getnR());
System.out.println("外环是:"+rh.getwR());
System.out.println(rh.toString());
}
}
运行结果如下:
|