如果未达到销售目标,这是我打印消息的加班例外。
public class OverTimeException extends Exception {
int salesTarget;
public OverTimeException(int s) {
salesTarget = s;
}
String myPrint()
{
return "exception caught because sales target is " + salesTarget;
}
}
这是我想在 salesTarget 方法中使用异常的 Clerk 类。我的问题是如何将异常实现到 salesTarget 方法中?谢谢
public class Clerk extends Admin implements ClerkInterface {
final double payRate = 13.00;
final int salesTargetNum = 46;
//Member variables
private double unitSold;
//Constructor
public Clerk(String inName, String inId, double inHoursWorked,
double intkPay, double inAdmin_quota,double inUnitSold) {
super(inName, inId, inHoursWorked, intkPay, inAdmin_quota);
setUnitSold(inUnitSold);
}
//setUnitsSold method
private void setUnitSold(double inUnitSold) {
unitSold = inUnitSold;
}
//getUnitsSold
public double getUnitsSold(){
return unitSold;
}
//toString method
public String toString()
{
return " " + super.toString() + "Admin Quota " + getAdmin_quota() + "Units Sold" + getUnitsSold();
}
//method to confirm sales targets are made from ClerkInterface.
public void salesTarget() {
if(salesTargetNum >= unitSold){
System.out.println("Clerk has not meet sales target");
}
else
{
System.out.println("Clerk has meet sales target");
}
}
}//end Clerk