I can 't resolve these errors....

Here is my code:

import java.util.Scanner;

import java.text.NumberFormat;

public class TestDriver

{

private Inventory inventory;

public TestDriver()

{

inventory = new Inventory();

}

public void acceptInput()

{

Scanner keyInput = new Scanner(System.in);

int counter = 0;

while (true)

{

if (counter > Inventory.MAX_NUM_OF_PRODUCTS)

{

break;

}

System.out.print("Enter product Name (enter stop to quit):");

String productName = keyInput.next();

if (productName.equalsIgnoreCase("STOP"))

{

return;

}

System.out.print("Enter item number:");

String itemNumber = keyInput.next();

System.out.print("Enter number of units in stock:");

int numUnitsInStock;

while ((numUnitsInStock = keyInput.nextInt()) <= 0)

{

System.out.print("Please enter a valid number:");

}

System.out.print("Enter price:");

double price;

while ((price = keyInput.nextDouble()) <= 0)

{

System.out.print("Please enter a valid number:");

}

Product product = new Product();

product.SetItemNumber(itemNumber);

product.SetProductName(productName);

product.SetNumOfUnitsInStock(numUnitsInStock);

product.SetPrice(price);

inventory.addProduct(counter, product);

counter++;

}

}

public void displayOutput()

{

NumberFormat moneyFormat = NumberFormat.getCurrencyInstance();

Product products[] = inventory.getSortedInventoryList();

for (int i = 0; i < inventory.getNumOfProducts(); i++)

{

Product product = products;

System.out.printf("Item number: %s\n", product.getItemNumber());

System.out.printf("Product Name: %s\n", product.getProductName());

System.out.printf("Number of units in stock: %d\n", product.getNumOfUnitsInStock());

System.out.printf("Price: %s\n", moneyFormat.format(product.getPrice()));

System.out.printf("Total value: %s\n", moneyFormat.format(product.getTotalValue()));

}

System.out.printf("Total Inventory value: %s\n", moneyFormat.format(inventory.getInventoryValue()));

}

static public void main(String[] args)

{

TestDriver driver = new TestDriver();

driver.acceptInput();

driver.displayOutput();

}

}

Here are my 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 SetPrice(double)

cannot find symbol method getItemNumber()

cannot find symbol method getProductName()

cannot find symbol method getNumOfUnitsInStock()

[2836 byte] By [4zlimita] at [2007-11-27 8:22:55]
# 1

sorry it didn't format correctly

import java.util.Scanner;

import java.text.NumberFormat;

public class TestDriver

{

private Inventory inventory;

public TestDriver()

{

inventory = new Inventory();

}

public void acceptInput()

{

Scanner keyInput = new Scanner(System.in);

int counter = 0;

while (true)

{

if (counter > Inventory.MAX_NUM_OF_PRODUCTS)

{

break;

}

System.out.print("Enter product Name (enter stop to quit):");

String productName = keyInput.next();

if (productName.equalsIgnoreCase("STOP"))

{

return;

}

System.out.print("Enter item number:");

String itemNumber = keyInput.next();

System.out.print("Enter number of units in stock:");

int numUnitsInStock;

while ((numUnitsInStock = keyInput.nextInt()) <= 0)

{

System.out.print("Please enter a valid number:");

}

System.out.print("Enter price:");

double price;

while ((price = keyInput.nextDouble()) <= 0)

{

System.out.print("Please enter a valid number:");

}

Product product = new Product();

product.SetItemNumber(itemNumber);

product.SetProductName(productName);

product.SetNumOfUnitsInStock(numUnitsInStock);

product.SetPrice(price);

inventory.addProduct(counter, product);

counter++;

}

}

public void displayOutput()

{

NumberFormat moneyFormat = NumberFormat.getCurrencyInstance();

Product products[] = inventory.getSortedInventoryList();

for (int i = 0; i < inventory.getNumOfProducts(); i++)

{

Product product = products;

System.out.printf("Item number: %s\n", product.getItemNumber());

System.out.printf("Product Name: %s\n", product.getProductName());

System.out.printf("Number of units in stock: %d\n", product.getNumOfUnitsInStock());

System.out.printf("Price: %s\n", moneyFormat.format(product.getPrice()));

System.out.printf("Total value: %s\n", moneyFormat.format(product.getTotalValue()));

}

System.out.printf("Total Inventory value: %s\n", moneyFormat.format(inventory.getInventoryValue()));

}

static public void main(String[] args)

{

TestDriver driver = new TestDriver();

driver.acceptInput();

driver.displayOutput();

}

}

