是第一个程序的加强版本,加入了BOSS功能

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

import javax.swing.*;

public class AdminHour

{

public static void main(String[] args)

{

Emplogee[] staff = new Emplogee[3];

String input = JOptionPane.showInputDialog

("how much money for A take");

int k = Integer.parseInt(input);

input = JOptionPane.showInputDialog

("how much money for B take");

int k1 = Integer.parseInt(input);

input = JOptionPane.showInputDialog

("how much money for C take");

int k2 = Integer.parseInt(input);

input = JOptionPane.showInputDialog

("How much add ");

double add = Integer.parseInt(input);

input = JOptionPane.showInputDialog

("how much money for zg take");

int zgmoney = Integer.parseInt(input);

input = JOptionPane.showInputDialog

("how much money for zg add");

int zgadd = Integer.parseInt(input);

staff[0] = new Emplogee("A",k );

staff[1] = new Emplogee("B",k1);

staff[2] = new Emplogee("C",k2);

Manager boss = new Manager("D",zgmoney);

boss.setBonus(zgadd);

staff[3] = boss;

for(int i = 0;i < staff.length; i++)

staff[i].getAdd(add);

for(int i = 0;i < staff.length; i++)

{Emplogee e = staff[i];

System.out.println("name=" + e.getName() + "\nOmoney=" + e.getOmoney() + "\nNmoney=" + e.getNmoney());

}

}

}

class Emplogee

{

public Emplogee (String n ,double s)

{ name = n;

money = s;

}

public String getName()

{

return name;

}

public double getOmoney()

{

return money;

}

public double getNmoney()

{

return Hadd;

}

public void getAdd(double byPercent)

{

double raise = money * byPercent / 100;

Hadd = raise + money;

}

private String name;

private double money;

private double Hadd;

}

class Manager extends Emplogee

{

/**

@param n the employee's name

@param s the onmeny

*/

public Manager(String n, double s)

{

super(n, s);

bonus = 0;

}

public double getSalary()

{

double baseSalary = super.getOmoney();

return baseSalary + bonus;

}

public void setBonus(double b)

{

bonus = b;

}

private double bonus;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航