943,993 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1854
  • Java RSS
Jun 22nd, 2007
0

Errors I can't resolve!!!

Expand Post »
I can't seem to resolve these errors. I have had people compile these codes on their computers with no problem, but I keep getting errors...can anyone help????

Here are the errors:
cannot find symbol method setItemNumber(java.lang.String)
cannot find symbol method setProductName(java.lang.String)
cannot find symbol method setNumOfUnitsInStock(int)
cannot find symbol method getItemNumber()
cannot find symbol method getProductName()
cannot find symbol method getNumOfUnitsInStock()

Here is the Product Code:
Java Syntax (Toggle Plain Text)
  1. public class Product
  2. {
  3. public String movieName; //movie name
  4. private double price; //movie price
  5. private int units; //number in inventory
  6. private String prodID; //product ID number
  7. public Product() { }
  8. public void setMovieName(String _movieName)
  9. {
  10. movieName = _movieName;
  11. }
  12. public void setPrice(double _price)
  13. {
  14. price = _price;
  15. }
  16. public void setUnits(int _units)
  17. {
  18. units = _units;
  19. }
  20. public void setProductID(String _prodID)
  21. {
  22. prodID = _prodID;
  23. }
  24. public String getMovieName()
  25. {
  26. return movieName;
  27. }
  28. public double getPrice()
  29. {
  30. return price;
  31. }
  32. public int getUnits()
  33. {
  34. return units;
  35. }
  36. public String getProductID()
  37. {
  38. return prodID;
  39. }
  40. public double getTotalValue()
  41. {
  42. return units * price;
  43. }
  44. }


Here is the Inventory Code:

Java Syntax (Toggle Plain Text)
  1. import java.util.Arrays;
  2. public class Inventory
  3. {
  4. static public final int MAX_NUM_OF_PRODUCTS = 10;
  5. private Product products[] = new Product[MAX_NUM_OF_PRODUCTS];
  6. private int numOfProducts;
  7. public Inventory()
  8. {
  9. }
  10. public double getInventoryValue()
  11. {
  12. double inventoryValue = 0;
  13. for (int i = 0; i < products.length; i++)
  14. {
  15. Product product = products[i];
  16. if (product != null)
  17. {
  18. inventoryValue += product.getTotalValue();
  19. }
  20. }
  21. return inventoryValue;
  22. }
  23. public Product[] getSortedInventoryList()
  24. {
  25. Arrays.sort(products, 0, numOfProducts) ;
  26. return products;
  27. }
  28. public void addProduct(int index,Product product)
  29. {
  30. products[index] = product;
  31. numOfProducts++;
  32. }
  33. public int getNumOfProducts()
  34. {
  35. return numOfProducts;
  36. }
  37. }



Here is the TestDriver:

Java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;
  2. import java.text.NumberFormat;
  3. public class TestDriver
  4. {
  5. private Inventory inventory;
  6.  
  7. public TestDriver()
  8. {
  9. inventory = new Inventory();
  10. }
  11.  
  12. public void acceptInput()
  13. {
  14. Scanner keyInput = new Scanner(System.in);
  15. int counter = 0;
  16. while (true)
  17. {
  18. if (counter > Inventory.MAX_NUM_OF_PRODUCTS)
  19. {
  20. break;
  21. }
  22.  
  23. System.out.print("Enter product Name (enter stop to quit):");
  24. String productName = keyInput.next();
  25. if (productName.equalsIgnoreCase("STOP"))
  26. {
  27. return;
  28. }
  29. System.out.print("Enter item number:");
  30. String itemNumber = keyInput.next();
  31. System.out.print("Enter number of units in stock:");
  32. int numUnitsInStock;
  33. while ((numUnitsInStock = keyInput.nextInt()) <= 0)
  34. {
  35. System.out.print("Please enter a valid number:");
  36. }
  37.  
  38. System.out.print("Enter price:");
  39. double price;
  40. while ((price = keyInput.nextDouble()) <= 0)
  41. {
  42. System.out.print("Please enter a valid number:");
  43. }
  44. Product product = new Product();
  45. product.setItemNumber(itemNumber);
  46. product.setProductName(productName);
  47. product.setNumOfUnitsInStock(numUnitsInStock);
  48. product.setPrice(price);
  49. inventory.addProduct(counter, product);
  50. counter++;
  51. }
  52. }
  53.  
  54. public void displayOutput()
  55. {
  56. NumberFormat moneyFormat = NumberFormat.getCurrencyInstance();
  57. Product products[] = inventory.getSortedInventoryList();
  58. for (int i = 0; i < inventory.getNumOfProducts(); i++)
  59. {
  60. Product product = products[i];
  61. System.out.printf("Item number: %s\n", product.getItemNumber());
  62. System.out.printf("Product Name: %s\n", product.getProductName());
  63. System.out.printf("Number of units in stock: %d\n", product.getNumOfUnitsInStock());
  64. System.out.printf("Price: %s\n", moneyFormat.format(product.getPrice()));
  65. System.out.printf("Total value: %s\n", moneyFormat.format(product.getTotalValue()));
  66. }
  67.  
  68. System.out.printf("Total Inventory value: %s\n", moneyFormat.format(inventory.getInventoryValue()));
  69. }
  70.  
  71. static public void main(String[] args)
  72. {
  73. TestDriver driver = new TestDriver();
  74. driver.acceptInput();
  75. driver.displayOutput();
  76. }
  77. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
4zlimit is offline Offline
5 posts
since Jun 2007
Jun 22nd, 2007
0

Re: Errors I can't resolve!!!

I just did a Ctrl+F in this thread for following 3 functions:
cannot find symbol method setItemNumber(java.lang.String)
cannot find symbol method setProductName(java.lang.String)
cannot find symbol method setNumOfUnitsInStock(int)

I didn't see their definition..
That should be the problem.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: A few questions regarding video, images and audio
Next Thread in Java Forum Timeline: Tomcat





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC