Been working on this for so long I am lost and my mind is mush,lol.
On line 106 i have this error (class camera is public, should be declared in a file named camera.java)
I have a lot of incompatible types required: java.lang.String found: camera.camera.string errors.

I do not know what they mean and I tired many ways to fix the problem. I am a newbie and this is my second time taking this class. Running out of gas and need help, please.

package camera;

import java.util.Scanner;

/**
 *
 * @author pastryfdr
 */
public class Camera {
    private static int count;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        // creating scanner to obtain input from command window

        int item_no;
        String product_name;
        String department;
        double unit_in_stock;
        double price_unit;
        double value_of_inventory = 0;


System.out.print("Enter Product Name: ");//prompt
    product_name = input.next();
    System.out.println();

System.out.print("Enter Item Number: ");//prompt
    item_no = input.nextInt();
    System.out.println();

System.out.print("Enter Price of Each Unit: ");//prompt
    price_unit = input.nextDouble();
    System.out.println();

System.out.print("Units in Stock: ");//prompt
    unit_in_stock = input.nextDouble();
    System.out.println();

    // array
    camera[] mycamera = new camera[10];

    for (int i = 0; i < count; i++)

    { //count number of new cameras

System.out.print("Enter Product Name: ");//prompt
    product_name = input.next();
    System.out.println();
    value_of_inventory = unit_in_stock * price_unit;

System.out.print("Enter Item Number: ");//prompt
    item_no = input.nextInt();
    System.out.println();

System.out.print("Enter Price of Each Unit: ");//prompt
    price_unit = input.nextDouble();
    System.out.println();

System.out.print("Units in Stock: ");//prompt
    unit_in_stock = input.nextDouble();
    System.out.println();

camera newcamera = newcamera(product_name, item_no, price_unit, unit_in_stock);

// put 

mycamera[count]= newcamera;

    }//end for

         for (int i = 0; i < count; i++)

        //print

    System.out.println("The product number is " +item_no);
    System.out.println("The name of the product is "+product_name);    
    System.out.println("The number of units in stock is "+unit_in_stock);
    System.out.println("The price of each unit " +price_unit);
    System.out.println("The value of inventory is "+value_of_inventory);

    System.out.println(); // space

    }// end for

    private static camera newcamera(String product_name, int item_no, double price_unit, double unit_in_stock) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private static class camera {

        public camera() {
        }
    }

}// end main container

public class camera {

    private static class string {

        public string() {
        }
    }

String department = "";
String product_name = "";
int item_no = 0;
double price_unit = 0.0;
double unit_in_stock = 0.0;

// contructor

private camera (string department, string product_name, int item_no, double unit_in_stock)
{
this.department = department;
this.product_name = product_name;
this.item_no = item_no;
this.price_unit = price_unit;
this.unit_in_stock = unit_in_stock;
}
// set and get method

public String getdepartment()
{
    return department;
}

public void setdepartment(string department)
{
    this.department = department;
}

public String getproduct_name()
{
    return product_name;

}

public void setproduct_name (string product_name)
{
    this.product_name = product_name;
}

public int getitem_no()
{
    return item_no;

}

public void setitem_no (int item_no)
{
    this.item_no = item_no;

}
    public double getprice_unit()
{
    return price_unit;

}

public void setprice_unit (double price_unit)
{
    this.price_unit = price_unit;
}

public double getunit_in_stock()
{
    return unit_in_stock;

}

public void setunit_in_stock (double unit_in_stock)
{
    this.unit_in_stock = unit_in_stock;
}
}
// end
Member Avatar for ztini
package camera;

import java.text.NumberFormat;

// class names should follow CamelCase format.
public class Camera {

	// Declare the visibility of your global variables.  Unless set to Final, these
	// typically should be private.  Access to these should be from getters/setters.
	// Also, camelCase should be followed as a prescribed naming convention.
	private String department, productName;
	
	// Consider moving unitInStock elsewhere, such as Inventory.  Concrete classes typically
	// represent a single entity.  Entities, such as an Inventory, can contain many things, such
	// as Cameras.
	private int itemNo, unitInStock;  
	
	private double unitPrice;

	// Generally a bad design to include so many parameters in the constructor.  Getters and setters 
	// should be invoked over extensively adding input parameters.  Your constructor should typically
	// be protected/public unless you have a static helper method to instantiate through.
	// I have removed the constructor in lieu of getters/setters

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public int getItemNo() {
		return itemNo;
	}

	public void setItemNo(int itemNo) {
		this.itemNo = itemNo;
	}

	public double getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(double unitPrice) {
		this.unitPrice = unitPrice;
	}

	public int getUnitInStock() {
		return unitInStock;
	}

	public void setUnitInStock(int unitInStock) {
		this.unitInStock = unitInStock;
	}
	
