Hello All,
I am submitting a inventory program that I need some help with.
I had to create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit.
Then I needed to create a java app that would display the product number, the name of the product, the number of units in stock, the price of the units, and the value of the inventory (number of units * price of each)
I would appreciate it if someone could look over what I have done and make suggestions I am new at this and appreciate the help...

//InventoryProgram1.Java   
//import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;

class Product {
    String name;
    int item number;
    int number of units;
    int price per unit;

    public Product (String name, int item number, int number of units, int price per unit) 

{
        this.name = name;
        this.item number = item number;
        this.numberofunits = units;
        this.priceperunit = price;
        computeValueInventory ();
    }

    private void computeValueInventory () {
        Value = Units * price;
    }

    public int getValueInventory () {
        return ValueInventory;
    }
}
     

public class InventoryProgram1 //declares public class inventory

{

    public static void main(String args []) //starts the program
    {
        Scanner input = new Scanner( System.in );
  
      Stapler[] stapler= new Stapler[1];
        
                       
        stapler[0] = new Stapler( 645, "Black", 2, 17.99 );//declares a new item number, 

color, quantity, and price
        
}      
           {  
               
               System.out.println(Stapler[i]);
               System.out.println();  
              
               System.out.println("The item number is " + stapler[i].getItemNumber());     

          
               System.out.println("Product Title is " + stapler[i].getstaplercolor()); 
               System.out.println("The number of units in stock is " + 

stapler[i].getOnHand());
               System.out.println("The price of each stapler is " + 

stapler[i].getstaplerCost());
               System.out.println("The value of the inventory is " + stapler[i].value());  

           }        
         
        
     }//end class

} // end class Inventory1

The code is unreadable. Please format/indent it and use code tags. NetBeans and other IDEs will format the code for you if you want. Code tags are used as follows. All indentation is stripped out if code tags are not used. Please repost with them.

[code=JAVA] // paste code here

[/code]

[edit]
Code tags have been added to your post. Please note that you cannot have spaces in the variable names. See lines 7 through 19. Use an underscore _ for spaces.
[/edit]

Does that mean that I should write String_name or should it be StringName ?
int itemNumber or int item_name?

He isn't referring to the space between the type and the variable name.

String name;

is just fine.
It is these

int item number;
    int number of units;
    int price per unit;

that are not allowed.
Generally they would instead be written

int itemNumber;
    int numberOfUnits;
    int pricePerUnit;

Does that mean that I should write
int itemNumber or int item_name?

I don't know that it matters. The compiler doesn't care. But the Java naming standards say that for multi-word variables, you should use no underscores, the first word should be lower-case, and the others should be upper-case, so I probably steered you wrong with the underscore idea. So itemNumber, pricePerUnit, and numberOfUnits are preferred, so do it that way. The compiler couldn't care less, but people do, so you might as well follow the conventions.

http://java.about.com/od/javasyntax/a/nameconventions.htm

[edit]
I just read your post more carefully as well as Ezzaral's. Yes, you need a space between the type and the variable name. There are no spaces between the words in the variable name. See Ezzaral's example.
[/edit]

Here is aupdated version of the app is this correct or does it need other changes?

//InventoryProgram1.Java   
//import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String

class Product {
    String Name;
    int itemNumber;
    int number_of_units;
    int price_ per_ unit;

    public Product (String name, int itemNumber, int numberofunits, int priceper
unit) {
        this.theName = name;
        this.itemNumber = itemNumber;
        this.numberofunits = units;
        this.priceperunit = price;
        computeValueInventory ();
    }

    private void computeValueInventory () {
        Value = Units * price;
    }

    public int getValueInventory () {
        return ValueInventory;
    }
}
     

public class InventoryProgram1 //declares public class inventory

{

    public static void main(String args []) //starts the program
    {
        Scanner input = new Scanner( System.in );
  
      Stapler[] stapler= new Stapler[1];
        
                       
        stapler[0] = new Stapler( 645, 2, 17.99 );//declares a new item number,units in 

stock,and price
        
}      
           {  
               
               System.out.println(Stapler[i]);
               System.out.println();  
              
               System.out.println("The item number is " + stapler[i].getItemNumber());     

      
               System.out.println("The number of units in stock is " + 

stapler[i].getnumberofunits());
               
               System.out.println("The price of each stapler is " + 

stapler[i].getstaplerCost());
               
               System.out.println("The value of the inventory is " stapler[i].value());  

           }        
Public static void ValueofInventory() {
        value = units * price
        
        System.out.printlnf("%s units $%4.2f price",itemNumber,value);
        System.out.println();   
        
     }//end class

} // end class InventoryProgram1

