package entities;
public class Product {
public String name;
public double price;
public int quantity;
public double totalValueInStock() {
return price * quantity;
}
public void addProducts(int quantity) {
this.quantity += quantity;
}
public void removeProducts(int quantity) {
this.quantity -= quantity;
}
public String toString() {
return name
+ ", $ "
+ String.format("%.2f", price)
+ ", "
+ quantity
+ " units, Total: $ "
+ String.format("%.2f", totalValueInStock());
}
}'
I thought I understood the difference between these basic topics but I could not explain the real difference between them ...
Note that: this.quantity += quantity;
, the assignment operator + = was used that says "this.quantity RECEIVES this.quantity + quantity".
But I can not see the difference between it and the arithmetic operator +, they would both do the same operation, right? I could not understand this "RECEIVE".
What would be the real difference between one and the other in a clear way, without saying what example: a += 2
means "a RECEIVE a + 2".
This I understood, if "a" is worth 10 the result of a + = 2 is 12 however, a + 2 also results in 12. Did you understand me?
Why use one and not another?