Java编程 求高手指教

作者在 2010-04-12 19:11:32 发布以下内容

用java   编写一个代表圆柱体的Cylinder类,该类是Circle类的子类。Cylinder类包括圆柱体的高度变量height以及计算圆柱体的体积方法volume()和计算表面积的方法surfaceArea()

求高手帮助  !

默认分类 | 阅读 714 次
文章评论,共2条
myhnuhai
2010-04-15 13:30
1
import javax.swing.JOptionPane;<br />
<br />
public class Circle {<br />
&nbsp; &nbsp; &nbsp; &nbsp; final double PI = 3.14159;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; public static void main(String[] args) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String number = JOptionPane<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .showInputDialog(&quot;Please enter the underside radius !&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String number1 = JOptionPane.showInputDialog(&quot;Enter the height!&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int n = Integer.parseInt(number);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int m = Integer.parseInt(number1);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cylinder(n, m);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; public static void Cylinder(int circle, int height) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; final double PI = 3.14159;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double volume = PI * Math.pow(circle, 2) * height;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.print(&quot;The volume is &quot; + volume + &quot;\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double surfaceArea = 2 * PI * circle * height;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.print(&quot;The&nbsp;&nbsp;area is &quot; + surfaceArea);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
}
asi88888520(作者)
2010-04-15 18:29
2
<div class="quote"><span class="q"><b>myhnuhai</b>: import javax.swing.JOptionPane;<br />
<br />
public class Circle {<br />
&nbsp; &nbsp; &nbsp; &nbsp; final double PI = 3.14159;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; public static void main(String[] args) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String number = JOpti</span></div>谢谢啊!你用的方法我还没有学到那儿! 不过真不错这程序!
游客请输入验证码
文章分类