Again, code tags. See my first post regarding how.

is this correct

Does it compile? If not, it's not correct.

class Product {
    String Name;
    int itemNumber;
    int number_of_units;
    int price_ per_ unit;

    public Product (String name, int itemNumber, int numberofunits, int priceper
unit) {
        this.theName = name;

See red. These need to match.

How do I add Code tags?

How do I add Code tags?

[code=JAVA] // code goes here

[/code]

or

[code]

// code goes here

[/code]

The first way adds line numbers and syntax highlighting.

//InventoryProgram1.java   
//import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String

class Product {
     String Name;
     int itemNumber;
     int numberofunits;
     int priceperunit;
    }

public Product (String name, int itemNumber, int numberofunits, 
        int priceperunit); {

        this.String Name = name;
        this.itemNumber = itemNumber;
        this.numberofunits = units;
        this.priceperunit = price;
        computeValueInventory ();
    }

    private void computeValueInventory () {
        Value = Units * price;
    }

}
     

public class InventoryProgram1 //declares public class inventory

{

    public static void main(String args []) //starts the program
    {
        Scanner input = new Scanner( System.in );
  
      Stapler[] stapler= new Stapler[45];
        
                       
        stapler[0] = new Stapler( 45, 2, 17.99 );//declares a new item number,units in 
stock,and price
        
}      
    {  
               
         System.out.println(Stapler[i]);
         System.out.println();  
              
         System.out.println("The item number is " + stapler[i].getItemNumber());           
         System.out.println("The number of units in stock is " + stapler[i].getnumberofunits());
               
         System.out.println("The price of each stapler is " + stapler[i].getstaplerprice());
               
         System.out.println("The value of the inventory is " stapler[i].value());  

     }        

Public static void ValueofInventory() {
        value = units * price
        
        System.out.printlnf("%s units $%4.2f price",itemNumber,value);
        System.out.println();   
        
     }// end class

}// end class InventoryProgram1

this is the code submitted and here are the errors that I received...could someone please help me fix them.

2. You define a product class, but then use a constructor for
a stapler class -- the stapler class is not defined.

3. I fixed the filename (from .Java to .java) so that I could
compile it -- there are many compilation errors:

javac InventoryProgram1.java
InventoryProgram1.java:5: ';' expected
import java.lang.String
^
InventoryProgram1.java:14: class, interface, or enum expected
public Product (String name, int itemNumber, int numberofunits,
^
InventoryProgram1.java:15: class, interface, or enum expected
int priceperunit); {
^
InventoryProgram1.java:18: class, interface, or enum expected
this.itemNumber = itemNumber;
^
InventoryProgram1.java:19: class, interface, or enum expected
this.numberofunits = units;
^
InventoryProgram1.java:20: class, interface, or enum expected
this.priceperunit = price;
^
InventoryProgram1.java:21: class, interface, or enum expected
computeValueInventory ();
^
InventoryProgram1.java:22: class, interface, or enum expected
}
^
InventoryProgram1.java:26: class, interface, or enum expected
}
^
InventoryProgram1.java:43: not a statement
stock,and price
^
InventoryProgram1.java:43: ';' expected
stock,and price
^
InventoryProgram1.java:43: ';' expected
stock,and price
^
InventoryProgram1.java:56: ')' expected
System.out.println("The value of the inventory is " stapler

.value());
^
InventoryProgram1.java:56: illegal start of expression
System.out.println("The value of the inventory is " stapler

.value());
^
InventoryProgram1.java:56: ';' expected
System.out.println("The value of the inventory is " stapler

.value());
^
InventoryProgram1.java:56: ';' expected
System.out.println("The value of the inventory is " stapler

.value());


