Hello all,

I am fairly new to Java, and have had a terrible time with arrays thus far. I am attempting to complete a project using arrays to store inventory items (item number, name, unit price, and unit numbers) and need to output information using an array to hold the information. Another requirement for class is using a subclass to hold one more unique feature to the program and calculating an additional .05% increase on the total for output on all items.

I have so far built the array, class to set/get item information and also a calculation to calculate item value (based on units*price), I have also included a sub-method to include a category to my item.

I had used String.valueOf() to retrieve all information and have a parse.Double to convert all double money values from user input, but I can not seem to get the output section to retrieve information from the get methods in order to display the information to the user.

For each line of output I am receiving the errors:

C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:90: error: cannot find symbol
inventoryTot += ProdArray.calcValue();
symbol: method calcValue()
location: class Product4
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:91: error: cannot find symbol
restockTot += ProdArray.getFee();
symbol: method getFee()
location: class Product4
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:99: error: bad operand type String for unary operator '+'
System.out.println("Item Number: ", +String.valueOf(ProdArray.getProductNumber()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:100: error: bad operand type String for unary operator '+'
System.out.println("Product name: ", +String.valueOf(ProdArray.getProductName()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:101: error: cannot find symbol
System.out.println("Product Category: ", +String.valueOf(ProdArray.getCatName()));
symbol: method getCatName()
location: class Product4
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:102: error: bad operand type String for unary operator '+'
System.out.println("Units in stock: ", +String.valueOf(ProdArray.getProductUnits()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:103: error: bad operand type String for unary operator '+'
System.out.println("Product price: ", +String.valueOf(ProdArray.getProductAmount()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:105: error: cannot find symbol
System.out.println("Product re-stocking fee: " +String.valueOf(ProdArray.getFee()));
symbol: method getFee()
location: class Product4
8 errors

Is anyone able to help me with this problem?? Thank you all!!

// import java scanner
import Inventory4.Product4;
import java.util.Scanner;
// import Arrays to implement sort
import java.util.Arrays;
import java.io.*;

public class Inventory4 {

     * @param args the command line arguments
    public static void main(String[] args) 
        // initialize scanner
        Scanner input = new Scanner(System.in);

        // welcome display output
        System.out.print("Welcome to the Scrapbook Inventory Program!");
        System.out.println(); // print blank line
        System.out.print("This program will track supplies and accumulate the total ");
        System.out.print("value of inventory.");    // description of program
        System.out.println();  // print blank line
        //local variables assigned to collecting and displaying information in array
        int maxCount = 5;
        int i = 0;
        double inventoryTot = 0.0;
        double restockTot = 0.0;
        // initialize Product4 array
        Product4 ProdArray[] = new Product4[maxCount];
            String name;
            String catName;            
            double number;
            double units;
            double amount;
            // for loop to accumulate count (i) up to the maxCount amt of 5
            // to obtain user input and store information in the array
            for (i=0; i<ProdArray.length; i++)
                // request user input for item name and store in array
                System.out.println("Please enter the item name: " +String.valueOf(i+1)+ "of" +String.valueOf(maxCount));
                name = input.nextLine();
                //request user input for item number and convert double to a string
                System.out.println("Please enter the item number: " +String.valueOf(i+1)+ "of" +String.valueOf(maxCount));
                number = Double.parseDouble(input.nextLine());
                // request user input for item units and convert double to a string
                System.out.println("Please enter the number of units in stock: " +String.valueOf(i+1)+ "of" +String.valueOf(maxCount));
                units = Double.parseDouble(input.nextLine());
                // request user input for item price and convert double to a string
                System.out.println("Please enter the price per unit: " +String.valueOf(i+1) + "of" +String.valueOf(maxCount));
                amount = Double.parseDouble(input.nextLine());
                // request user input for category of item- this is a call to the sub-method
                System.out.println("Please enter the category of the item :" +String.valueOf(i+1) + "of" +String.valueOf(maxCount));
                catName = input.nextLine();
                ProdArray[i] = new Category4(name, number, units, amount, catName);
            } // end for                
        }  // end try
        catch (Exception ec)
                } // end catch
for (i=0; i < maxCount; i++)
            inventoryTot = ProdArray[i].calcValue();
            restockTot = ProdArray[i].getFee();
        }// end for
        // output results
        System.out.println("***Scrapbook Inventory Results***");
        System.out.println(); // print blank line
        for (i=0; i < maxCount; i++)
               System.out.println("Item Number: ", +String.valueOf(ProdArray[i].getProductNumber()));
               System.out.println("Product name: ", + String.valueOf(ProdArray[i].getProductName()));
               System.out.println("Product Category: ", + String.valueOf(ProdArray[i].getCatName()));
               System.out.println("Units in stock: ", + String.valueOf(ProdArray[i].getProductUnits()));
               System.out.println("Product price: ", + String.valueOf(ProdArray[i].getProductAmount()));
               System.out.println("Product total: " + String.valueOf(ProdArray[i].CalcValue()));
               System.out.println("Product re-stocking fee: " +String.valueOf(ProdArray[i].getFee()));
               System.out.println();  //print blank line               
        } //end for
        // output total inventory results
        System.out.println("Scrapbook inventory total: " +String.valueOf(inventoryTot));
        System.out.println("Scrapbook inventory total with re-stocking fee: " +String.valueOf(restockTot));
    } //end main

} //end Inventory

public class Product4   // beginning of super class 
    // declare all variables and array
    public String ProdName;
    public double ProdNum;
    public double ProdUnits;
    public double ProdAmt;
    public Product4(){
    //implicit call to 4 argument constructors
    public Product4(String name, double number, double units, double amount)
        ProdName = name;
        ProdNum = number;
        ProdUnits = units;
        ProdAmt = amount;
    // get and set methods for all objects
    public void setProductName(String name)
    public String getProductName()
        return ProdName;
    public void setProductNumber(double number)
    public double getProductNumber()
        return ProdNum;
    public void setProductUnits(double units)
    public double getProductUnits()
        return ProdUnits;
    public void setProductAmount (double amount)
    public double getProductAmount()
        return ProdAmt;
    public double CalcValue()
        return getProductAmount()*getProductUnits();        
} // end class

public class Category4 extends Product4{
    private String catName;
    public double restockFee;
    public double fee = 0.05;

    // constructors
    public Category4(String name, double number, double units, double amount, String category)
    super(name, number, units, amount);
    catName= category;
    // set and get methods of the subclass**** double check these- may need to
    // use this.category=category; see example if need be
    public void setCatName(String category)
    public String getCatName()
        return catName;
    public double getFee()
        return super.CalcValue()*fee;
} // end subclass

Take another look at the calls in those error messages. Does your ProdArray have a getFee() method?

It does have a getFee method .. (I think).. it is in the subclass (line 189). Or am I incorrect?

ProdArray is just an array.

Correct- ProdArray[] (and a counter if int i) is the array, and according to our instructions, should obtain information regarding the item number, item name, number of units, and amount of each item. I created the ProdArray to ask for user input for 5 items, and at the end, the information should be output, but it does not seem that the String.valueOf() is working according to what I had planned. Did I mess something up in the transfer process to the set/get methods in the Product4 class?

the ProdArray[] is meant to hold objects (I actually had 20 points knocked off on Sunday because I was not using objects in my code, so I tried to update it). I still have not had one successful build since my first project.

There is a difference between calling a method on an array and calling a method on an element of the array.

All right, I think that I am officially confused now. I had gone back to re-read our text. From what I can tell, either the elements can be passed to a method for modification or the array value could be passed to the method to modify. With the program I am trying to build, the array element needs to be passed to the method because each element needs to be calculated individually and then output as one. Or am I incorrect in my understanding?

The important difference here is that ProdArray is an array reference. ProdArray[0] is an element of that array. It is those elements that you wish to call methods on.

Look at line 89 in the code you posted above. See the difference in syntax?

ok.. I think I know what you are saying. So instead of having getProductNumber(), I should have getProductNumber.. Or am I still completely wrong?

You specify the index of the element on the array itself. As I said, look at lines 89,90,91... in your code above. On those lines, you are calling methods on a particular element in the ProdArray array.

ProdArray[0] is the first element in ProdArray. It is an object of type 'Product4'. ProdArray[1] is the second element in ProdArray.

I tried to change the method calls for output to getProductNumber(i); (i is for the count in the array as it passes though each item element) and now I am receiving the error: cannot be applied to given types.

Ok, third time: look at line 89.

Do you see anything that looks like getProductNumber(i)?

all right- on line 89 I have ProdArray.getProductNumber(). The ProdArray is meant to retrieve the element stored in the given loop for , weather it be element [0] through [4] and for each pass through the array of elements, display what is in the array. You asked if I see anything that looks like getProductNumber(i) and that would be what I thought was the call on the method to retrieve the contents of the particular element .

You have already gotten the object. It is ProdArray. You call methods on it just the same as you would any Product4 object. You don't specify any indexes in the method call parenthesis.

hi im new java i want create a lgin system but im blocked

String query = "SELECT * FROM multiuser WHERE username=? and password =? and usertype=?";

        con = DriverManager.getConnection("jdbc:mysql://localhost/multiuserlogin", "root", "");
        pst = con.prepareStatement(query);
        pst.setString(1, txtuser.getText());
        pst.setString(2, txtpass.getText());
        pst.setString(3, String.valueof(jComboBox1.getSelectedItem()));   // this line i have error message no method find please can you help
            JOptionPane.showMessageDialog(this, "username and password matched and youare logined as "+rs.getString("usertype"));

    }catch(SQLException ex){
        JOptionPane.showMessageDialog(this, ex.getMessage)
commented: 9 years later? Be timely. -3
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.