I am having some issues with my Inventory Program and could use some help. I had the program working last night where my GUI would display the correct categories but today when I tried to get the restocking fee to add in to the value, I seemed to have messed up my file. If anyone can help that would be great.

I think my error with the file not working is in the super of the MovieDirector class since that is the only part of my file that is in red. But I also still cannot get the restock fee to add into the value field. Any ideas. Thanks

Here are my 3 files. The error I am receiving is:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: guiinventoryprogram.Dvd.<init>
at guiinventoryprogram.MovieDirector.<init>(MovieDirector.java:9)
at guiinventoryprogram.GUIInventoryProgram.<init>(GUIInventoryProgram.java:103)
at guiinventoryprogram.GUIInventoryProgram.main(GUIInventoryProgram.java:301)
Java Result: 1

package guiinventoryprogram;

/** Program: Inventory Program
 *  File: InventoryProgram.java
 *  Summary: Inventory program that gives the name of the movie, the quanity in stock, the price, and the item number
 *  Author: Garvis Hopwood
 *  Date: August, 4 2011
 */

import java.awt.GridLayout;       // required to create a grid layout

import java.awt.BorderLayout;     // required to create a border layout

import java.awt.event.ActionEvent; // required for click events

import java.awt.event.ActionListener; // required for click events

import javax.swing.JPanel;  // required to create panels

import javax.swing.JFrame;  // required to use the frame

import javax.swing.JButton;  // required to create buttons

import javax.swing.JLabel;  // required to create text fields

import javax.swing.JTextField; // required to create text fields

import java.util.Arrays;  // required to sort array

import java.text.DecimalFormat;

public class GUIInventoryProgram extends JFrame implements ActionListener

{

      // Declare Class Variables      

      //Declare two panels. gridPanel is main panel. panel is inserted into gridPanel.

      private JPanel gridPanel = new JPanel(); // one panel that contains my gridlayout.

      private JPanel panel = new JPanel(); // panel used to contain buttons, labels and text fields

      // Declare buttons

      JButton nextButton; // first button

      // Declare Text Fields

      JTextField TitleField; // Dvd Title

      JTextField UnitsField; // Units Field

      JTextField ItemNumberField; // Item Number field

      JTextField PriceField; // Dvd Price field

      JTextField ValueField;  // Value field
      
      JTextField DirectorField;
      

      // Declare Labels

      JLabel lblTitle; // Title label

      JLabel lblUnits; // Units Label

      JLabel lblItemNumber; // Item Number label

      JLabel lblPrice; // Price Label

      JLabel lblValue;  // Value of DVDs Label
      
      JLabel lblDirector;

      // Declare 5 Dvd Objecs

      Dvd dvd1;

      Dvd dvd2;

      Dvd dvd3;

      Dvd dvd4;

      Dvd dvd5;
      
      private static final int MAX_dvds = 5; // set maximum size for DVD Array

      Dvd[] dvd = new Dvd[MAX_dvds]; // create Dvd Array object
      
      DecimalFormat formatter = new DecimalFormat("$##,###.00");
      
      private static DecimalFormat currency = new DecimalFormat("$#,##0.00");

      private static int ArrayIndex = 0; // array index

      public GUIInventoryProgram() // constructor

      {

        MovieDirector d1 = new MovieDirector("Transformers", 7, 1002, 19.98, "Michael Bay");
        // Creates an instance of the DVD class and initialize class instance variables
        MovieDirector d2 = new MovieDirector("Green Mile", 3, 542, 14.50, "Frank Darabont");
        // Creates an instance of the DVD class and initialize class instance variables
        MovieDirector d3 = new MovieDirector("Lord of the Rings", 5, 937, 24.98, "Peter Jackson");
        // Creates an instance of the DVD class and initialize class instance variables
        MovieDirector d4 = new MovieDirector("Jar Head", 2, 865, 9.75, "Sam Mendes");
        // Creates an instance of the DVD class and initialize class instance variables
        MovieDirector d5 = new MovieDirector("Inception", 6, 1157, 21.97, "Christopher Nolan");
        // Creates an instance of the DVD class and initialize class instance variables
        

        // adding Dvd objects to the array
        dvd[0] = d1; // adding Transformers to the array of dvds
        dvd[1] = d2; // adding Green Mile to the array of dvds 
        dvd[2] = d3; // adding Lord of the Rings to the array of dvds
        dvd[3] = d4; // adding Jar Head to the array of dvds
        dvd[4] = d5; // adding Inception to the array of dvds
        
        Dvd.sortByTitle(dvd);  // sort the array by name of title


            gridPanel.setLayout(new BorderLayout()); // create a border layout

            gridPanel.add(this.createLabelPanel(), BorderLayout.WEST); // add label panel

            gridPanel.add(this.createTextPanel(), BorderLayout.CENTER); // add field panel

            gridPanel.add(this.createButtonPanel(), BorderLayout.SOUTH); // add button panel

            add(gridPanel);

      }
     
