hi, all ... very new to java, but plugging along somehow ... however, i have an assignment that wants me to find the value of all of the inventory of a product and i have the entire code, but the method that i created to calculate the value ... calculateTotInvent() can't find the name of my array? i've been at this for more than 5 hours now and my brain is mush. any ideas?

btw i get the "errors" on these two lines

for(int number =0 ; number < arrCam.length(); number++)
            {
    		totValue+= arrCam[number].getIValue();
            }

and this is the error msg i get when I try to compile:

cannot find symbol
symbol : variable arrCam
location: class Invent2
for(int number =0 ; number < arrCam.length; number++)
^
Invent2.java:116: cannot find symbol
symbol : variable arrCam
location: class Invent2
totValue+= arrCam[number].getIValue();
^
Invent2.java:116: inconvertible types
found : <nulltype>
required: double
totValue+= arrCam[number].getIValue();
^
3 errors


here's the main program

public class Invent2 
{
    
  
	public static final String IDEPT = "Electronics"; 	// FIXED Variable for camera's department

   	public static void main(String[] args)
    {
	System.out.println( );								// One blank line
	System.out.println( "____________________________________________________ " ); // Show a long line
	System.out.println( );								// One blank line
	System.out.println( "Welcome to the input module of the Inventory Program ");
	System.out.println( "____________________________________________________ " ); // Show a long line
	System.out.println( "Please enter the details of the four models we carry. ");
	System.out.println( "You will be prompted 4 times for each of the 4 models ");

   	// Create an array of Cameras
    	DigitalCamera arrCam[] = new DigitalCamera[4];    	
    	
    	arrCam[0] = getCamera( );
    	arrCam[1] = getCamera( );
    	arrCam[2] = getCamera( );
    	arrCam[3] = getCamera( );
        
		
	// Display results
		System.out.println( );		// One blank Line
		System.out.println( "List of Current Inventory" ); // Display welcome line
		System.out.println( "________________________________" ); // One long line
                System.out.println( );		// One blank Line
		
	   	for(int number = 0; number < arrCam.length; number++)
    	{
			System.out.println( "Camera Name         : " + arrCam[number].getIName() );
			System.out.println( "Item number         : " + arrCam[number].getINum() );
			System.out.println( "Digital resolution  : " + arrCam[number].getiRes() );
			System.out.println( "Department          : " + IDEPT );
			System.out.printf( "Unit Price          : $%.2f\n", arrCam[number].getIPrice() );
			System.out.println( "Units in Stock      : " + arrCam[number].getIStock() );
			System.out.printf( "Total Value in Stock: $%.2f\n", arrCam[number].getIValue() );
			System.out.println();
    	}
		// display total inventory using method calculateTotInvent() developed below
                System.out.println( "________________________________" ); // One long line
                System.out.println( );					// One blank line
		System.out.printf("Value of Entire Inventory: %.2f\n", calculateTotInvent());
                System.out.println( "________________________________" ); // One long line

		// Show Program Exit Message
		System.out.println( );				// One blank line
		System.out.println( "Now exiting the program."); // Show Exit Message	
		System.out.println( );				// One blank line
							
	} // end method main
        
        public static double calculateTotInvent(){ 
           
    	double totValue=0.0;
        {
            
    	for(int number =0 ; number < arrCam.length(); number++)
            {
    		totValue+= arrCam[number].getIValue();
            }
        }
    	return totValue;
           
	}

    public static DigitalCamera getCamera( ) 
    { 
                
                Scanner input = new Scanner(System.in);
                
                int iNum;	// Variable for camera's item number
		String iName; 	// Variable for camera's name
		int iStock;	// Variable for number of units in stock
		float iPrice;	// Variable for price of each unit
		float iRes;	// Variable for Digital subclass
		
		System.out.println( ); // One blank line

		
		System.out.println( ); // One blank line
		              
		// First input for camera's name
		System.out.print ( "Enter the name of the Camera: " ); 
		iName = input.next();
		
                // Second input for camera's item number
		System.out.print( "Enter a Camera's item number: " );  
		iNum = input.nextInt();
                
                // Third input for resolution of Digital camera
		System.out.print( "Enter the resolution of this model: " );
		iRes = input.nextFloat();
                
		// Fourth Input for number of cameras in stock
		System.out.print( "Enter the number of units in stock: " );
		iStock = input.nextInt();

		// Fifth input for price of each Camera
		System.out.print( "Enter the price of this model: " );
		iPrice = input.nextFloat();
                
		
        	
                
                // create constructor for this object of Digital Cameras
                DigitalCamera myCamera = new DigitalCamera(iName, iNum, IDEPT, iStock, iPrice, iRes);
                
                
      return myCamera;  
    }
    
      
    } // end class Invent2

here's my camera class

public class Camera
{
	
	protected int iNum2;	// Variable for instance of camera's item number
	protected String iName2; 	// Variable for instance of camera's name
	protected int iStock2;	// Variable for instance of number of units in stock
	protected float iPrice2;	// Variable for instance of price of each unit	
	
	// constructor to create camera object
	public Camera(String iName, int iNum, String IDEPT, int iStock, float iPrice)
	{
	this.iName2 = iName;
	this.iNum2 = iNum;
	this.iStock2 = iStock;
	this.iPrice2 = iPrice;
	}

	// Methods to retrieve this info is below
	//method to get item Number
	public int getINum() 
	{
		return this.iNum2;
	}
	
	//method to get item Name
	public String getIName() 
	{
		return this.iName2;
	}
	
	//method to get Department
	public int getIStock()
	{	
		return this.iStock2;
	}
        // method to get price of each unit
	public float getIPrice()
	{
		return this.iPrice2;
	}
	float getIValue() {
        
        return iPrice2 * iStock2;

      

        }
        } // end class Camera

and here's my extended class

public class DigitalCamera extends Camera
{
	protected float iRes;
	protected float reStock;
     	  

	DigitalCamera(String iName2, int iNum2, String IDEPT, int iStock2, float iPrice2, float iRes)    
	{
		super(iName2, iNum2, IDEPT, iStock2, iPrice2);
		this.iRes = iRes;
	}

	public float getiRes()
	{
		return iRes;
	}
	
	public void setDigital(float iRes)
	{
		this.iRes = iRes;
	}

	public float getReStock()
	{
		return reStock;
	}
        
    @Override
        public float getIValue() {
        
 	{
        return iPrice2 * iStock2;
	}
        
    }
        
}//class ends

pass the arrCam array to calculateTotInvent method

like so?

public static double calculateTotInvent(arrCam[]){ 
           
    	double totValue=0.0;
        {
            
    	for(int number =0 ; number < arrCam.length(); number++)
            {
    		totValue+= arrCam[number].getIValue();
            }   
        }
    	return totValue;

that still gives me an error?

Aha! I figured it out. Got it now. Thanks1

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.