^
InventoryProgram1.java:60: <identifier> expected
Public static void ValueofInventory() {
^
InventoryProgram1.java:61: ';' expected
value = units * price
^
18 errors

Close on the code tags. There should be no spaces.

[code=JAVA] // code here

[/code]

not

[code = JAVA] // code here

[/code]

You have spaces between "code" and "=" and between "=" and "JAVA". You don't want the spaces.

The error messages are fairly self-explanatory. Fix the top one first, recompile, see if the others go away.

//InventoryProgram1.java
//import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String

class Product {
String Name;
int itemNumber;
int numberofunits;
int priceperunit;
}

public Product (String name, int itemNumber, int numberofunits,
int priceperunit); {

this.String Name = name;
this.itemNumber = itemNumber;
this.numberofunits = units;
this.priceperunit = price;
computeValueInventory ();
}

private void computeValueInventory () {
Value = Units * price;
}

}


public class InventoryProgram1 //declares public class inventory

{

public static void main(String args []) //starts the program
{
Scanner input = new Scanner( System.in );

Stapler[] stapler= new Stapler[45];


stapler[0] = new Stapler( 45, 2, 17.99 );//declares a new item number,units in
stock,and price

}
{

System.out.println(Stapler[i]);
System.out.println();

System.out.println("The item number is " + stapler[i].getItemNumber());
System.out.println("The number of units in stock is " + stapler[i].getnumberofunits());

System.out.println("The price of each stapler is " + stapler[i].getstaplerprice());

System.out.println("The value of the inventory is " stapler[i].value());

}

Public static void ValueofInventory() {
value = units * price

System.out.printlnf("%s units $%4.2f price",itemNumber,value);
System.out.println();

}// end class

}// end class InventoryProgram1

Line 5 - The error says exactly what the problem is.

javac InventoryProgram1.java
InventoryProgram1.java:5: ';' expected
import java.lang.String
^

Look at your other import lines. They all end with a semicolon. Look at this line and the error message. No semicolon.

Line 14 error:

