Inventory program in Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stevedub
    New Member
    • Jan 2007
    • 40

    #46
    Well, I get this error when compiled:
    Code:
    C:\Documents and Settings\stevew\My Documents\Java test\Inventory2.java:217: 'class' or 'interface' expected
    else if(command.equals("Add Item")) {
    ^
    C:\Documents and Settings\stevew\My Documents\Java test\Inventory2.java:220: 'class' or 'interface' expected
    }
    ^
    C:\Documents and Settings\stevew\My Documents\Java test\Inventory2.java:377: 'class' or 'interface' expected
    ^
    3 errors
    
    Tool completed with exit code 1
    What did I miss?

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #47
      Originally posted by stevedub
      Well, I get this error when compiled:
      Code:
      C:\Documents and Settings\stevew\My Documents\Java test\Inventory2.java:217: 'class' or 'interface' expected
      else if(command.equals("Add Item")) {
      ^
      C:\Documents and Settings\stevew\My Documents\Java test\Inventory2.java:220: 'class' or 'interface' expected
      }
      ^
      C:\Documents and Settings\stevew\My Documents\Java test\Inventory2.java:377: 'class' or 'interface' expected
      ^
      3 errors
       
      Tool completed with exit code 1
      What did I miss?
      Could be something to do with your braces. Here is the complete actionPerformed method

      Code:
       
      public void actionPerformed(ActionEvent event) {
        String command = event.getActionCommand(); //This retrieves the command that we set for the button
        //Always compare strings using the .equals method and not using ==
        if(command.equals("First")) {
         if(!locked) {
      	displayFirst();
         }
        }
        else if(command.equals("Next")) {
         if(!locked) {
      	displayNext();
         }
        }
        else if(command.equals("Previous")) {
         if(!locked) {
      	displayPrevious();
         }
        }
        else if(command.equals("Last")) {
         if(!locked) {
      	displayLast();
         }
        }
        else if(command.equals("Exit")) {
         this.dispose();
         System.exit(0);
        }
        else if(command.equals("Add")) {
         if(!locked) {
      	addItem();
      	locked = true;
         }
        }
        else if(command.equals("Add Item")) {
         addItemToArray();
        }
        else if(command.equals("Modify")) {
         if(!locked) {
      	modify();
      	locked = true;
         }
        }
        else if(command.equals("Update")) {
      	 if(!locked) {
      	modifyItemInArray();
      	locked = true;
         }
        }
        else if(command.equals("Delete")) {
         if(!locked) {
      	DVD dvd = (DVD)supplies[currentIndex];
      	   int confirm = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete item "+dvd.getItemNumber());
      		  if(confirm == JOptionPane.YES_OPTION) {
      	 removeItemAt(currentIndex);
      	 displayFirst();
      	  }
         }
        } 
       }

      Comment

      • stevedub
        New Member
        • Jan 2007
        • 40

        #48
        Ok, it works now. I always screw stuff up with the copy and paste, hehe. I think all I need now is to have the modify button to work. Oh, I also have to code in to show the items inventory value + restock fee, and total value, I should be able to figure that one out.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #49
          Originally posted by stevedub
          Ok, it works now. I always screw stuff up with the copy and paste, hehe. I think all I need now is to have the modify button to work. Oh, I also have to code in to show the items inventory value + restock fee, and total value, I should be able to figure that one out.
          The modify and delete buttons are already working! Only the save and search are not yet done.

          Comment

          • stevedub
            New Member
            • Jan 2007
            • 40

            #50
            Opps, thats what I meant, modify and delete are good to go. I'm telling ya, its been quite the month hehe.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #51
              Originally posted by stevedub
              Opps, thats what I meant, modify and delete are good to go. I'm telling ya, its been quite the month hehe.
              Don't forget to let me know if there is anything you don't understand in that code. I would also want you to try to make the search function work.

              Comment

              • stevedub
                New Member
                • Jan 2007
                • 40

                #52
                I have a question on how the 'lock' method works in the action panel. This part is a little confusing. I will also try to give the search function a try, that seems to be a little complicated

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #53
                  Originally posted by stevedub
                  I have a question on how the 'lock' method works in the action panel. This part is a little confusing. I will also try to give the search function a try, that seems to be a little complicated
                  The idea is stop the user from trying to add while in the middle of another add or a modify which would really mess up the screen

                  Comment

                  • stevedub
                    New Member
                    • Jan 2007
                    • 40

                    #54
                    Ah that makes sense now. I guess I've never seen the 'lock' actually used before.

                    Comment

                    • stevedub
                      New Member
                      • Jan 2007
                      • 40

                      #55
                      Hey r035198x, just wanted to give you an update. My girlfriend and I had a baby girl on the 14th (Valentines day!). We just got home today, and everything is going great. I haven't had any time to work on my program, and things are going to be a little hectic for a while. I was wondering if you could help me out with the last couple of steps on my program, which is due Sunday. You have been such a great help throughout my course and I really thank you for taking the time to do so. Thanks again, hope to hear from you soon.

                      Comment

                      • stevedub
                        New Member
                        • Jan 2007
                        • 40

                        #56
                        Is this something how it should look?
                        Code:
                        private DVD searchName(String searchName) {
                        for (DVD dvd : dvdList) {
                            if (dvd.getName().equals(searchName)) {
                                return dvd;
                            }
                        }
                        return null;
                        }

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #57
                          Originally posted by stevedub
                          Hey r035198x, just wanted to give you an update. My girlfriend and I had a baby girl on the 14th (Valentines day!). We just got home today, and everything is going great. I haven't had any time to work on my program, and things are going to be a little hectic for a while. I was wondering if you could help me out with the last couple of steps on my program, which is due Sunday. You have been such a great help throughout my course and I really thank you for taking the time to do so. Thanks again, hope to hear from you soon.
                          I hope you didn't call her Valentine!
                          For the search, the object of the search is to display the DVD that we have searched for. We already have a mthod that displays an item in the array if we know it's position in the array. So all we need to do is to find the position of that DVD in the array. Our search method should therefore return just an int.
                          Code:
                           
                          private int findPositionOfProduct(String productName) {//We need the index so the short for won't work
                          	 int pos = -1;
                          	 for(int i = 0; i < supplies.length; i++) {
                             DVD dvd = (DVD)supplies[i];
                             if(dvd.getItemName().equalsIgnoreCase(productName)) { //Make the search case insensitive
                          	return i;
                             }
                            }
                            return pos;// -1 is returned if we did not find the product.
                           }

                          Now to make it work we need to add the part that handles the command from the clicking of the search button. We want to tell the user that the product is not there if we did not find it.

                          Code:
                           
                          else if(command.equals("Search")) {
                          	 if(!locked) {
                          	  String product = JOptionPane.showInputDialog(this, "Enter the product's name");
                          	  int pos = findPositionOfProduct(product);
                          	  if(pos == -1) {
                          	 JOptionPane.showMessageDialog(this, "There is no product named "+ product + " in the inventory");
                          	}
                          	else {
                          	 displayItemAt(pos);
                          	}
                          	 }
                            }
                          And that's it! The search is complete.

                          Comment

                          • carylrahn
                            New Member
                            • Feb 2007
                            • 4

                            #58
                            Originally posted by r035198x
                            I hope you didn't call her Valentine!
                            For the search, the object of the search is to display the DVD that we have searched for. We already have a mthod that displays an item in the array if we know it's position in the array. So all we need to do is to find the position of that DVD in the array. Our search method should therefore return just an int.
                            Code:
                             
                            private int findPositionOfProduct(String productName) {//We need the index so the short for won't work
                            	 int pos = -1;
                            	 for(int i = 0; i < supplies.length; i++) {
                               DVD dvd = (DVD)supplies[i];
                               if(dvd.getItemName().equalsIgnoreCase(productName)) { //Make the search case insensitive
                            	return i;
                               }
                              }
                              return pos;// -1 is returned if we did not find the product.
                             }

                            Now to make it work we need to add the part that handles the command from the clicking of the search button. We want to tell the user that the product is not there if we did not find it.

                            Code:
                             
                            else if(command.equals("Search")) {
                            	 if(!locked) {
                            	  String product = JOptionPane.showInputDialog(this, "Enter the product's name");
                            	  int pos = findPositionOfProduct(product);
                            	  if(pos == -1) {
                            	 JOptionPane.showMessageDialog(this, "There is no product named "+ product + " in the inventory");
                            	}
                            	else {
                            	 displayItemAt(pos);
                            	}
                            	 }
                              }
                            And that's it! The search is complete.
                            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.

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #59
                              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.
                              I make it a point to reply code with code. The OP posted some code for the method which was not correct so I posted the corrected code for that and an explanation. Sometimes it is easier to explain using code. But I will take your point and remember not to post code in assignment questions

                              Comment

                              • carylrahn
                                New Member
                                • Feb 2007
                                • 4

                                #60
                                Originally posted by r035198x
                                I make it a point to reply code with code. The OP posted some code for the method which was not correct so I posted the corrected code for that and an explanation. Sometimes it is easier to explain using code. But I will take your point and remember not to post code in assignment questions

                                Thank you, that will be appreciated. It really hurts the students when they do not write the code themselves.

                                Comment

                                Working...