4zlimita at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 2
USE CODE TAGS TO RETAIN FORMATTING WHEN POSTING CODE.Copy your code from the source.Paste it in message.Highlight it.Click code button.
floundera at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 3

Use [code] and [/code] around your code. And make sure to indent it. Paste it from your editor. You've already lost the indents, so if you just add the tags, it won't be indented. You have to re-paste the correctly indented original.

The error messages are telling you exactly what's wrong. You're trying to call methods that don't exist.

jverda at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 4

import java.util.Scanner;

import java.text.NumberFormat;

public class TestDriver

{

private Inventory inventory;

public TestDriver()

{

inventory = new Inventory();

}

public void acceptInput()

{

Scanner keyInput = new Scanner(System.in);

int counter = 0;

while (true)

{

if (counter > Inventory.MAX_NUM_OF_PRODUCTS)

{

break;

}

System.out.print("Enter product Name (enter stop to quit):");

String productName = keyInput.next();

if (productName.equalsIgnoreCase("STOP"))

{

return;

}

System.out.print("Enter item number:");

String itemNumber = keyInput.next();

System.out.print("Enter number of units in stock:");

int numUnitsInStock;

while ((numUnitsInStock = keyInput.nextInt()) <= 0)

{

System.out.print("Please enter a valid number:");

}

System.out.print("Enter price:");

double price;

while ((price = keyInput.nextDouble()) <= 0)

{

System.out.print("Please enter a valid number:");

}

Product product = new Product();

product.SetItemNumber(itemNumber);

product.SetProductName(productName);

product.SetNumOfUnitsInStock(numUnitsInStock);

product.SetPrice(price);

inventory.addProduct(counter, product);

counter++;

}

}

public void displayOutput()

{

NumberFormat moneyFormat = NumberFormat.getCurrencyInstance();

Product products[] = inventory.getSortedInventoryList();

for (int i = 0; i < inventory.getNumOfProducts(); i++)

{

Product product = products[i];

System.out.printf("Item number: %s\n", product.getItemNumber());

System.out.printf("Product Name: %s\n", product.getProductName());

System.out.printf("Number of units in stock: %d\n", product.getNumOfUnitsInStock());

System.out.printf("Price: %s\n", moneyFormat.format(product.getPrice()));

System.out.printf("Total value: %s\n", moneyFormat.format(product.getTotalValue()));

}

System.out.printf("Total Inventory value: %s\n", moneyFormat.format(inventory.getInventoryValue()));

}

static public void main(String[] args)

{

TestDriver driver = new TestDriver();

driver.acceptInput();

driver.displayOutput();

}

}

4zlimita at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 5
And this is the wrong code too.We need to see the code for the Product class.
cotton.ma at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 6

public class Product implements Comparable

{

protected String itemNumber;

protected String productName;

protected int numOfUnitsInStock;

protected double price;

public Product()

{

}

public void setItemNumber(String itemNumber)

{

this.itemNumber = itemNumber;

}

public void setProductName(String productName)

{

this.productName = productName;

}

public void setNumOfUnitsInStock(int numOfUnitsInStock)

{

this.numOfUnitsInStock = numOfUnitsInStock;

}

public void setPrice(double price)

{

this.price = price;

}

public String getItemNumber()

{

return itemNumber;

}

public String getProductName()

{

return productName;

}

public int getNumOfUnitsInStock()

{

return numOfUnitsInStock;

}

public double getPrice()

{

return price;

}

public double getTotalValue()

{

return price * numOfUnitsInStock;

}

public int compareTo(Object object) // for sorting by product name

{

if (productName == null)

{

return -1;

}

if (object == null)

{

return 1;

}

return productName.compareTo(((Product)object).getProductName());

}

}

4zlimita at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 7
Okay.SetItemNumberis not the same assetItemNumberJava is case sensitive.
cotton.ma at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 8

I changed the case on the 'set'. I get the same errors but instead of "Set", it is "set".

import java.util.Scanner;

import java.text.NumberFormat;

public class TestDriver

