cylindertest.java

来自「《Java面向对象程序设计》例子源代码.轻松学习书本.」· Java 代码 · 共 27 行

JAVA
27
字号
//CylinderTest.java
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class CylinderTest {
   public static void main( String[] args ){
      Cylinder cylinder = new Cylinder( 12, 23, 2.5, 5.7 );
      String output = "X coordinate is " + cylinder.getX() +
         "\nY coordinate is " + cylinder.getY() + "\nRadius is " + 
         cylinder.getRadius() + "\nHeight is " + cylinder.getHeight();
      cylinder.setX( 35 );   		//调用继承自Point3中的setX方法       
      cylinder.setY( 20 );         	//调用继承自Point3中的setY方法 
      cylinder.setRadius( 4.25 );   //调用继承自Circle3中的setRadius方法
      cylinder.setHeight( 10.75 );  
      output += 
         "\n\nThe new location, radius and height of cylinder are\n" + 
         cylinder.toString();
      DecimalFormat twoDigits = new DecimalFormat( "0.00" );
	   output += "\n\nDiameter is " + 
         twoDigits.format( cylinder.getDiameter() );
      output += "\nCircumference is " +
         twoDigits.format( cylinder.getCircumference() );
      output += "\nArea is " + twoDigits.format( cylinder.getArea() );
      output += "\nVolume is " + twoDigits.format( cylinder.getVolume() );
      JOptionPane.showMessageDialog( null, output ); // display output
      System.exit( 0 );
   } 
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?