C:\Documents and Settings\Sam\GUICDInventory.java:22: cannot find symbol
symbol : constructor JList(CDInventory)
location: class javax.swing.JList
cDJList = new JList( gUICDInventory );
Here's the code where I get the error:
Expand|Select|Wrap|Line Numbers
- // GUICDInventory.java
- // uses CD class
- import java.awt.FlowLayout;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.SwingConstants;
- import javax.swing.JList;
- import javax.swing.JScrollPane;
- public class GUICDInventory extends JFrame
- {
- CDInventory gUICDInventory = new CDInventory();
- private JList cDJList;
- public GUICDInventory()
- {
- super( "Compact Disc Inventory" );
- setLayout( new FlowLayout() );
- cDJList = new JList( gUICDInventory );
- cDJList.setVisibleRowCount( 25 );
- add( new JScrollPane( cDJList ) );
- }
- // executes application
- public static void main( String args[] )
- {
- GUICDInventory guICDInventory = new GUICDInventory();
- guICDInventory.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
- guICDInventory.setSize( 500, 500 );
- guICDInventory.setVisible( true );
- } // end main
- } // end class GUICDInventory
Expand|Select|Wrap|Line Numbers
- // CDInventory.java
- // uses CD class
- public class CDInventory
- {
- // executes application
- public static void main( String args[] )
- {
- CD completeCDInventory[] = new CD2[ 5 ]; // creates a new 5 element array
- // populates array with objects that implement CD
- completeCDInventory[ 0 ] = new CD2( "Sixpence None the Richer" , "D121401" , 12 , 11.99, 1990 );
- completeCDInventory[ 1 ] = new CD2( "Clear" , "D126413" , 10 , 10.99, 1998 );
- completeCDInventory[ 2 ] = new CD2( "NewsBoys: Love Liberty Disco" , "2438-51720-2" , 10 , 12.99, 1999 );
- completeCDInventory[ 3 ] = new CD2( "Skillet: Hey You, I Love Your Soul" , "D122966" , 9 , 9.99, 1998 );
- completeCDInventory[ 4 ] = new CD2( "Michael Sweet: Real" , "020831-1376-204" , 15 , 12.99, 1995 );
- double totalInventoryValue = CD.calculateTotalInventory( completeCDInventory ); //declares totalInventoryValue variable
- CD.displayTotalInventory( completeCDInventory ); //calls CD's display method
- System.out.println("Total Inventory Value is: " + totalInventoryValue);
- CD.sortedCDInventory( completeCDInventory ); // calls CD's sortedCDInventory method
- System.out.println("Total Inventory Value is: " + totalInventoryValue);
- } // end main
- } // end class CDInventory
Expand|Select|Wrap|Line Numbers
- // CD2.java
- // subclass of CD
- public class CD2 extends CD
- {
- protected int copyrightDate; // CDs copyright date variable declaration
- private double price2;
- // constructor
- public CD2( String title, String prodNumber, double numStock, double price, int copyrightDate )
- {
- // explicit call to superclass CD constructor
- super( title, prodNumber, numStock, price );
- this.copyrightDate = copyrightDate;
- }// end constructor
- public double getInventoryValue() // modified subclass method to add restocking fee
- {
- price2 = price + price * 0.05;
- return numStock * price2;
- } //end getInventoryValue
- public void displayInventory() // modified subclass display method
- {
- System.out.printf( "\n%-22s%s\n%-22s%d\n%-22s%s\n%-22s%.2f\n%-22s%s%.2f\n%-22s%s%.2f\n%-22s%s%.2f\n \n" , "CD Title:", title, "Copyright Date:", copyrightDate, "Product Number:", prodNumber , "Number in Stock:", numStock , "CD Price:" , "$" , price , "Restocking fee (5%):", "$", price*0.05, "Inventory Value:" , "$" , getInventoryValue() );
- } // end method
- }//end class CD2
Expand|Select|Wrap|Line Numbers
- // CD.java
- // Represents a compact disc object
- import java.util.Arrays;
- class CD implements Comparable
- {
- protected String title; // CD title (name of product)
- protected String prodNumber; // CD product number
- protected double numStock; // CD stock number
- protected double price; // price of CD
- protected double inventoryValue; //number of units in stock times price of each unit
- // constructor initializes CD information
- public CD( String title, String prodNumber, double numStock, double price )
- {
- this.title = title; // Artist: album name
- this.prodNumber = prodNumber; //product number
- this.numStock = numStock; // number of CDs in stock
- this.price = price; //price per CD
- } // end constructor
- public double getInventoryValue()
- {
- return numStock * price;
- } //end getInventoryValue
- public void displayInventory()
- {
- System.out.printf( "\n%s%35s\n%s%12s\n%s%9.2f\n%s%12s%.2f\n%s%.2f\n%s%5s%.2f\n \n" , "CD Title:", title, "Product Number:", prodNumber , "Number in Stock:", numStock , "CD Price:" , "$" , price , "Restocking fee (5%):", price*0.05, "Inventory Value:" , "$" , getInventoryValue() );
- } // end method
- public static double calculateTotalInventory( CD completeCDInventory[] )
- {
- double totalInventoryValue = 0;
- for ( int count = 0; count < completeCDInventory.length; count++ )
- {
- totalInventoryValue += completeCDInventory[count].getInventoryValue();
- } // end for
- return totalInventoryValue;
- } // end calculateTotalInventory
- public static void displayTotalInventory( CD completeCDInventory[] )
- {
- System.out.printf( "\n%s\n" ,"Inventory of CDs (unsorted):" );
- for ( int count = 0; count < completeCDInventory.length; count++ )
- {
- System.out.printf( "%s%d", "Item# ", count + 1 );
- completeCDInventory[count].displayInventory();
- }// end for
- }// end displayTotalInventory
- public int compareTo( Object obj ) //overlaod compareTo method
- {
- CD tmp = ( CD )obj;
- if( this.title.compareTo( tmp.title ) < 0 )
- {
- return -1; //instance lt received
- }
- else if( this.title.compareTo( tmp.title ) > 0 )
- {
- return 1; //instance gt received
- }
- return 0; //instance == received
- }// end compareTo method
- public static void sortedCDInventory( CD completeCDInventory[] )
- {
- System.out.printf( "\n%s\n" ,"Inventory of CDs (sorted by title):" );
- Arrays.sort( completeCDInventory ); // sort array
- for( int count = 0; count < completeCDInventory.length; count++ )
- {
- System.out.printf( "%s%d", "Item# ", count + 1 );
- completeCDInventory[count].displayInventory();}
- }
- } // end class CD