0

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?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by BestJewSinceJC
0

well you should have a product class that has a price field and have a set and get method. This would allow you to easily change a product's price from any other class

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.