      // helper method creates a panel for the button 

      private JPanel createButtonPanel()

      {

           // ActionListener btnListen = new ButtonListener(); // create listener

             // create button objects

            nextButton = new JButton("Display DVD Information");  // create and label button

            nextButton.setActionCommand("Next");  // action command for click button event
            

           // nextButton.addActionListener(btnListen);  // button listener for click button event

            nextButton.addActionListener(this);

            // create panel object

            JPanel pobj = new JPanel(); 

            pobj.add(nextButton); // add next button to panel

            return pobj; // return panel

      } // end createButtonPanel method

      private JPanel createLabelPanel()

      {

            // create instance of label objects

            lblTitle = new JLabel("Title:"); // label for Title of DVD

            lblUnits = new JLabel("Units:"); // label for Units in stock for DVD

            lblItemNumber = new JLabel("Item Number:"); // label for DVD Item Number

            lblPrice = new JLabel("Price:"); // label for price of DVD

            lblValue = new JLabel("Value of Items:"); // lable for value of DVD
            
            lblDirector = new JLabel ("Directors Name:");

            panel = new JPanel();

            panel.setLayout(new GridLayout(6, 1));

            // add labels to the panel

            panel.add(lblTitle);

            panel.add(lblUnits);

            panel.add(lblItemNumber);

            panel.add(lblPrice);

            panel.add(lblValue);
            
            panel.add(lblDirector);

            return panel;

      } // end createLabelPanel method

      private JPanel createTextPanel()

      {

            //create instances of text box objects

            TitleField = new JTextField(); // Title text field

            TitleField.setEditable(false);  // set field to not editable to prevent user from changing the data

            UnitsField = new JTextField(); // Units text field

            UnitsField.setEditable(false);  // set field to not editable to prevent user from changing the data

            ItemNumberField = new JTextField(); // Item Number field

            ItemNumberField.setEditable(false);  // set field to not editable to prevent user from changing the data

            PriceField = new JTextField();   // Price text field

            PriceField.setEditable(false);   // set field to not editable to prevent user from changing the data

            ValueField = new JTextField();    // Value text field to sum the total of the DVDs value.

            ValueField.setEditable(false);   // set field to not editable to prevent user from changing the data
            
            DirectorField = new JTextField();
            
            DirectorField.setEditable(false);


            panel = new JPanel(); // create panel object

            panel.setLayout(new GridLayout(6, 1)); // create grid layout for fields.

            panel.add(TitleField); // add the Title field to the grid layout

            panel.add(UnitsField); // add the Units field to the grid layout

            panel.add(ItemNumberField); // add the Item Number field to the grid layout

            panel.add(PriceField); // add the Price field to the grid layout

            panel.add(ValueField); // add the total value field to the grid layout
            
            panel.add(DirectorField);

            return panel; // return the panel

      } // end createTextPanel method

 
            @ Override public void actionPerformed(ActionEvent e)

            {                 

                  // add button functions

                  if ("Next".equals(e.getActionCommand()))

                        if (ArrayIndex < dvd.length) 

                        {

                              TitleField.setText(dvd[ArrayIndex].getDvdTitle()); // get the Dvds title

                              // and assign it the name text field.

                              UnitsField.setText(String.valueOf(dvd[ArrayIndex].getDvdUnits())); 
                              // get the units in stock and assign it the Units text field.

                              ItemNumberField.setText(String.valueOf(dvd[ArrayIndex].getDvdItemNumber()));

                              // get Dvds item number and assign it the item number text field.                              
                              
                              PriceField.setText(String.format("$ %8.2f", dvd[ArrayIndex].getDvdPrice()));

                              // get the Price of the DVD and assign it the price text field.

                              ValueField.setText(String.format("$ %8.2f", dvd[ArrayIndex].getDvdValue()));  
                              // display the sum of the total of the DVDs in stock
                              
                              DirectorField.setText(String.valueOf(dvd[ArrayIndex].getdvdDirector()));
                              // display the Directors name of the DVD

                              ArrayIndex = ArrayIndex + 1; // increment the array index to get to the next value

                        } // end if

            } // end actionPerformed

