Not sure what it is nedding I'm needing help on coding this program I get back some 2 errors.

What I have is:

public class Inventory
{

 private double ItemNumber; //to store Item number
 private String ItemName; //to store Item name
 private double UnitsInStock; //to store number of units in stock
 private double UnitPrice; //to store Unit price
 private double InventoryValue; //to store Inventory value
 private double TotalInventory; //to store Total Inventory value

 public Inventory() //constructor with no initial variables
   {
    this ("", 0.0, 0.0, 0.0);
   }

   public Inventory (String name, double number, double stock, double price)
    {

      ItemName = name; //set Item name
      ItemNumber = number; //set Item number
      UnitsInStock = stock; //set Units in stock
      UnitPrice = price; //set Unit price
    }

     //method to set the Item name
     public void setItemName( String name )
     {
       ItemName = name; //store the Item name
     } 

     //method to get the Item name
     public String getItemName()
     {
       return ItemName;
     }

     //method to set the Item number
     public void setItemNumber( int number )
     {
       ItemNumber = number; //store the Item number
     }

     //method to get the Item number
     public double getItemNumber()
     {
       return ItemNumber;
     }

     //method to set the UnitsInStock
     public void setUnitsInStock( double stock )
     {
       UnitsInStock = stock; //store the Units in stock
     } 

     //method to get the UnitsInStock
     public double getUnitsInStock()
     {
       return UnitsInStock;
     } 

     //method to set the UntiPrice
     public void setUnitPrice( double price )
     {
       UnitPrice = price; //store the Unit price
     } 

     //method to get the UnitPrice
     public double getUnitPrice()
     {
       return UnitPrice;
     }

     //method to set Inventory value
     public void setInventoryValue(double value)
     {
      InventoryValue = value;
     } 

     //method to get InventoryValue
     public double getInventoryValue()
     {
       return InventoryValue;
     } 

     public double getInventoryValue()
     {
       return UnitPrice*UnitsInStock;
     } 

     //method to set TotalInventory
     public void setTotalInventory(double value)
     {

     TotalInventory = total;
     } 

     //method to get TotalInventoty
     public double getTotalInventory()
     {
     return TotalInventory;

     } //end method to getTotalInventory
} //end class Inventory

The errors that I am getting are:

F:\java inventory program part 2\Inventory.java:85: error: method getInventoryValue() is already defined in class Inventory
     public double getInventoryValue()
                   ^
F:\java inventory program part 2\Inventory.java:94: error: cannot find symbol
     TotalInventory = total;
                      ^
  symbol:   variable total
  location: class Inventory
2 errors

Recommended Answers

All 3 Replies

the first error means you have two methods with the exact same name and parameter list, which is not possible. if you want to overload methods, you must change the signature.

so:

remove or re-name one of these.

//method to get InventoryValue
     public double getInventoryValue()
     {
       return InventoryValue;
     } 
     public double getInventoryValue()
     {
       return UnitPrice*UnitsInStock;
     } 

in the second error, replace total with value, because that is how you called your parameter

Thank you for all your help

Dont forget to mark the thread as solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.