import java.util.Scanner;// Import and use scanner 
import java.util.Arrays; 
public class Inventory3 {
//begins execution of program
public static void main(String[] args) { 
//create new object
CD mycd = new CD();
//create and intialize array of CDs
CD[] cdArray = new CD[3];
cdArray[0] = new CD("Rolling Stones",100,25,14.99);
cdArray[1] = new CD("Pearl Jam",101,18,12.99);
cdArray[2] = new CD("Journey",102,11,15.99);

for(int i=0; i < cdArray.length; i++)
{

System.out.println("\nCategory, Unit, and Price Information\n" + cdArray[i].toString());
    cdArray[i].showInventory();
}

//sorting items
private static void sortArray; {   
   Arrays.sort( cdArray, new productComparator());     

} // end method  

double total = 0; 

sortArray();

for (int item =0; item < cdArray.length; item ++) {

System.out.println("Category is " + cdArray[item].getName());
System.out.println("The number of units in stock is " + cdArray[item].getitems());
System.out.println("The price of each CD is $" + cdArray[item].getprice());
System.out.println("The item number is " + cdArray[item].getitemNum());
System.out.println("The value of inventory is $" + cdArray[item].getvalue());

total=total+cdArray[item].getvalue();

}

    // display the value of entire inventory
System.out.println( "Total inventory value is: $%.2f", total ); 

//sorting items
private static void sortArray; {   

   Arrays.sort( cdArray, new ProductComparator());     


} // end method  
} //end main

} // end class Inventory

I am new to the daniweb site, so please bare with me. I already have compiled correctly the "CD class" and another class calcuating a re-stocking fee. I am having an issue getting this array to work work properly and display properly. There is no GUI needed.. I obviously am doing something wrong and could use some guidance please!

Recommended Answers

All 3 Replies

And what's the problem you're having? Does the code compile? If the code compiles, what happens when you run it, and how is that different from what you wanted?

Please be specific when you ask a question, so you can get the answer you're looking for.

This portion of the code does not compile at all, and I was told there were some "simple" corrections that had to be made in order for it to do so. This specific code keeps giving me 8 error messages that all point to "public static void" statements, but I can't figure out what I am doing wrong... I hope this is the answer you were lookin for.

It's a start. It points me to these:

private static void sortArray; {
private static void sortArray; {


First problem, that's not a legal method declaration for several reasons.
- a concrete method can't be followed by a semicolon
- a concrete method has to be followed by a pair of parentheses
- a static method can't access instance fields, which you haven't got any of anyway, so it's going to need some formal parameters on which to work, which will be declared in the parentheses
- you can't declare two methods with the same signature - that is, you can only have one sortArray() method. You'll eventually learn about overloading, which allows you to declare multiple methods with the same name but different parameter lists, but that's not now.

I would suggest you have a look at this tutorial and try to fix these issues. If you're still having trouble after you give it a good try, come back - but I'll be skeptical about how good a try you've given it if I see you posting again in an hour! :)

And, just as a tip, if you have error messages, please do post them when you're asking a question. They may not mean anything to you, but a more experienced programmer can often use them to diagnose the problem, and give you a good answer right away. You might even learn how to do this yourself.

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.