⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 中国水利水电出版社java程序设计教程,附源码
💻 JAVA
字号:
// Test.java
//Employee主程序模块
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Test {
   public static void main( String args[] )
   {
      Employee ref;  // ref为Employee引用
      String output = "";

      Boss b = new Boss( "史", "季华", 800.00 );
      CommissionWorker c =
         new CommissionWorker( "张", "雪",
                               400.0, 3.0, 150);
      PieceWorker p =
         new PieceWorker( "包", "利", 2.5, 200 );
      HourlyWorker h =
         new HourlyWorker( "科", "鹏", 13.75, 40 );

      DecimalFormat precision2 = new DecimalFormat( "0.00" );

      ref = b;  // 把父类的引用ref赋值为子类Boss对b的引用
      output += ref.toString() + " 工资 ¥" +
                precision2.format( ref.earnings() ) + "\n" +
                b.toString() + " 工资 ¥" +
                precision2.format( b.earnings() ) + "\n";
   
      ref = c;  // 把父类的引用ref赋值为子类普通员工对c的引用
      output += ref.toString() + " 工资 ¥" +
                precision2.format( ref.earnings() ) + "\n" +
                c.toString() + " 工资 ¥" +
                precision2.format( c.earnings() ) + "\n";
   
      ref = p;  // 把父类的引用ref赋值为子类计件工人对p的引用
      output += ref.toString() + " 工资 ¥" +
                precision2.format( ref.earnings() ) + "\n" +
                p.toString() + " 工资 ¥" +
                precision2.format( p.earnings() ) + "\n";
   
      ref = h;  // 把父类的引用ref赋值为子类计时工人对h的引用
      output += ref.toString() + " 工资 ¥" +
                precision2.format( ref.earnings() ) + "\n" +
                h.toString() + " 工资 ¥" +
                precision2.format( h.earnings() ) + "\n";

      JOptionPane.showMessageDialog( null, output,
         "Demonstrating Polymorphism",
         JOptionPane.INFORMATION_MESSAGE );
      System.exit( 0 );
   }
}

⌨️ 快捷键说明

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