Basically I want my program to change the current price of an object with a new one, but I'm having trouble doing so. Here's my code:
//-----------------------------------------------------------------
// Updates the product's price.
//-----------------------------------------------------------------
public void setPrice(double newPrice)
{
this.newPrice = newPrice;
}
//-----------------------------------------------------------------
// Changes the price of the product from the collection.
//-----------------------------------------------------------------
public void changePrice(int prodID, double newPrice)
{
int index = findProduct(prodID);
if (index > -1)
collection[index].setPrice(newPrice);
else
System.out.println("The product having the ID number " + prodID
+ " was not found.\n");
}
System.out.print("\nEnter the ID number of product to modify: ");
idNum = userInput.nextInt();
System.out.print("\nWhat is the new price? ");
price = userInput.nextDouble();
userInput.nextLine();
data.changePrice(idNum, price);
The error I get from my program is:
Product.java:70: cannot find symbol
symbol : variable newPrice
location: class Product
this.newPrice = newPrice;
Am I coding this incorrectly or is there an alternative for what I hope to acheive?