InventoryProgram1.java:14: class, interface, or enum expected
public Product (String name, int itemNumber, int numberofunits,
^

This is almost always a brackets problem. You have an extra bracket or you're missing a bracket or it's in the wrong place. You have an ending bracket on line 12 that matches a starting bracket on line 7. The bracket on line 7 marks the start of the Product class. Therefore the ending bracket on line 12 marks the end of the Product class. Therefore anything after line 12 is not in the Product class. You have a Product constructor on line 14. A Product constructor needs to be in the Product class. It isn't. Therefore the ending bracket on line 12 shouldn't be there. Delete it and recompile.

Line 15 - You have a semicolon after the function header and before the starting bracket. That's an error. Delete it. Recompile.

Go from top to bottom. Fix the top error, recompile. Count brackets. They need to match. Do a little bit at a time. Fixing one error often makes a lot of the others simply go away, particularly when they have to do with brackets.

Is there someone out there that can help me fix these errors?

Is there someone out there that can help me fix these errors?

Yes, I can, and I did. If you are looking for someone to fix them all and post the corrected code for you, you've come to the wrong forum. I've given you some advice on how to write and debug your own code and what to look out for. I've given you an idea of how to interpret error messages. It's a detail-oriented, meticulous process. You count starting and ending brackets, you comment things out, you delete lines till you get the bare minimum that compiles. You make a change and you recompile. You make more changes. You recompile. You indent code so that the brackets line up. You'll screw up five dozen times at first before you start to get the hang of it, and you'll probably have to start from scratch a few times, even on a program this short.

Thank you Vernon,
Will try

I made the suggested corrections and then modified it to fit my assignment and would appreciate it if you would look it over and let me know how it looks. Below is a the modified version.

//InventoryProgram1.java   
//import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String;

class Product {
     String Name;
     int itemNumber;
     int numberofunits;
     int priceperunit;
   

public Product (String name, int itemNumber, int numberofunits, 
        int priceperunit); {

        String Name = name;
        this.itemNumber = itemNumber;
        this.numberofunits = units;
        this.priceperunit = price;
        computeValueInventory ();
    }

    private void computeValueInventory () {
        Value = Units * price;
    }

}
     

public class InventoryProgram1 //declares public class inventory

{

        public static void main(String args []) //starts the program
    
        {
        
                       
                  PRODUCT[] = new Product[3];

                  product[0] = new PRODUCT(1, "StApler",45, 2, 17.99 );//
declares a new item
                  // number, name
                 //  quantity, and price

                 product[1] = new PRODUCT(2, "Calanders", 47, 4, 12.99 );

                 product[2] = new PRODUCT(3, "Toner", 49, 6, 19.99 );

//added changes
                 Inventory1 x = new Inventory1();
                 x.sortPRODUCT(product);

        }// end main

        public void SortPRODUCT(PRODUCT[] the PRODUCT) {
                 for (int index = 0; index < the PRODUCT.size - 1;
index++) {
 
                          String s1 = thePRODUCT[index].getProductName();
                          String s2 = thePRODUCT[index] + 1].getProductName
();
                          if (comparewords(s1, s2)) {
                                   PRODUCT temp = thePRODUCT[index];
                                   thePRODUCT[index] = thePRODUCT[index + 1];
                                   thePRODUCT[index + 1] = temp;
                                   index = -1;
                          }
                  }
         }

         private boolean comparewords(String s1, String s2) {
                  boolean islarger = false;

                  for (int index = 0; index < s1.length(); index++) {
                           if (index < s2.length()) {
                                    if (s1.toLowerCase().charAT
(index) > s2.toLowerCase().charAT(index)) {
                                             islarger = true;
                                             break;
                                    {
                                    if (s1.toLowerCase().charAT
(index) < s2.toLowerCase().charAT(index) {

                                             break;
                                    {
                           }else {
                                    return true;
                           }
                   }
                   return islarger;
         }
//end of changes

} // end class Inventory1

class PRODUCT // declares class inventory

{

             private int itemName;// declares item number as in
             private String productTitle;// declares product title as string
             private int onHand; // declares on hand as int
             private double productCost;// declares cost as double

             public PRODUCT(int stockNumber, String title, int inStock,
double price) // constructor
         {
                 itemNumber = stockNumber;// intitiates stock
number, title, instock, and
                  // price
                  productTitle = title;
                  onHand = inStock;
                  productCost = price;

         } //

         // set PRODUCT StockNumber //sets stock number
         public void seItemNumber(int stockNumber)

         {

                   itemNumber = stockNumber;

         }

         public int getItemNumber() // class item number

         {

                   return itemNumber; // returns item number
         } // end method get PRODUCT Item

         public void setProductTitle(String title) // set PRODUCT Title

         {
                 productTitle = title;
         }

         public String getProductTitle() // gets and returns PRODUCT Title

         {
                 return productTitle;
         }

         public void setOnHand(int inStock) // Set on hand

         {
                 onHand = inStock;
         }

         public int getOnHand() // gets and returns on hand

         {
                 return onHand;
         } //

         public void setProductCost(double price) // sets product cost

         {
                 productCost = price;
         }

         public double getProductCost() // gets and returns PRODUCT cost

         {
                 return productCost;
         }

         public double value() // calculate the value of stock

         {
                 return productCost * onHand;
         }

} // end class Product

Line 15 - Same problem as before. You almost never want to have a semicolon between an ending parentheses and a starting bracket (it may be "never" instead of "almost never". I can't think of any exceptions off the top of my head, though there may be one. You don't want it THERE though). Delete that semicolon.

Line 17 - See your other lines (18 - 20). Those are correct.

this.Name = name;

You should change "Name" to "name" in lines 8 and 17 to be consistent.

Java is case-sensitive. "PRODUCT is not "Product" is not "product". Your class is called "Product". Your variable name used in lines 42, 47, and 49 is "product". "PRODUCT" shouldn't exist anywhere as far as I can tell.

Line 40 - This line doesn't make sense. You have a type but no variable name. I assume the variable name is "product". If so, it should be this:

Product product[] = new Product[3];

Case counts! I would strongly suggest consistency. As mentioned in earlier posts, the compiler doesn't care, but you are going to make mistakes if you don't have consistency. Read the earlier links on naming conventions. To recap:

Constants - Can be all caps.
Classes - First letter of each word is in capital letters.
Variables - First letter of all but first word is in capital letters.

//InventoryProgram1.java   
//import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String;

class Product {
     String name;
     int itemNumber;
     int numberofunits;
     double priceperunit;
   

public Product (String name, int itemNumber, int numberofunits, 
        double priceperunit) {

        this.name = name;
        this.itemNumber = itemNumber;
        this.numberofunits = units;
        this.priceperunit = price;
        
    }

    private void computeValueInventory () {
        Value = Units * price;
    }

}
     

public class InventoryProgram1 //declares public class inventoryProgram1

{

        public static void main(String args []) //starts the program
    
        {
        
                       
                  Item item[] = new item[3];

                  item[0] = new item(1, "Stapler",45, 2, 17.99 );
// declares a new item
                  // number, name;
                 //  quantity, and price;

                 item[1] = new item(2, "Calanders", 47, 4, 12.99 );

                 item[2] = new item(3, "Toner", 49, 6, 19.99 );

//added changes
                 Inventory1 x = new Inventory1();
                 x.sortitem(item);

        }// end main

        public static void Sortitem(item[] the item) {
                 for (int index = 0; index < the item.size - 1;
index++) {
 
                          String s1 = theitem[index].getItemName();
                          String s2 = theitem[index] + 1].getItemName
();
                          if (comparewords(s1, s2)) {
                                   Item temp = theitem[index];
                                   theItem[index] = theItem[index + 1];
                                   theItem[index + 1] = temp;
                                   index = -1;
                          }
                  }
         }

         private boolean comparewords(String s1, String s2) {
                  boolean islarger = false;

                  for (int index = 0; index < s1.length(); index++) {
                           if (index < s2.length()) {
                                    if (s1.toLowerCase().charAT
(index) > s2.toLowerCase().charAT(index)) {
                                             islarger = true;
                                             break;
                                    {
                                    if (s1.toLowerCase().charAT
(index) < s2.toLowerCase().charAT(index) {

                                             break;
                                    {
                           }else {
                                    return true;
                           }
                   }
                   return islarger;
         }
//end of changes

} // end class Inventory1

class Inventory // declares class inventory

{

             private int itemName;// declares item number as in
             private String itemTitle;// declares product title as string
             private int onHand; // declares on hand as int
             private double itemCost;// declares cost as double

             public PRODUCT(int stockNumber, String title, int inStock,
double price) // constructor
         {
                 itemNumber = stockNumber;// intitiates stock
number, title, instock, and
                  // price
                  itemTitle = title;
                  onHand = inStock;
                  itemCost = price;

         } //

         // set PRODUCT StockNumber //sets stock number
         public void set ItemNumber(int stockNumber)

         {

                   itemNumber = stockNumber;

         }

         public int getItemNumber() // class item number

         {

                   return itemNumber; // returns item number
         } // end method get Item

         public void setitemTitle(String title) // set item Title

         {
                 ItemTitle = title;
         }

         public String getitemTitle() // gets and returns item Title

         {
                 return itemTitle;
         }

         public void setOnHand(int inStock) // Set on hand

         {
                 onHand = inStock;
         }

         public int getOnHand() // gets and returns on hand

         {
                 return onHand;
         } //

         public void setitemCost(double price) // sets item cost

         {
                 itemCost = price;
         }

         public double getitemCost() // gets and returns item cost

         {
                 return itemCost;
         }

         public double value() // calculate the value of stock

         {
                 return itemCost * onHand;
         }

} // end class Product

Is this what you mean by the changes you suggested?

This doesn't compile. You are doing too much at once. One, you have a brackets problem, or at least you do according to the comment on line 177. Your ending bracket for the Product class is on line 28, not line 177. You have too many errors to debug at once. Here's a very rough skeleton from your code, but it compiles. Note the upper versus lower case. Start from here and start adding a little at a time, then compiling a little at a time.

Line 18 doesn't make much sense though. You have an integer called itemName , which sounds like a String.

//InventoryProgram1.java
import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String;



public class InventoryProgram1 //declares public class InventoryProgram1
{
     public static void main(String args []) //starts the program
     {
     }// end main
} // end class InventoryProgram1

class Inventory // declares class Inventory
{
    private int itemName;// declares itemName as int
    private String itemTitle;// declares itemTitle as String
    private int onHand; // declares onHand as int
    private double itemCost;// declares itemCost as double
}// end class Inventory


class Product
{
    private String name;
    private int itemNumber;
    private int numberOfUnits;
    private double pricePerUnit;


    public Product (String name, int itemNumber, int numberOfUnits,
        double pricePerUnit)
    {
    }
} // end class Product
Errors in MAIN Method
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.