You need to add instance variables for the four fields, then use these in your code. So in the constructor you would be setting the values for these instance variables (these values will be sent to the constructor generally from another class).
private String description;
private String dept;
private int units;
private double price;
public PetStoreInventory(String s, String d, int units, double p) {
this.description = s;
this.dept = d;
this.units = units;
this.price = p;
}
public void setDescription( String s){
// set instance var equal to the passed parameter
this.description = s;
}
public void setDepartment( String d){
this.dept = d;
}
public void setUnitsOnHand ( int units){
this.units = units;
}
public void setPrice ( double p ){
this.price = p;
}
public String getDescription(){
return description; // return the instance var
}
public String getDepartment(){
return dept;
}
public int getUnitsOnHand(){
return units;
}
public double getPrice(){
return price;
}
public double calcTotalValue(){
double totalVal = 0.0; //initalise a new variable
/* the next line must calculate the total using the instance
variables created at the beginning.
*/
totalVal =?? //to be completed as it is an assignment
return totalVal;
}
Only the line ‘totalVal = ??’ needs to be completed. Follow the question and use the instance variables and let me know if you need any more help!