	@Override
	public String toString() {
		NumberFormat numberFormat = NumberFormat.getCurrencyInstance();
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append("The product number is ");
		stringBuffer.append(this.getItemNo());
		stringBuffer.append("\r\nThe name of the product is ");
		stringBuffer.append(this.getProductName());
		stringBuffer.append("\r\nThe number of units in stock is ");
		stringBuffer.append(this.getUnitInStock());
		stringBuffer.append("\r\nThe price of each unit ");
		stringBuffer.append(numberFormat.format(this.getUnitPrice()));
		stringBuffer.append("\r\nThe value of the inventory is ");
		stringBuffer.append(numberFormat.format(this.getUnitInStock() * this.getUnitPrice()));
		return stringBuffer.toString();
	}
}
package camera;

import java.util.ArrayList;
import java.util.Scanner;

public class Inventory {
	
	// List to hold cameras entered by the user.
	private ArrayList<Camera> cameras = new ArrayList<Camera>();
	
	public Inventory() { 
		displayMenu();
		report();
	}
	
	// Access your private globals through getters/setters (or Adds/Removes for lists)
	public void addCamera(Camera camera) { 
		cameras.add(camera);
	}
	
	public void displayMenu() { 
		do {
			// As a personal preference, i like to likewise name variables to their instantiation.
			// By no means a best practice, just how I've evolved my own preference.
			Scanner in = new Scanner(System.in);
			Camera camera = new Camera();		
			
			// If you can invoke a setter directly, do it instead of needlessly allocating memory.
			// Unless you intend to sterilize the input prior to passing to the setter.  Typically
			// you should allow the setter to perform that task.
			System.out.print("Enter Product Name: ");
			camera.setProductName(in.nextLine()); // includes space, such as: "foo bar".
			
			System.out.print("Enter Item Number: ");
			camera.setItemNo(in.nextInt());
			
			System.out.print("Enter Price of Each Unit: ");
			camera.setUnitPrice(in.nextDouble());
	
			System.out.print("Units in Stock: ");
			camera.setUnitInStock(in.nextInt()); // int unless you can a partial item stocked? 0.75 cameras stocked?
			
			// Add camera to list.  Do not add directly to global variable.  Allow adding logic to be isolated within
			// a helper method.
			addCamera(camera);
			
			// Loop until something other than 'Y' is entered
			System.out.print("Enter more cameras?(Y/N) ");
			if (!in.next().substring(0, 1).equalsIgnoreCase("Y"))
				break;
			
		} while (true);
	}
	
	public void report() { 
		// for each Camera in the List cameras
		for (Camera camera : cameras)
			System.out.println(camera);
	}
	
	// Main method should start your application, not contain the logic.
	public static void main(String[] args) {
		new Inventory();
	}
}

output:

Enter Product Name: Foo
Enter Item Number: 1
Enter Price of Each Unit: 1.25
Units in Stock: 3
Enter more cameras?(Y/N) y
Enter Product Name: Bar
Enter Item Number: 2
Enter Price of Each Unit: 1.5
Units in Stock: 9
Enter more cameras?(Y/N) n
The product number is 1
The name of the product is Foo
The number of units in stock is 3
The price of each unit $1.25
The value of the inventory is $3.75
The product number is 2
The name of the product is Bar
The number of units in stock is 9
The price of each unit $1.50
The value of the inventory is $13.50

Generally a bad design to include so many parameters in the constructor. Getters and setters should be invoked over extensively adding input parameters.

I can't let this pass without comment.
When you instantiate any class there is some number of values that must be set for subsequent uses of that instance to be valid. Eg a Book must have an ISBN, title and author. Best practice is to require ALL mandatory non-defaultable values in every non-private constructor. If you don't do this then anyone instantiating this class will need to call one or more setters to create a valid instance, but there is no standard protocol to inform them of this requirement, nor to check that it has been met.

Member Avatar for ztini

I can't let this pass without comment.
When you instantiate any class there is some number of values that must be set for subsequent uses of that instance to be valid. Eg a Book must have an ISBN, title and author. Best practice is to require ALL mandatory non-defaultable values in every non-private constructor. If you don't do this then anyone instantiating this class will need to call one or more setters to create a valid instance, but there is no standard protocol to inform them of this requirement, nor to check that it has been met.

That's a good point. I generally just leave required values as null and let the NPE do my talking. ;)

I've been on a few projects that have asserted these types of required fields by invoking a isValid() method on objects. This worked exceptionally well for a shared domain model consumed by 400+ SOAP calls.

Although, I stand by substantially reducing input values into a constructor. Using getters/setters promotes readability and does not impede on performance. This is a must for large scale, Agile projects.

For instance:

new Book(93248234, "FooBar", "Smith, John")

Is not as instantly clear as:

Book book = new Book();
book.setISBN(93248234);
book.setTitle("FooBar");
book.setAuthor("Smith, John");

Thanks everyone for your help.

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.