Results 1 to 4 of 4
  1. #1
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Help with Errors in Inventory Program

    I hope someone can help me with this. I have the following problem due by Sunday, August 10. I am getting 13 errors when I try to compile the program. Most of the errors are related to the buttons I am trying to add. I think what is wrong with one button is the same thing that is wrong will all the buttons. I cannot seem to figure out what is wrong. Please help me solve the errors in this program. Thank you! The errors and my program are listed below.


    Assignment
    Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display. Add a company logo to the GUI using Java graphics classes.

    Errors
    InventoryProgramPart5.java:235: totalValue is already defined in RunInv
    JTextField totalValue = new JTextField(20);
    ^
    InventoryProgramPart5.java:196: RunInv is not abstract and does not override abs
    tract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.Actio
    nListener
    class RunInv extends JFrame implements ActionListener
    ^
    InventoryProgramPart5.java:242: cannot find symbol
    symbol : method makeTheDataItems()
    location: class RunInv
    makeTheDataItems();
    ^
    InventoryProgramPart5.java:266: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton first = makeButton( "First" );
    ^
    InventoryProgramPart5.java:267: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton next = makeButton( "Next" );
    ^
    InventoryProgramPart5.java:268: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton previous = makeButton( "Previous" );
    ^
    InventoryProgramPart5.java:269: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton last = makeButton( "Last" );
    ^
    InventoryProgramPart5.java:270: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton exit = makeButton( "Exit" );
    ^
    InventoryProgramPart5.java:273: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton add = makeButton( "Add" );
    ^
    InventoryProgramPart5.java:274: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton delete = makeButton( "Delete" );
    ^
    InventoryProgramPart5.java:275: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton modify = makeButton( "Modify" );
    ^
    InventoryProgramPart5.java:276: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton save = makeButton( "Save" );
    ^
    InventoryProgramPart5.java:277: cannot find symbol
    symbol : method makeButton(java.lang.String)
    location: class RunInv
    JButton find = makeButton( "Find" );
    ^
    13 errors

    Java Code:
    // CheckPoint:  InventoryProgramPart5.java
    // Week 8
    // This program calculates inventory value
    
    import java.util.Arrays;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class InventoryProgramPart5
    {
         public static void main( String args[] )
         {
              double restockingFee = 0.05;
              manufacturer[] inventory = new manufacturer[5]; // array of 5
    
              inventory[0] = new manufacturer
                   ( "notepads", restockingFee, "4000", "Ampad", 60, 2.75 );
              inventory[1] = new manufacturer
                   ( "pencils", restockingFee, "5000", "Bic", 75, 1.25 );
              inventory[2] = new manufacturer
                   ( "folders", restockingFee, "2000", "3M", 30, 4.75 );
              inventory[3] = new manufacturer
                   ( "envelopes", restockingFee, "1000", "Universal", 15, 5.25 );
              inventory[4] = new manufacturer
                   ( "markers", restockingFee, "3000", "Sanford", 45, 3.50 );
    
              manufacturer temp[] = new manufacturer[1];
          
                   for( int j = 0; j < inventory.length - 1; j++ )
                   {
                        for( int k = 0; k < inventory.length - 1; k++ )
                        {
                             if( inventory[k].getItemName().compareToIgnoreCase
                                  ( inventory[k+1].getItemName() ) > 0 )
                             {
                                  temp[0] = inventory[k];
                                  inventory[k] = inventory[k+1];
                                  inventory[k+1] = temp[0];
                             } // end if
                        } // end for    
                   } // end for
    
                   javax.swing.JTextArea ta = new javax.swing.JTextArea( 10, 25 );
                   for( int j = 0; j < inventory.length; j++ )
                   {
    
                   // System.out.println( inventory[j].toString() );<-----------------
    
                        ta.append( inventory[j].toString()+"\n" );
                   } // end for
    
              // System.out.printf( "Total value of all inventory = $%.2f",
              // Inventory.etTotalValueOfAllInventory( inventory ) );
              // return; // <------------------above line and this line
              ta.append("Total value of all inventory = "+product.getTotalValueOfAllInventory(inventory));
              javax.swing.JFrame frame = new javax.swing.JFrame();
              frame.getContentPane().add( new javax.swing.JScrollPane(ta) );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE );
              frame.setVisible( true );
    
         } // end main
    
    } // end class InventoryProgramPart5
    
    // The product class
    class product
    {
         String productNumber;
         String name;
         int numberOfUnits;
         double pricePerUnit;
    
         // create a new instance of Inventory
         // main constructor for the class
         product( String Item_Number, String Item_Name, int Items_in_Stock, double Item_Price )
         {
              productNumber = Item_Number;
              name = Item_Name;
              numberOfUnits = Items_in_Stock;
              pricePerUnit = Item_Price;
         } // end constructor
    
         // sets the product name
         public void setItemName( String Item_Name )
         {
              name = Item_Name;
         }
    
         // sets the product number
         public void setItemNumber( String Item_Number )
         {
              productNumber = Item_Number;
         }
    
         // sets the number of units in stock
         public void setItemsInStock( int Items_in_Stock )
         {
              numberOfUnits = Items_in_Stock;
         }
    
         // sets the price of the product
         public void setItemPrice( double Item_Price )
         {
              pricePerUnit = Item_Price;
         }
    
         // returns product name
         public String getItemName()
         {
              return name;
         }
    
         // returns product number
         public String getItemNumber()
         {
              return productNumber;
         }
    
         // returns units in stock
         public int getItemsInStock()
         {
              return numberOfUnits;
         }
    
         // returns product price
         public double getItemPrice()
         {
              return pricePerUnit;
         }
    
         // returns the total value of inventory
         public double getInventoryValue()
         {
              return pricePerUnit * numberOfUnits;
         }
    
         public static double getTotalValueOfAllInventory( product[] inv )
         {
              double tot = 0.0;
              for( int i = 0; i < inv.length; i++ )
              {
                   tot += inv[i].getInventoryValue();
              }
              return tot;
         }
    
         public String toString()
         {
              StringBuffer sb = new StringBuffer();
              sb.append( "Product Name:  \t" ).append( name ).append( "\n" );
              sb.append( "Product Number:  \t" ).append( productNumber ).append( "\n" );
              sb.append( "Units in Stock:       \t" ).append( numberOfUnits ).append( "\n" );
              sb.append( "Unit Price:            \t" ).append( String.format( "$%.2f%n", pricePerUnit ) );
              sb.append( "Inventory Value:  \t" ).append(String.format("$%.2f%n", this.getInventoryValue())); 
                   return sb.toString();
         } // end toString
    } // end class product
    
    class manufacturer extends product
    { 
         // manufacturer of product
         String manufacturer;
    
         // percentage added to base price as restocking fee
         double restockingFee;
    
         // actual inventory value will be the base inventory value plus
         // the base inventory value times this amount ( value + ( value * restockingFee ) )
         public manufacturer( String Item_Name, double restockingFee, String Item_Number,
              String manufacturer, int Items_in_Stock, double Item_Price )
    
         {
              super( Item_Number, Item_Name, Items_in_Stock, Item_Price);
                   this.manufacturer = manufacturer;               this.restockingFee = restockingFee;
         } 
    
         // returns inventory value plus the restocking fee
         public double getInventoryValue()
         {
              return super.getInventoryValue() + ( super.getInventoryValue() * restockingFee );
         } // end getInventoryValue
    
         public String toString()
         {
              StringBuffer sb = new StringBuffer( "Manufacturer:       \t" ).append( manufacturer ).append( "\n" );
              sb.append( super.toString() );
                   return sb.toString();
    
         } // end toString
    
    } // end class manufacturer
    
    class RunInv extends JFrame implements ActionListener
    {
         // utility class for displaying the picture
         private class MyPanel extends JPanel
         {
              ImageIcon image = new ImageIcon( "HTML.jpg" );
              int width = image.getIconWidth();
              int height = image.getIconHeight();
              long angle = 0;
              public MyPanel()
              {
                   super();
              }
    
              public void paintComponent( Graphics g )
              {
                   super.paintComponent(g);
                   Graphics2D g2d = ( Graphics2D )g;
                   g2d.rotate( Math.toRadians(angle), 200+width/2, 90+height/2 );
                   g2d.drawImage( image.getImage(), 5, 5, this );
                   g2d.dispose();
              }
    
         } // end class MyPanel
    
         int currentIndex; // currently displayed Item
         manufacturer[] inventory = new manufacturer[5];
         JLabel name;
         JLabel number;
         JLabel manufacturer;
         JLabel units;
         JLabel price;
         JLabel fee;
         JLabel totalValue;
         JTextField nameField = new JTextField(20);
         JTextField numberField = new JTextField(20);
         JTextField manufacturerField = new JTextField(20);
         JTextField unitsField = new JTextField(20);
         JTextField priceField = new JTextField(20);
         JTextField totalValue = new JTextField(20);
         JPanel display;
         JPanel displayHolder;
         JPanel panel;
    
         public RunInv()
         {
              makeTheDataItems();
              setSize( 700, 300 );
              setTitle( "Inventory Program" );
    
              // make the panels
              display = new JPanel();
              JPanel other = new JPanel();
              JPanel picture = new MyPanel();
              JPanel buttons = new JPanel();
              JPanel centerPanel = new JPanel();
              displayHolder = new JPanel();
              display.setLayout( new GridLayout( 3, 3 ) );
              other.setLayout( new GridLayout( 2, 1 ) );
    
              // make the labels
              name = new JLabel( "Product Name:" );
              number = new JLabel( "Product Number:" );
              manufacturer = new JLabel( "Manufacturer:" );
              units = new JLabel( "Units in Stock:" );
              price = new JLabel( "Price     :$" );
              fee = new JLabel( "Fee     :$" );
              totalValue = new JLabel( "Total value : $" );
    
              // make the buttons
              JButton first = makeButton( "First" );
              JButton next = makeButton( "Next" );
              JButton previous = makeButton( "Previous" );
              JButton last = makeButton( "Last" );
              JButton exit = makeButton( "Exit" );
    
              // other buttons
              JButton add = makeButton( "Add" );
              JButton delete = makeButton( "Delete" );
              JButton modify = makeButton( "Modify" );
              JButton save = makeButton( "Save" );
              JButton find = makeButton( "Find" );
                   // add the labels to the display panel
                   display.add( name );
                   display.add( number );
                   display.add( manufacturer );
                   display.add( units );
                   display.add( price );
                   display.add( fee );
                   display.add( totalValue );
    
                   // add the buttons to the buttonPanel
                   buttons.add( first );
                   buttons.add( previous );
                   buttons.add( next );
                   buttons.add( last );
                   buttons.add( exit );
    
                   // add the picture panel and display to the centerPanel
                   displayHolder.add( display );
                   centerPanel.setLayout( new GridLayout( 2, 1 ) );
                   centerPanel.add( picture );
                   centerPanel.add( displayHolder );
                   other.add( buttons );
                   JPanel forAdd = new JPanel(); // add the other buttons to this panel
                   forAdd.add( find );
                   forAdd.add( add );
                   forAdd.add( modify );
                   forAdd.add( delete );
                   forAdd.add( save );
                   other.add( forAdd );
    
                   // add the panels to the frame
                   getContentPane().add( centerPanel, "Center" );
                   getContentPane().add( other, "South" );
                   this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                   setVisible( true );
    
         } // end RunInv
    
    } // end class RunInv extends JFrame implements ActionListener

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,514
    Rep Power
    25

    Default

    The error messages give the line number where the error occured.
    Go to each of those lines and put a comment next to it so that they can be easily seen in your post. For example: //<<<<<< ERROR HERE LINE 235

    Where is the method makeButton defined? Can it be seen where it is being used?

  3. #3
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default

    I do not know how to fix this error message. What does this mean and how do I fix it?

    InventoryProgramPart5.java:196: RunInv is not abstract and does not override abs
    tract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.Actio
    nListener
    class RunInv extends JFrame implements ActionListener
    ^

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,514
    Rep Power
    25

    Default

    Why did you code the following?
    implements ActionListener
    The above requires that you code ALL of the methods defined in the interface in your class. Have you misspelled it or given it the wrong signature?

Similar Threads

  1. Java Inventory Program Part 3
    By ljk8950 in forum New To Java
    Replies: 18
    Last Post: 07-28-2008, 05:47 AM
  2. Inventory Program Part 3 - DUE TODAY (7/28/08)
    By ljk8950 in forum New To Java
    Replies: 7
    Last Post: 07-27-2008, 10:28 PM
  3. Inventory Program modification help
    By badness in forum Java Applets
    Replies: 1
    Last Post: 01-17-2008, 05:24 AM
  4. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 07:00 AM
  5. Inventory program
    By Nexcompac in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •