I have a class called receipt and one of the attributes is an array item[] items; and I have a method addItem (string name , int quantity , double price). My question is how can I add these parameters to the array items[]? And how do I check if the quantity is more than 0?
Whats the code? Is my question clear?
Hers is my code:
public boolean addItem(String name, int quantity,double price){
if(quantity <= 0){
System.out.println("Item wasnt added");
return false;}
else{
item [nItem++];//here is the problem
}
}
new Item(variable1, variable2, and_so_on)might do the magic.itemclass, then add it to the array using an assignment. Both of these things are missing.if (item.length < nItems)...