📄 factorysystem.java
字号:
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
public void displayMenu()
{
//-------------------------------------------------------------------
//函数功能:显示菜单功能起提示作用。
//函数参数:无。
//------------------------------------------------------------------------
System.out.println("0:Quit");
System.out.println("1:Calculate payroll");
System.out.println("2:Search for employee");
}
}
//=================================================================================
//程序启动类。
//=================================================================================
public class FactorySystem
{
private MenuChoice menud=null;
private sheffield.EasyReader kbd=null;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
public static void main(String [] args)
{
//---------------------------------------------------------------------------
//函数功能:启动程序。变量factorysys为启动类的对象。
//factorysys.runfactorySystem()运行程序功能。
//--------------------------------------------------------------------------
FactorySystem factorysys = new FactorySystem();
if(factorysys==null)
{
System.out.println("FactorySystem对象内存分配失败!!!");
System.exit(0);
}
try
{
factorysys.runfactorySystem();
}
catch(NullPointerException f)
{
//System.out.println("aaaaaa");
f.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
public void runfactorySystem() throws NullPointerException,Exception
{
//-----------------------------------------------------------------------------
//函数功能:启动运行菜单对象。menud为菜单类对象。对象kbd在此处为功能是
//接受一个int型的变量。menud.setChoiceNumber(choicenumber)设置菜单的选择
//menud.choiceMenu()运行菜单。
//-----------------------------------------------------------------------------
menud= new MenuChoice();
kbd= new sheffield.EasyReader();
System.out.println("Welcome to the factory syatem");
//menud.displayMenu();
while(true)
{
if(kbd==null || menud==null)
throw new NullPointerException();
menud.displayMenu();
int choicenumber=kbd.readInt("number of items(MAX 20):");
if(choicenumber==0)
{
System.out.println("Goodbye!");
System.out.println("Hope you enjoyed the factory system.");
System.exit(0);
}
menud.setChoiceNumber(choicenumber);
try{
menud.choiceMenu();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
//================================================================================
//职员类,有两个属性name、position初始化为unknow。有两个方法 getname()返回对象的name;
//方法showpayroll打印对象的信息.
//=================================================================================
class Employee
{
public static int iOrder=0;
protected int everyOrder=0;
protected String sName="unknow";
protected String sPosition="unknow";
public Employee(String name,String position)
{
iOrder++;
everyOrder=iOrder;
this.sName=name;
this.sPosition=position;
}
public String getName()
{
//------------------------------------------------------------------
//函数功能:返回对象的名字.
//参数:无.
//-------------------------------------------------------------------
return sName;
}
public void calculatePayment()
{
}
public String getPosition()
{
//-------------------------------------------------------------------
//
//------------------------------------------------------------------------
return sPosition;
}
public void showPayroll()
{
//-----------------------------------------------------------------------
//函数功能:打印对象信息.
//
//------------------------------------------------------------------------
System.out.print(""+everyOrder+" :("+sName+" "+sPosition+")");
}
}
//===================================================================================
//类WagedEmployee是employee的子类,它有三个属性dHoursworked是工作的时间数,dPaymentPerHour是每小时
//工作的报酬.payment是每周的报酬.有三个方法.方法setTimeAndPaymentPerHour设置对象的工作
//时间和每小时的工作报酬.方法calculatePayment根据对象的每周的工作时间和每小时的工作报酬
//计算出一周的报酬.方法showPayroll覆盖父类showPayroll函数打印对象的信息.
//===================================================================================
class WagedEmployee extends Employee
{
protected double dHoursworked=-1f;
protected double dPaymentPerHour=-1f;
protected double payment=-1f;
public WagedEmployee(String name,String position,double hour,double paymentperhour)
{
super(name,position);
this.dHoursworked=hour;
this.dPaymentPerHour=paymentperhour;
}
public void setTimeAndPaymentPerHour(double hour,double paymentperhour)
{
//----------------------------------------------------------------------
//函数功能:设置对象的每周工作时间和每小时的工作报酬.
//----------------------------------------------------------------------
this.dHoursworked=hour;
this.dPaymentPerHour=paymentperhour;
}
public void calculatePayment()
{
//---------------------------------------------------------------------------
//函数功能:计算WagedEmployee的每周工资.
//---------------------------------------------------------------------------
payment=dPaymentPerHour*dHoursworked;
}
public void showPayroll()
{
//--------------------------------------------------------------------------
//覆盖父类showPayroll函数打印对象的信息.
//-----------------------------------------------------------------------------
payment=dPaymentPerHour*dHoursworked;
System.out.println(""+everyOrder+" :("+sName+" "+sPosition+","+dHoursworked+" hours@"+dPaymentPerHour+" per hour ="+payment+")");
}
}
//================================================================================
//类Manager是employee的子类,它有一个属性dWeeklyPayment是Manager对象的每周工资,有一个方法
//showPayroll()覆盖父类showPayroll函数打印对象的信息.
//=================================================================================
class Manager extends Employee
{
double dWeeklyPayment=-1;
public Manager(String name,String position,double weeklypayment)
{
super(name,position);
this.dWeeklyPayment=weeklypayment;
}
public void showPayroll()
{
//------------------------------------------------------------------------
//覆盖父类showPayroll函数打印对象的信息.
//-------------------------------------------------------------------------
System.out.println(""+everyOrder+" :("+sName+" "+sPosition+","+dWeeklyPayment+")");
}
}
class SalesPerson extends WagedEmployee
{
private int isaleProductNumber=-1;
private double dCommission=-1;
public SalesPerson(String name,String position,double hour,double paymentperhour,
int saleproductnumber,double commission)
{
super(name,position,hour,paymentperhour);
this.isaleProductNumber=saleproductnumber;
this.dCommission=commission;
}
public void calculatePayment()
{
//---------------------------------------------------------------------------
//函数功能:计算WagedEmployee的每周工资.
//---------------------------------------------------------------------------
payment=dPaymentPerHour*dHoursworked+dCommission*isaleProductNumber;
}
public void setSaleProductNumberAndcommission(int salenumber,double commission)
{
this.isaleProductNumber=salenumber;
this.dCommission=commission;
}
public void showPayroll()
{
//--------------------------------------------------------------------------
//覆盖父类showPayroll函数打印对象的信息.
//-----------------------------------------------------------------------------
payment=dPaymentPerHour*dHoursworked+dCommission*isaleProductNumber;
System.out.println(""+everyOrder+" :("+sName+" "+sPosition+","+dHoursworked+" hours@"
+dPaymentPerHour+" per hour "+isaleProductNumber+"sales @"+dCommission+"commission="+payment+")");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -