public class Asset
{
//*****************************************************
// Variables
//*****************************************************
private String assetID;
private double cost;
private int lifeExpectancy;
private String employeeID;
private String purchaseDate;
private String description;
private int calcAge;
private boolean outDated;
//******************************************************
// Special constructor that sets assetID and employeeID
//******************************************************
public Asset(String assetID, String employeeID)
{
this.assetID = assetID;
this.employeeID = employeeID;
}
//******************************************************
// Special constructor that takes and sets all data
//******************************************************
public Asset(double cost, int lifeExpectancy, String purchaseDate, String description, String assetID, String employeeID, int calcAge, boolean outDated )
{
this.cost = cost;
this.lifeExpectancy = lifeExpectancy;
this.purchaseDate = purchaseDate;
this.description = description;
this.assetID = assetID;
this.employeeID = employeeID;
this.calcAge = calcAge;
this.outDated = outDated;
}
//************************************************
// Typical getters for all data
//************************************************
public String getAssetID() {
return assetID;
}
public double getCost() {
return cost;
}
public int getLifeExpectancy() {
return lifeExpectancy;
}
public String getEmployeeID() {
return employeeID;
}
public String getPurchaseDate() {
return purchaseDate;
}
public String getDescription() {
return description;
}
//************************************************
// Special setters for assetID and employeeID that
// guarantees the two data are always stored in
// upper case.
//***********************************************
public void setAssetID(String assetID)
{
assetID = assetID.toUpperCase();
}
public void setEmployeeID(String employeeID)
{
employeeID = employeeID.toUpperCase();
}
//*****************************************************
// Typical setters for all data
//*****************************************************
public void setCost(double cost) {
this.cost = cost;
}
public void setLifeExpectancy(int lifeExpectancy) {
this.lifeExpectancy = lifeExpectancy;
}
public void setPurchaseDate(String purchaseDate) {
this.purchaseDate = purchaseDate;
}
public void setDescription(String description) {
this.description = description;
}
//*****************************************************************
// Method called calcAge that accepts the current date in a String
// formatted as mm/dd/yyyy, and returns the age.
//*****************************************************************
public int calcAge(String purchaseDate)
{
String stringYear = purchaseDate.substring(1);
int intDate = Integer.parseInt(stringYear);
return (2013) - intDate;
}
//******************************************************************
// Predicate method to decide if the component needs to be replaced
//******************************************************************
public boolean outdated()
{
if (calcAge(purchaseDate) > lifeExpectancy)
{
return true;
}
else
{
return false;
}
}
//*****************************************************************************************
// Print the data
//*****************************************************************************************
public String printData()
{
return "Asset Number: " + assetID + "\n" + "Description: " + description + "\n" +
"Cost: " + cost + "\n" + "Purchase on: " + purchaseDate +
"\n" + "Assigned to Employee ID: " + "Life Expectancy: " +
lifeExpectancy + "\n" + "Age: " + calcAge(purchaseDate) + "Needs Replacement? " +
outdated();
}
}