I am writing a simple inventory system for practice and I have an item class that holds these values:
private String name;
private int quantity;
private Integer ID;
private Double pricePerUnit;
private Double totalPrice;
I am writing the constructors for this class and I want everything except the name and quantity to be optional, as in the user can opt whether or not to input any data for those fields. Currently I have two constructors that look like this:
public Item(String name, int quantity)
{
this.name=name;
this.quantity=quantity;
}
public Item(String name, int quantity, Integer ID, Double pricePerUnit, Double totalPrice)
{
this(name, quantity);
this.ID=ID;
this.pricePerUnit=pricePerUnit;
this.totalPrice=totalPrice;
}
Is there any way I can make some of the arguments in the second constructor optional, or non-mandatory?
Thanks!