Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: inventory System

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Talking inventory System

    You are to simulate an inventory system. A class product holds id, name, price and quantity as its belonging. ID is a fix value by default, say 0, and should increase by one every time there’s a new product been instantiated. Write a proper object class with its constructors, accessors and mutators.

    The following methods are needed:
    1. addStock method:
     This method is to add up the stock in hand. This method should receive an argument of the amount needed to add. Do a checking on the amount given. Perform the update on the current stock only if the amount is greater than zero. Return true if adding the stock is successful or false otherwise.
    2. deleteStock method:
     This method is to deduct the stock in hand. This method should receive an argument of the amount needed to deduct. Do a checking on the amount given. Deduct from current stock only if the amount is less than the stock, and the stock after deduction should not be less than 15. Return true if purchase is successful or false otherwise.
    In your main application, named <your_id>, create an array that holds the products data. Also, include a menu-page of your program should contain these options:
    1 – Enter new product
    2 – Display all products
    3 – Update product
    0 – Exit
    To make the whole program complete, include the proper exceptions, decimal places to wherever appropriate. Add your own creativity to the system but do not change the basic requirements.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    Do you have any specific questions about your assignment?
    Please post your code and any questions about problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    this all i got for the Q

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    You'll need to read it and do some work now.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    yes sir!!
    for now still no idea
    im doing it

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    For how to write a java program see the tutorials:
    The Really Big Index
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    can u help me to perfect this code, there is some problem after i key in the product then i want to display it the system stop..
    can u help me to change the code without JOP(JOpntionPane)
    Attached Files Attached Files

  8. The Following User Says Thank You to w4nz For This Useful Post:


  9. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    tomorrow i need to submit it... XD
    i tried to do the code keep looping before exit but i failed

  10. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    Please post the code you have questions about here on the forum. No links.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #10
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    import java.util.Random;
    import static javax.swing.JOptionPane.*;
    public class I11007783
    {
        public static void main(String arg[]){
            Inventory n[]=new Inventory[3];//create an object
            String name="";
            int Product_Price=50;
            int quantity=6;
            int id=8; 
            boolean status;
            int Option;
     
            Option=Integer.parseInt(showInputDialog("Press\n1 - Enter new product\n2 - Display all products\n3 - Update And Delete product\n4 - Exit"));
            switch(Option)
            {
                case 1: EnterNewProduct(n);
                break;
                case 2: DisplayAllProducts(n);
                break;
                case 3: UpdateAndDelProducts(n);
                break;
                case 4: System.exit(4);
                default : showMessageDialog(null,"Error");
            }
        }
     
        public static void EnterNewProduct(Inventory n[]){
            String name="";
            int Product_Price=50;
            int quantity=6;
            int id=8;
            boolean status;
     
            for(int i=0; i<n.length; i++){
                do{
                    try{
                        status=false;
                        name=showInputDialog("Please Enter name for product" + " " +( i) +":");
                        if(name.length()==0){
                            throw new Exception("Invalid");
                        }
                        if(!name.matches("[A-Za-z ]+")){
                            throw new Exception("Invalid");
                        }
                    }catch(Exception e){
                        showMessageDialog(null, e.getMessage());
                        status=true;
                    }
                }while(status==true);
                do{
                    try{
                        status=false;
                        quantity=Integer.parseInt(showInputDialog("Please Enter quantity for product" +" " +(i)+ ":"));
                        if(quantity<0){
                            throw new Exception("Invalid");
                        }
                    }catch(NumberFormatException nfe){
                        System.out.println(nfe.getMessage());
                        status=true;
                    }catch(Exception e){
                        showMessageDialog(null, e.getMessage());
                        status=true;
                    }
                }while(status==true);
     
                do{
                    try{
                        status=false;
                        Product_Price=Integer.parseInt(showInputDialog("Please Enter Product_Price for product :" +" " +(i)+ ": "));
                        if(Product_Price<0){
                            throw new Exception("Invalid");
                        }
                    }catch(NumberFormatException nfe){
                        System.out.println(nfe.getMessage());
                        status=true;
                    }catch(Exception e){
                        showMessageDialog(null, e.getMessage());
                        status=true;
                    }
                }while(status==true);
                n[i]=new Inventory(name, i, Product_Price,quantity);
            }
            int Option;
     
            Option=Integer.parseInt(showInputDialog("Press\n1 - Enter New Product\n2 - Display All Products\n3 - Update and Delete product\n4 - Exit"));
            switch(Option){
                case 1: EnterNewProduct(n);break;
                case 2: DisplayAllProducts(n);break;
                case 3: UpdateAndDelProducts(n);break;
                case 4: System.exit(4);
                default : showMessageDialog(null,"Error");
            }
        }
     
        public static void DisplayAllProducts(Inventory n[]){
            for(int i=0; i<n.length; i++){
                System.out.println(" \n Product's Name:" + n[i].getName() + "\nProduct's id:" + n[i].getId() +"\nProduct's Price:" +n[i].getPrice() +"\nQuantity:"+ n[i].getQuantity());
                System.out.println("--------------------------------------------------------------------");
            }
        }
     
        public static void UpdateAndDelProducts(Inventory n[]){
            {
                int x = Integer.parseInt(showInputDialog("Enter 1. to Add New Stock \nEnter 2. to Delete Stock"));
                if(x == 1)
                {
                    addStock(n);
                }
                else if(x == 2)
                {
                    deleteStock(n);
                }
            }
            int Option;//initialize Option
            //ask
            Option=Integer.parseInt(showInputDialog("Press\n1 - Enter New Product\n2 - Display All Products\n3 - Update and Delete product\n4 - Exit"));
            switch(Option){
                case 1: EnterNewProduct(n);break;
                case 2: DisplayAllProducts(n);break;
                case 3: UpdateAndDelProducts(n);break;
                case 4: System.exit(4);
                default : showMessageDialog(null,"Error");
            }
        }
     
        public static boolean addStock(Inventory n[]){ 
            int x=Integer.parseInt(showInputDialog("Enter the ID of the product:"));
            int a=Integer.parseInt(showInputDialog("Enter the amount that you want to add:"));
     
            boolean status=false;
            for(int i=0; i<n.length; i++){
                if(x==n[i].getId()){
                    if(a>0){
                        int quantity = n[i].getQuantity() + a;
                        n[i].setQuantity(quantity);
                        status= true;
                    }
                    else status=false;
                }
            }
            return status;
        }
     
        public static boolean deleteStock(Inventory n[])
        {
            int x=Integer.parseInt(showInputDialog("Please Enter the Item_ID of the product:"));
            int d=Integer.parseInt(showInputDialog("Please Enter the amount that you want to delete:"));
            boolean status=true;
            for(int i=0;i<n.length;i++){
                if(x==n[i].getId()){
                    if(n[i].getQuantity() - d < 15)
                    {
                        status=false;
                    }
                    else{
                        int quantity = n[i].getQuantity() - d;
                        n[i].setQuantity(quantity);
                        status=true;
                    }
                }
            }
            return status;
        }
    }
    Last edited by Norm; March 17th, 2013 at 06:41 AM. Reason: added code tags

  12. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    there is some problem
    Can you post the program's output that shows the problem.

    What is the input to the program? How can the code be tested? Can you post the all the input the user must make to test the code?

    The posted code does not compile because of missing class.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #12
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System


  14. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    0 is the id of the product..

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    The posted code needs the Inventory class's definition to compile and test.

    Please post a list of all the inputs that the user must make to test the code. Images are no good because you can not copy text from an image.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #15
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    public class Inventory
    {


    private String name;
    private int Inventory_id;
    private int Item_price;
    private int quantity;


    public Inventory(){
    name="default"; Inventory_id=1; Item_price=50;
    quantity=1;
    }

    public Inventory( String n, int Inventory_id, int p,int q){

    setName(n); setId(Inventory_id); setPrice(p);
    setQuantity(q);
    }


    public void setId( int i){
    Inventory_id=i;
    }
    public void setPrice( int p){
    Item_price=p;
    }
    public void setName(String n){

    name=n;
    }
    public void setQuantity( int q){
    quantity=q;
    }

    public String getName(){
    return name;
    }

    public int getQuantity(){
    return quantity;
    }

    public int getPrice(){
    return Item_price;
    }

    public int getId(){
    return Inventory_id;
    }



    }

    --- Update ---

    code above for inventory which is print screen to images

  17. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    Please post a list of all the inputs that the user must make to test the code. Images are no good because you can not copy text from an image.
    I don't test by answering prompts. I put all the responses in a String array and feed the JOPtionPane methods from the array.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #17
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    u mean the Q?
    there is no question from the lecturer to test the program for the output only the Q below that she give it to me

    You are to simulate an inventory system. A class product holds id, name, price and quantity as its belonging. ID is a fix value by default, say 0, and should increase by one every time there’s a new product been instantiated. Write a proper object class with its constructors, accessors and mutators.

    The following methods are needed:
    1. addStock method:
     This method is to add up the stock in hand. This method should receive an argument of the amount needed to add. Do a checking on the amount given. Perform the update on the current stock only if the amount is greater than zero. Return true if adding the stock is successful or false otherwise.
    2. deleteStock method:
     This method is to deduct the stock in hand. This method should receive an argument of the amount needed to deduct. Do a checking on the amount given. Deduct from current stock only if the amount is less than the stock, and the stock after deduction should not be less than 15. Return true if purchase is successful or false otherwise.
    In your main application, named <your_id>, create an array that holds the products data. Also, include a menu-page of your program should contain these options:
    1 – Enter new product
    2 – Display all products
    3 – Update product
    0 – Exit
    To make the whole program complete, include the proper exceptions, decimal places to wherever appropriate. Add your own creativity to the system but do not change the basic requirements.

  19. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    I need a list of the responses that the user makes to the questions asked by the dialog boxes.
    What is typed into each box? For example what is the answer for this prompt:
    Press
    1 - Enter new product
    2 - Display all products
    3 - Update And Delete product
    4 - Exit
    And for all the following prompts.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #19
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    1 - enter new product
    please Enter name for product 0: A
    Enter quantity for product 0 : 2
    Please enter price for product : 25

    please Enter name for product 0: A
    Enter quantity for product 0 : 2
    Please enter price for product : 25

    please Enter name for product 1: B
    Enter quantity for product 1 : 3
    Please enter price for product : 20

    please Enter name for product 2: C
    Enter quantity for product 2 : 4
    Please enter price for product : 10
    2 - Display all the product (clicked it)

    Product's Name:A
    Product's id:0
    Product's Price:25
    Quantity:2

    --------------------------------------------------------------------

    Product's Name:B
    Product's id:1
    Product's Price:20
    Quantity:3
    --------------------------------------------------------------------

    Product's Name:C
    Product's id:2
    Product's Price:10
    Quantity:4
    --------------------------------------------------------------------

    3 - update and delete product
    Enter 1. to Add Stock
    - Enter the ID of the product : 0
    - Enter the amount that you want to add : 3
    Enter 2. to Delete Stock
    - Enter the ID of the product : 1
    - Enter the amount that you want to delete : 1

    after display : delete stock have problem (after delete still the exact amount)

    Product's Name:A
    Product's id:0
    Product's Price:25
    Quantity:5
    --------------------------------------------------------------------

    Product's Name:B
    Product's id:1
    Product's Price:20
    Quantity:3
    --------------------------------------------------------------------

    Product's Name:C
    Product's id:2
    Product's Price:10
    Quantity:4
    --------------------------------------------------------------------

    --- Update ---

    after i display it i cant run the program
    so i need to re-run and re-enter all the command in (1- enter new product) then i can add n delete my stock

  21. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    I need only the answers to the questions. I am going to copy the answers into a String that will give the answers to the program's questions. It looks like you have posted the question AND the answers. I need JUST the answers so I can copy them and pasted them into a String.
    If you don't understand my answer, don't ignore it, ask a question.

  22. The Following User Says Thank You to Norm For This Useful Post:

    w4nz (March 17th, 2013)

  23. #21
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    1 - enter new product
    please Enter name for product 1: A
    Enter quantity for product 1: 2
    Please enter price for product : 25

    please Enter name for product 2: B
    Enter quantity for product 2 : 3
    Please enter price for product : 20

    please Enter name for product 3: C
    Enter quantity for product 3 : 4
    Please enter price for product : 10

    3 - update and delete product
    Enter 1. to Add Stock
    - Enter the ID of the product : 1
    - Enter the amount that you want to add : 3
    Enter 2. to Delete Stock
    - Enter the ID of the product : 2
    - Enter the amount that you want to delete : 1
    2 - Display all the product:
    Product's Name:A
    Product's id:1
    Product's Price:25
    Quantity:5
    --------------------------------------------------------------------

    Product's Name:B
    Product's id:2
    Product's Price:20
    Quantity:2
    --------------------------------------------------------------------

    Product's Name:C
    Product's id:2
    Product's Price:10
    Quantity:4
    --------------------------------------------------------------------

  24. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    Are you saying that the answer to the first question is: "1 - enter new product"
    and the answer to the second question is: "please Enter name for product 1: A"
    etc?

    Those are very weird looking answers.

    When I use those answers I get:
    Exception in thread "main" java.lang.NumberFormatException: For input string: "1 - enter new product"
    If you don't understand my answer, don't ignore it, ask a question.

  25. #23
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    1 - enter new product
    please Enter name for product 1: A
    Enter quantity for product 1: 2
    Please enter price for product : 25

    please Enter name for product 2: B
    Enter quantity for product 2 : 3
    Please enter price for product : 20

    please Enter name for product 3: C
    Enter quantity for product 3 : 4
    Please enter price for product : 10

    3 - update and delete product
    Enter 1. to Add Stock
    - Enter the ID of the product : 1
    - Enter the amount that you want to add : 3
    Enter 2. to Delete Stock
    - Enter the ID of the product : 2
    - Enter the amount that you want to delete : 1
    2 - Display all the product:
    Product's Name:A
    Product's id:1
    Product's Price:25
    Quantity:5
    --------------------------------------------------------------------

    Product's Name:B
    Product's id:2
    Product's Price:20
    Quantity:2
    --------------------------------------------------------------------

    Product's Name:C
    Product's id:2
    Product's Price:10
    Quantity:4
    --------------------------------------------------------------------

    --- Update ---

    yes sir, that the ans for my code, can u solve it? after display that the result
    the Q tell us to us exception

  26. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: inventory System

    Sorry, I can't use what you have posted. I need the answers only, not the questions.
    This is what I need. Just the answers:
    1
    A
    2
    etc
    If you don't understand my answer, don't ignore it, ask a question.

  27. The Following User Says Thank You to Norm For This Useful Post:

    w4nz (March 17th, 2013)

  28. #25
    Junior Member
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: inventory System

    A
    1
    25
    3
    B
    2
    35
    3
    C
    3
    40
    5

Page 1 of 2 12 LastLast

Similar Threads

  1. Inventory Management System
    By Luffy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 26th, 2013, 03:11 AM
  2. Inventory Management System
    By Luffy in forum Java Theory & Questions
    Replies: 0
    Last Post: February 26th, 2013, 01:50 AM
  3. Please help, my inventory code is not working
    By ggarrett in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 17th, 2013, 06:39 AM
  4. Help with inventory program
    By curmudgeon in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 13th, 2013, 10:53 PM
  5. Simple inventory System. Sometimes it doesn't update my added book.
    By JustinK in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 1st, 2011, 10:50 AM