?? test.java
字號(hào):
// 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賦值為子類計(jì)件工人對p的引用
output += ref.toString() + " 工資 ¥" +
precision2.format( ref.earnings() ) + "\n" +
p.toString() + " 工資 ¥" +
precision2.format( p.earnings() ) + "\n";
ref = h; // 把父類的引用ref賦值為子類計(jì)時(shí)工人對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 );
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -