So here's my code :
public class Shoe {
String brandName;
double shoePrice;
int shoesInStock;
double totalRevenue;
public Shoe(String name, double price, int shoesAvailable){
brandName = name;
shoePrice = price;
shoesInStock = shoesAvailable;
}
public void shoeSold(){
totalRevenue = totalRevenue + shoePrice;
System.out.println("Your new total revenue is " + totalRevenue + "$");
}
public static void main(String[] args){
Shoe yeezy = new Shoe("adidas", 75, 10);
Shoe airforce = new Shoe("nike", 140, 15);
yeezy.shoeSold();
airforce.shoeSold();
}
}
Output :
Your new total revenue is 75.0$
Your new total revenue is 140.0$
Why am I not able to make the totalRevenue variable update and not return to 0 each time, I'm new to java and this was quite an easy task in python I know that java is an oop language but is there no way to make a variable store the value and not return to 0 ? Thanks in advance !