{

private Inventory inventory;

public TestDriver()

{

inventory = new Inventory();

}

public void acceptInput()

{

Scanner keyInput = new Scanner(System.in);

int counter = 0;

while (true)

{

if (counter > Inventory.MAX_NUM_OF_PRODUCTS)

{

break;

}

System.out.print("Enter product Name (enter stop to quit):");

String productName = keyInput.next();

if (productName.equalsIgnoreCase("STOP"))

{

return;

}

System.out.print("Enter item number:");

String itemNumber = keyInput.next();

System.out.print("Enter number of units in stock:");

int numUnitsInStock;

while ((numUnitsInStock = keyInput.nextInt()) <= 0)

{

System.out.print("Please enter a valid number:");

}

System.out.print("Enter price:");

double price;

while ((price = keyInput.nextDouble()) <= 0)

{

System.out.print("Please enter a valid number:");

}

Product product = new Product();

product.setItemNumber(itemNumber);

product.setProductName(productName);

product.setNumOfUnitsInStock(numUnitsInStock);

product.setPrice(price);

inventory.addProduct(counter, product);

counter++;

}

}

public void displayOutput()

{

NumberFormat moneyFormat = NumberFormat.getCurrencyInstance();

Product products[] = inventory.getSortedInventoryList();

for (int i = 0; i < inventory.getNumOfProducts(); i++)

{

Product product = products[i];

System.out.printf("Item number: %s\n", product.getItemNumber());

System.out.printf("Product Name: %s\n", product.getProductName());

System.out.printf("Number of units in stock: %d\n", product.getNumOfUnitsInStock());

System.out.printf("Price: %s\n", moneyFormat.format(product.getPrice()));

System.out.printf("Total value: %s\n", moneyFormat.format(product.getTotalValue()));

}

System.out.printf("Total Inventory value: %s\n", moneyFormat.format(inventory.getInventoryValue()));

}

static public void main(String[] args)

{

TestDriver driver = new TestDriver();

driver.acceptInput();

driver.displayOutput();

}

}

4zlimita at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 9
Copy and paste the new error messages
floundera at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 10

Thanks flounder..here they are:

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()

4zlimita at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 11
Make sure you have saved all files before recompiling.
floundera at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 12
You haven't by any chance created your own class named String somewhere have you?
cotton.ma at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 13

I don't believe so...I have three files in one project...

The only one I get errors on is the TestDriver.

Here is the third file:

import java.util.Arrays;

public class Inventory

{

static public final int MAX_NUM_OF_PRODUCTS = 10;

private Product products[] = new Product[MAX_NUM_OF_PRODUCTS];

private int numOfProducts;

public Inventory()

{

}

public double getInventoryValue()

{

double inventoryValue = 0;

for (int i = 0; i < products.length; i++)

{

Product product = products[i];

if (product != null)

{

inventoryValue += product.getTotalValue();

}

}

return inventoryValue;

}

public Product[] getSortedInventoryList()

{

Arrays.sort(products, 0, numOfProducts) ;

return products;

}

public void addProduct(int index,Product product)

{

products[index] = product;

numOfProducts++;

}

public int getNumOfProducts()

{

return numOfProducts;

}

}

4zlimita at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 14
Well I just copied all your code and it compiled fine for me.I repeat make sure you have saved all your files (and that they are the correct ones) before compiling!
floundera at 2007-7-12 20:11:44 > top of Java-index,Java Essentials,New To Java...
# 15
I did save them. I am not sure what is happening. Thank you for trying!
4zlimita at 2007-7-21 22:38:59 > top of Java-index,Java Essentials,New To Java...
# 16

> I did save them. I am not sure what is happening.

>

> Thank you for trying!

Something is screwy with your environment. The code as posted now works.

So if you are using an IDE try and close that and reopen. Then make sure you do a clean/full rebuild.

Otherwise make sure your old class files are gone before you try and recompile.

cotton.ma at 2007-7-21 22:38:59 > top of Java-index,Java Essentials,New To Java...
# 17

Have you made multiple copies and have backups stored somewhere? Try saving all your files with diff names. Delete all current .java and .class files( not the new ones you just created). Then rename you files back to what they should be. Make sure you are in the correct directory and try again.

Either that or you are just trolling.

floundera at 2007-7-21 22:38:59 > top of Java-index,Java Essentials,New To Java...
# 18
what is trolling? I did have NetBeans, but I was told by my instructor to try just using Java. Could that be the issue?
4zlimita at 2007-7-21 22:38:59 > top of Java-index,Java Essentials,New To Java...
# 19
No, sorry flounder, I am not trolling. I would not stay up to midnight when I work full time, go to school at night, and have 4 kids to make people in a forum upset.
4zlimita at 2007-7-21 22:38:59 > top of Java-index,Java Essentials,New To Java...