    public static void main(String[] args)

      {

            JFrame frame = new GUIInventoryProgram(); // creat a frame object

            frame.setSize(400, 300); // set the size of the window - 400 is width, 200 is height

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // close the application

            frame.setTitle("DVD Inventory"); // set the title of the window

            frame.setLocationRelativeTo( null );  // center the form

            frame.setVisible(true); // display form

      } // end main

 

} // end GUIInventoryProgram class
package guiinventoryprogram;

class Dvd {
    // declare instance variables
    private String dvdTitle; //title of dvd
    private int dvdUnits; // number of units of the dvd
    private double dvdItemNumber; // item number of the dvd
    private double dvdPrice; // Price of the dvd
    private String dvdDirector;
    public Dvd()
    {
    }
    //declare DVD constructor that shows title, stock, item, and price
    public Dvd(String Title, int Units, double ItemNumber, double Price, String Director) {
    //call to Object constructor occurs here
        dvdTitle = Title;
        dvdUnits = Units;
        dvdItemNumber = ItemNumber;
        dvdPrice = Price;
        dvdDirector = Director;
        
    } //end four-argument constructor
    
    //set DVD name
    public void setdvdTitle(String Title) {
        setdvdTitle(Title);
    } //end method setDvdTitle

    //return dvd Title
    public String getDvdTitle() {
    return dvdTitle;
    } //end method getDvdTitle

    //set Dvd stock
    public void setDvdUnits(int Units) {
    dvdUnits = (Units < 0) ? 0 : Units;
    } //end method setDvdStock

    //return dvd stock
    public double getDvdUnits() {
    return dvdUnits;
    } //end method getDvdStock

    public void setDvdItemNumber(double ItemNumber) {
    dvdItemNumber = (ItemNumber < 0.0) ? 0.0 : ItemNumber;
    } //end method set dvd Item

    //return dvd item
    public double getDvdItemNumber() {
    return dvdItemNumber;
    } //end method getDvdItem

    public void setDvdPrice(double Price) {
    dvdPrice = (Price < 0.0) ? 0.0 : Price;
    } //end method SetDvdPrice

    //return dvd price
    public double getDvdPrice() {
    return dvdPrice;
    } //end method get Dvd Price

    // calculate inventory value
    public double getDvdValue() {
    return  getDvdPrice() * dvdUnits;
    } //end method value
    
        public double getdvdRestockingfee() {
        return getDvdValue() * .05;
    }
    
    public void setdvdDirector(String Director) {
    setdvdDirector(Director);
    } //end method setDvdTitle

    //return dvd Title
    public String getdvdDirector() {
    return dvdDirector;
    } //end method getDvdTitle
    

        public static void sortByTitle(Dvd dvd[])
    {    // sort the dvd by title
        Dvd temp;
        for(double j = dvd.length - 2; j >= 0; j--)
                for(int i = 0 ; i <= j ; i++)
                    if(dvd [ i ].getDvdTitle().compareTo(dvd[ i + 1 ].getDvdTitle())>0)
                    {
                    temp=dvd[ i ];
                    dvd[ i ] = dvd[ i + 1 ];
                    dvd[ i + 1 ] = temp;
                    }

                } // end sort by title method

} // end class dvd
package guiinventoryprogram;

class MovieDirector extends Dvd{
    private String Director;
    private double  Restockingfee;
    
    public MovieDirector(String Title, int Units, double ItemNumber, double Price, String Director)
    {
        super(Title, Units, ItemNumber, Price);
        this.Director=Director;
        this.Restockingfee = Restockingfee;
        
    }

    public String getDirector() {
        return Director;
    }

    public void setDirector(String Director) {
        this.Director = Director;
    }
    

    public double getRestockingfee() {
        return getDvdValue() * 0.05;
    }    
        public void setRestockingfee (double Restockingfee){
        this.Restockingfee = Restockingfee;
        }
}

Recommended Answers

All 3 Replies

Check your Dvd class constructors against the one you are trying to invoke with the super() call in the MovieDirector constructor.

Thanks, I checked and corrected my constructors and now the GUI is at least working. Any ideas how to get the restocking fee added into the total value of each dvd value?

totalValue += restockFee; // add restocking fee to total value

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.