Inventory program in Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #61
    Originally posted by carylrahn
    Thank you, that will be appreciated. It really hurts the students when they do not write the code themselves.
    A good point you make. I'll admit in this case I gave far much more than the student was giving. Very good of you to point that out. I hope you will be around more often and help to create better programmers than copy-paste type of programmers we are likely to get if students have solutions dumped at them each time.

    Comment

    • newbie8
      New Member
      • May 2007
      • 2

      #62
      Originally posted by carylrahn
      I teach this class and I have to tell you all that I am very frustrated looking at these forums. I have students turning in these programs as you have them posted, this earns them 0's. I understand that the moderator here is trying to help, but writing code for students is not going to help them in the long run. I will be poting this site to the faculty lounges so that all faculty are aware of this site and can take appropriate action when they grade programs. It is fine to help students, but not fine to write code for them.
      If you are like the teachers I have had so far, you are not teaching this class. Teaching is telling someone what they did wrong in their own programs and helping them to understand how to fix it. Not giving them the answers but guiding them to find the correct answers. This is the second time I have taken this class because I had no hope of passing it the first time. Both times everyone in each class has wondered how in the world they are going to pass it. We are reading all the textbook, usually three to four times, and most of us have purchased other books to help us try to understand what is going on. There is nothing in the text to help us to understand how to code the buttons that we need for the last two weeks. There is nothing that I have found online to help me understand it. This is the ONLY place I have found any answers at all.
      I agree that students should not COPY the code, but it has been very helpful to have that code to help me understand how it is supposed to work.

      Comment

      • mistb2002
        New Member
        • May 2007
        • 11

        #63
        Originally posted by hollywoood
        I am trying to add the Delete button, save and search buttons. I have tried to call my teacher and he is absolutly no help and i have read and reread the text but still have no idea what is going on.........I have the added the add button but now i am stuck. Is there a simple way in completeing this??

        Please help

        • Due Date: Day 7 [Individual] forum
        • Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit.An item added to the inventory should have an item number one more than the previous last item.
        • Add a Save button to the GUI that saves the inventory to a C:\data\invento ry.dat file.
        • Use exception handling to create the directory and file if necessary.
        • Add a search button to the GUI that allows the user to search for an item in the inventory by the product name. If the product is not found, the GUI should display an appropriate message. If the product is found, the GUI should display that product’s information in the
        GUI. • Post as an attachment

        I am having the same problem I developed the icon for add but I am lost this is my program I called this one my buttonframe



        // Display The DVDs.
        import java.text.*;
        import java.util.*;

        import java.awt.*;
        import java.awt.FlowLa yout;
        import java.awt.event. ActionListener;
        import java.awt.event. ActionEvent;
        import javax.swing.JFr ame;
        import javax.swing.JBu tton;
        import javax.swing.JTe xtField;
        import javax.swing.Ico n;
        import javax.swing.Ima geIcon;
        import javax.swing.JOp tionPane;
        import javax.swing.*;


        public class ButtonFrame extends JFrame
        {

        private JButton nextJButton; // button with just text
        private JButton prevJButton; // button with icons
        private JButton lastJButton; // button with just text
        private JButton firstJButton; // button with icons
        private JButton addJButton; // button with icons
        private JLabel logoLabel;
        private JTextField space1;
        private JTextField space2;
        private JTextField lblArtist; // text field with set size
        private JTextField txtArtist; // text field constructed with text
        private JTextField lblItemNum; // text field with set size
        private JTextField txtItemNum; // text field constructed with text
        private JTextField lblTitle; // text field with set size
        private JTextField txtTitle; // text field constructed with text
        private JTextField lblQuantity; // text field with set size
        private JTextField txtQuantity; // text field constructed with text
        private JTextField lblUnitPrice; // text field with set size
        private JTextField txtUnitPrice; // text field constructed with text
        private JTextField lblRestockFee; // text field with set size
        private JTextField txtRestockFee; // text field constructed with text
        private JTextField lblItemValue; // text field with set size
        private JTextField txtItemValue; // text field constructed with text
        private JTextField lblInventoryVal ue; // text field with set size
        private JTextField txtInventoryVal ue; // text field constructed with text


        // Just keeping an a class variable to keep count of where I am in the array
        // keeping a class variable of the myPlayer array that I passed
        UsedDVD[] arrayDVDs;
        private int currentArrayCou nter;
        private int arrayCount;
        private String invTotal;
        // public Image i;


        // i = getImage(getDoc umentBase(), "logo.gif") ;

        // ButtonFrame adds JButtons to JFrame
        public ButtonFrame(Use dDVD[] myDVDs, int totalArrayCount , String stringInventory Total)
        {

        super( "UsedDVD Inventory" );
        arrayDVDs = myDVDs;
        invTotal=string InventoryTotal;
        // drawImage(i,0,0 );

        // I am setting the local passed variable totalArrayCount
        // to the class variable arrayCounter so I can see it in the setTextfields method
        arrayCount = totalArrayCount ;
        currentArrayCou nter = 0;
        // Sertting the current array position to 0


        setLayout( new FlowLayout() ); // set frame layout
        // Load the next and previous icons
        Icon logo = new ImageIcon( getClass().getR esource( "logo.gif" ) );
        Icon iconAdd = new ImageIcon(getCl ass().getResour ce( "add.gif" ) );
        Icon iconNext = new ImageIcon( getClass().getR esource( "forward.gi f" ) );
        Icon iconPrev = new ImageIcon( getClass().getR esource( "back.gif" ) );
        Icon iconLast = new ImageIcon( getClass().getR esource( "last.gif" ) );
        Icon iconFirst = new ImageIcon( getClass().getR esource( "first.gif" ) );
        logoLabel = new JLabel("",logo, SwingConstants. LEFT);
        add(logoLabel);
        // construct Label Fields with default text and 25 columns
        space1 = new JTextField( "", 20 );
        space1.setEdita ble( false ); // disable editing
        add( space1 );
        space2 = new JTextField( "", 20 );
        space2.setEdita ble( false ); // disable editing
        add( space2 );
        lblItemNum = new JTextField( "Item Number", 25 );
        lblItemNum.setE ditable( false ); // disable editing
        add( lblItemNum );
        txtItemNum = new JTextField("", 25 );
        add( txtItemNum ); // add txtActor to JFrame
        lblArtist = new JTextField( "Actor", 25 );
        lblArtist.setEd itable( false ); // disable editing
        add( lblArtist );
        txtArtist = new JTextField("", 25 );
        add( txtArtist ); // add txtActor to JFrame
        lblTitle = new JTextField( "Title", 25 );
        lblTitle.setEdi table( false ); // disable editing
        add( lblTitle );
        txtTitle = new JTextField("", 25 );
        add( txtTitle ); // add txtActor to JFrame
        lblQuantity = new JTextField( "Quantity", 25 );
        lblQuantity.set Editable( false ); // disable editing
        add( lblQuantity );
        txtQuantity = new JTextField("", 25 );
        add( txtQuantity ); // add txtActor to JFrame
        lblUnitPrice = new JTextField( "Unit Price", 25 );
        lblUnitPrice.se tEditable( false ); // disable editing
        add( lblUnitPrice );
        txtUnitPrice = new JTextField("", 25 );
        add( txtUnitPrice ); // add txtUnitPrice to JFrame
        lblRestockFee = new JTextField( "Restocking Fee", 25 );
        lblRestockFee.s etEditable( false ); // disable editing
        add( lblRestockFee );
        txtRestockFee = new JTextField("", 25 );
        add( txtRestockFee ); // add txtActor to JFrame
        lblItemValue = new JTextField( "Total Item Value", 25 );
        lblItemValue.se tEditable( false ); // disable editing
        add( lblItemValue );
        txtItemValue = new JTextField("", 25 );
        add( txtItemValue ); // add txtActor to JFrame
        lblInventoryVal ue = new JTextField( "Total Inventory Value", 25 );
        lblInventoryVal ue.setEditable( false ); // disable editing
        add( lblInventoryVal ue );
        txtInventoryVal ue = new JTextField(invT otal, 25 );
        add( txtInventoryVal ue ); // add txtActor to JFrame
        // construct textfield with default text

        // Create the buttons
        addJButton = new JButton( "Add", iconAdd ); //button with Add
        nextJButton = new JButton( "Next", iconNext ); // button with Next
        prevJButton =new JButton( "Prev" , iconPrev ); // button with Prev
        lastJButton = new JButton( "Last", iconLast ); // button with Last
        firstJButton =new JButton( "First" , iconFirst ); // button with First
        add( addJButton) ;
        add( firstJButton ); // add plainJButton to JFrame
        add(prevJButton );
        add( nextJButton ); // add plainJButton to JFrame
        add(lastJButton );
        // create new ButtonHandler for button event handling
        ButtonHandler handler = new ButtonHandler() ;
        addJButton.addA ctionListener (handler );
        firstJButton.ad dActionListener ( handler );
        prevJButton.add ActionListener( handler );
        nextJButton.add ActionListener( handler );
        lastJButton.add ActionListener( handler );



        // Now I am going to call SetTextFields to set the text fields
        setTextFields() ;

        } // end ButtonFrame constructor





        // inner class for button event handling
        private class ButtonHandler implements ActionListener
        {
        // handle button event
        public void actionPerformed ( ActionEvent event )
        {

        // System.out.prin tln(event.getAc tionCommand());

        // See which button was pressed
        if (event.getActio nCommand()== "Next"){


        currentArrayCou nter++;
        }

        else if (event.getActio nCommand()== "Prev"){
        currentArrayCou nter--;
        }
        else if (event.getActio nCommand()== "Last"){
        currentArrayCou nter= arrayCount-1;
        }

        else if (event.getActio nCommand()== "First"){
        currentArrayCou nter = 0;
        }
        else if (event.getActio nCommand()== "Add"){
        currentArrayCou nter = +1;
        }
        else if (event.getActio nCommand()== "Delete"){
        currentArrayCou nter = 0;

        }

        setTextFields() ;

        } // end method actionPerformed
        } // end private inner class ButtonHandler



        private void setTextFields ()
        {
        // Make sure you havent gone past the end of the array
        if (currentArrayCo unter == arrayCount)
        {
        currentArrayCou nter = 0;
        }

        // Make sure you havent gone past the first if so, set it to the last
        if (currentArrayCo unter < 0)
        {
        currentArrayCou nter = arrayCount-1;
        }

        // System.out.prin tln(currentArra yCounter); // Debug statement

        NumberFormat n = NumberFormat.ge tCurrencyInstan ce(Locale.US); //Provides Locale appropriate currency format

        txtArtist.setTe xt(arrayDVDs[currentArrayCou nter].getactor());
        txtItemNum.setT ext(arrayDVDs[currentArrayCou nter].getitemnumber( ));
        txtTitle.setTex t(arrayDVDs[currentArrayCou nter].gettitle());
        txtQuantity.set Text(Double.toS tring(arrayDVDs[currentArrayCou nter].getquantity()) );
        txtUnitPrice.se tText(Double.to String(arrayDVD s[currentArrayCou nter].getunitprice() ));
        String stringRestockFe e = n.format(arrayD VDs[currentArrayCou nter].CalculateResto ckFee());
        txtRestockFee.s etText(stringRe stockFee);
        txtItemValue.se tText(n.format( arrayDVDs[currentArrayCou nter].calculateDVDVa lue()));


        }


        } // end class ButtonFrame

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #64
          Originally posted by mistb2002
          I am having the same problem I developed the icon for add but I am lost this is my program I called this one my buttonframe



          // Display The DVDs.
          import java.text.*;
          import java.util.*;

          import java.awt.*;
          import java.awt.FlowLa yout;
          import java.awt.event. ActionListener;
          import java.awt.event. ActionEvent;
          import javax.swing.JFr ame;
          import javax.swing.JBu tton;
          import javax.swing.JTe xtField;
          import javax.swing.Ico n;
          import javax.swing.Ima geIcon;
          import javax.swing.JOp tionPane;
          import javax.swing.*;


          public class ButtonFrame extends JFrame
          {

          private JButton nextJButton; // button with just text
          private JButton prevJButton; // button with icons
          private JButton lastJButton; // button with just text
          private JButton firstJButton; // button with icons
          private JButton addJButton; // button with icons
          private JLabel logoLabel;
          private JTextField space1;
          private JTextField space2;
          private JTextField lblArtist; // text field with set size
          private JTextField txtArtist; // text field constructed with text
          private JTextField lblItemNum; // text field with set size
          private JTextField txtItemNum; // text field constructed with text
          private JTextField lblTitle; // text field with set size
          private JTextField txtTitle; // text field constructed with text
          private JTextField lblQuantity; // text field with set size
          private JTextField txtQuantity; // text field constructed with text
          private JTextField lblUnitPrice; // text field with set size
          private JTextField txtUnitPrice; // text field constructed with text
          private JTextField lblRestockFee; // text field with set size
          private JTextField txtRestockFee; // text field constructed with text
          private JTextField lblItemValue; // text field with set size
          private JTextField txtItemValue; // text field constructed with text
          private JTextField lblInventoryVal ue; // text field with set size
          private JTextField txtInventoryVal ue; // text field constructed with text


          // Just keeping an a class variable to keep count of where I am in the array
          // keeping a class variable of the myPlayer array that I passed
          UsedDVD[] arrayDVDs;
          private int currentArrayCou nter;
          private int arrayCount;
          private String invTotal;
          // public Image i;


          // i = getImage(getDoc umentBase(), "logo.gif") ;

          // ButtonFrame adds JButtons to JFrame
          public ButtonFrame(Use dDVD[] myDVDs, int totalArrayCount , String stringInventory Total)
          {

          super( "UsedDVD Inventory" );
          arrayDVDs = myDVDs;
          invTotal=string InventoryTotal;
          // drawImage(i,0,0 );

          // I am setting the local passed variable totalArrayCount
          // to the class variable arrayCounter so I can see it in the setTextfields method
          arrayCount = totalArrayCount ;
          currentArrayCou nter = 0;
          // Sertting the current array position to 0


          setLayout( new FlowLayout() ); // set frame layout
          // Load the next and previous icons
          Icon logo = new ImageIcon( getClass().getR esource( "logo.gif" ) );
          Icon iconAdd = new ImageIcon(getCl ass().getResour ce( "add.gif" ) );
          Icon iconNext = new ImageIcon( getClass().getR esource( "forward.gi f" ) );
          Icon iconPrev = new ImageIcon( getClass().getR esource( "back.gif" ) );
          Icon iconLast = new ImageIcon( getClass().getR esource( "last.gif" ) );
          Icon iconFirst = new ImageIcon( getClass().getR esource( "first.gif" ) );
          logoLabel = new JLabel("",logo, SwingConstants. LEFT);
          add(logoLabel);
          // construct Label Fields with default text and 25 columns
          space1 = new JTextField( "", 20 );
          space1.setEdita ble( false ); // disable editing
          add( space1 );
          space2 = new JTextField( "", 20 );
          space2.setEdita ble( false ); // disable editing
          add( space2 );
          lblItemNum = new JTextField( "Item Number", 25 );
          lblItemNum.setE ditable( false ); // disable editing
          add( lblItemNum );
          txtItemNum = new JTextField("", 25 );
          add( txtItemNum ); // add txtActor to JFrame
          lblArtist = new JTextField( "Actor", 25 );
          lblArtist.setEd itable( false ); // disable editing
          add( lblArtist );
          txtArtist = new JTextField("", 25 );
          add( txtArtist ); // add txtActor to JFrame
          lblTitle = new JTextField( "Title", 25 );
          lblTitle.setEdi table( false ); // disable editing
          add( lblTitle );
          txtTitle = new JTextField("", 25 );
          add( txtTitle ); // add txtActor to JFrame
          lblQuantity = new JTextField( "Quantity", 25 );
          lblQuantity.set Editable( false ); // disable editing
          add( lblQuantity );
          txtQuantity = new JTextField("", 25 );
          add( txtQuantity ); // add txtActor to JFrame
          lblUnitPrice = new JTextField( "Unit Price", 25 );
          lblUnitPrice.se tEditable( false ); // disable editing
          add( lblUnitPrice );
          txtUnitPrice = new JTextField("", 25 );
          add( txtUnitPrice ); // add txtUnitPrice to JFrame
          lblRestockFee = new JTextField( "Restocking Fee", 25 );
          lblRestockFee.s etEditable( false ); // disable editing
          add( lblRestockFee );
          txtRestockFee = new JTextField("", 25 );
          add( txtRestockFee ); // add txtActor to JFrame
          lblItemValue = new JTextField( "Total Item Value", 25 );
          lblItemValue.se tEditable( false ); // disable editing
          add( lblItemValue );
          txtItemValue = new JTextField("", 25 );
          add( txtItemValue ); // add txtActor to JFrame
          lblInventoryVal ue = new JTextField( "Total Inventory Value", 25 );
          lblInventoryVal ue.setEditable( false ); // disable editing
          add( lblInventoryVal ue );
          txtInventoryVal ue = new JTextField(invT otal, 25 );
          add( txtInventoryVal ue ); // add txtActor to JFrame
          // construct textfield with default text

          // Create the buttons
          addJButton = new JButton( "Add", iconAdd ); //button with Add
          nextJButton = new JButton( "Next", iconNext ); // button with Next
          prevJButton =new JButton( "Prev" , iconPrev ); // button with Prev
          lastJButton = new JButton( "Last", iconLast ); // button with Last
          firstJButton =new JButton( "First" , iconFirst ); // button with First
          add( addJButton) ;
          add( firstJButton ); // add plainJButton to JFrame
          add(prevJButton );
          add( nextJButton ); // add plainJButton to JFrame
          add(lastJButton );
          // create new ButtonHandler for button event handling
          ButtonHandler handler = new ButtonHandler() ;
          addJButton.addA ctionListener (handler );
          firstJButton.ad dActionListener ( handler );
          prevJButton.add ActionListener( handler );
          nextJButton.add ActionListener( handler );
          lastJButton.add ActionListener( handler );



          // Now I am going to call SetTextFields to set the text fields
          setTextFields() ;

          } // end ButtonFrame constructor





          // inner class for button event handling
          private class ButtonHandler implements ActionListener
          {
          // handle button event
          public void actionPerformed ( ActionEvent event )
          {

          // System.out.prin tln(event.getAc tionCommand());

          // See which button was pressed
          if (event.getActio nCommand()== "Next"){


          currentArrayCou nter++;
          }

          else if (event.getActio nCommand()== "Prev"){
          currentArrayCou nter--;
          }
          else if (event.getActio nCommand()== "Last"){
          currentArrayCou nter= arrayCount-1;
          }

          else if (event.getActio nCommand()== "First"){
          currentArrayCou nter = 0;
          }
          else if (event.getActio nCommand()== "Add"){
          currentArrayCou nter = +1;
          }
          else if (event.getActio nCommand()== "Delete"){
          currentArrayCou nter = 0;

          }

          setTextFields() ;

          } // end method actionPerformed
          } // end private inner class ButtonHandler



          private void setTextFields ()
          {
          // Make sure you havent gone past the end of the array
          if (currentArrayCo unter == arrayCount)
          {
          currentArrayCou nter = 0;
          }

          // Make sure you havent gone past the first if so, set it to the last
          if (currentArrayCo unter < 0)
          {
          currentArrayCou nter = arrayCount-1;
          }

          // System.out.prin tln(currentArra yCounter); // Debug statement

          NumberFormat n = NumberFormat.ge tCurrencyInstan ce(Locale.US); //Provides Locale appropriate currency format

          txtArtist.setTe xt(arrayDVDs[currentArrayCou nter].getactor());
          txtItemNum.setT ext(arrayDVDs[currentArrayCou nter].getitemnumber( ));
          txtTitle.setTex t(arrayDVDs[currentArrayCou nter].gettitle());
          txtQuantity.set Text(Double.toS tring(arrayDVDs[currentArrayCou nter].getquantity()) );
          txtUnitPrice.se tText(Double.to String(arrayDVD s[currentArrayCou nter].getunitprice() ));
          String stringRestockFe e = n.format(arrayD VDs[currentArrayCou nter].CalculateResto ckFee());
          txtRestockFee.s etText(stringRe stockFee);
          txtItemValue.se tText(n.format( arrayDVDs[currentArrayCou nter].calculateDVDVa lue()));


          }


          } // end class ButtonFrame
          This post is no different from your first post. You obviously are not learning from your mistakes.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #65
            Originally posted by r035198x
            This post is no different from your first post. You obviously are not learning from your mistakes.
            mistb2002 is also running his own thread in this forum here to no avail. I replied
            in that thread two times now but I suspect we're dealing with a cut 'n paste code
            hunter here.

            btw, this thread is a total smelly wallpaper code mess ;-)

            kind regards,

            Jos

            Comment

            • mistb2002
              New Member
              • May 2007
              • 11

              #66
              no I am not cutting a pasting anything I am actually in attendance at the university of phoenix and I partially have just the icon for add and I am lost in figuring out how to add the delete icon and then producing the screen for a user input. you weren't helping me so I went to another forum. I have no intentions on copying anyones work I want to do this on my own but I have been on this pc since 12am last night. I am getting truly frustrated at this program.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #67
                Originally posted by mistb2002
                no I am not cutting a pasting anything I am actually in attendance at the university of phoenix and I partially have just the icon for add and I am lost in figuring out how to add the delete icon and then producing the screen for a user input. you weren't helping me so I went to another forum. I have no intentions on copying anyones work I want to do this on my own but I have been on this pc since 12am last night. I am getting truly frustrated at this program.
                I was helping you but you don't realize it (yet?) I wasn't spoonfeeding you any
                code but I was explaining how to post a sensible question in any forum;
                I also explained how model-view-controller separation should be used in an
                application. All that in your other thread.

                kind regards,

                Jos

                Comment

                • mistb2002
                  New Member
                  • May 2007
                  • 11

                  #68
                  Originally posted by hollywoood
                  I have the add button working......I just need help with the other.

                  Thanks
                  How did you get your add button to work I have my delete button working but I am stuck from there. this what my program looks like:

                  I finally got my add button to work thank god for back up disk because I did not save the correct file on my pc. I was using the correct code all along but just in the wrong order.

                  Comment

                  Working...