Results 1 to 2 of 2

Thread: Product Problem

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Posts
    159

    Question Product Problem

    I am trying to write a program to input details of several products and quantities and display
    them.

    After all the product data has been entered (terminated by 0), print the summary totals.:

    The inputs will be inputed like so:


    Kellogs
    Cornflakes 750g
    5000127062092
    123
    10


    and should be outputed like so:


    Kellogs:Cornflakes 750g:5000127062092:123:10:1230
    Transactions 1
    Total quantity 10
    Total value 1230
    Average cost 123


    if a number of product details where entered the following would be added together:

    The transactions is the number of times it has been around the loop

    Total quantity is the quantity added together

    Total value is the Total value added together

    Average cost is the Average cost added together and devided by 3

    e.g.

    Input


    Kellogs:Cornflakes 750g :5000127062092:123:10:1230
    Kellogs:Rice Krispies 600g:5000127053090:123:16:1968
    Quaker:Puffed Wheat 160g :1000108001010:78:11:858


    Output


    Transactions 3
    Total quantity 37
    Total value 4056
    Average cost 109


    But im havig trouble doing the above. I think i gotta use a loop or somthing.

    Here is the code i have so far:

    Code:
    public class ProcessProduct{
    
    public static void main(String[] argv) {
    
              int barcodeLength, quantity, price, totalPrice, transaction = 0;
             String barcode, manufaturer = "", productName;
       
             while(manufaturer != "0"){
          
                    System.out.println ("Please enter manufaturer name");
                    manufaturer = UserInput.readString();
       
                    if(manufaturer.equals ("0")){
                        break; 
                    }
       
                    System.out.println ("Please enter product name");
                    productName = UserInput.readString();
       
                    System.out.println ("Please enter barcode");
                    barcode = UserInput.readString();
        
                    barcodeLength = barcode.length();
        
                    if (barcodeLength < 13){
                        System.out.println ("Error, invalid entry, barcode length is less than 13 characters");
                        System.exit (0);
                    }
        
                    if (barcodeLength > 13){
                        System.out.println("Error, invalid entry, barcode length is greater than 13 characters");
                        System.exit(0);
                    }
              
         
                    System.out.println ("Please enter price");
                    price = UserInput.readInt();
       
                    if (price <= 0 ){
                        System.out.println ("Error,invalid entry");
                        System.exit (0);
                    }    
       
                    System.out.println ("Please enter quantity");
                    quantity = UserInput.readInt();
       
                    if (quantity <= 0 ){
                        System.out.println ("Error,invalid entry");
                        System.exit (0);
                    }
                    
                    ++ transaction ;
                    
                    totalPrice = price * quantity;
                    System.out.println (manufaturer +":"+ productName +":"+ barcode +":"+ price +":"+ totalPrice);
            }   
            
                            
            System.out.println ("Transaction " +transaction);
            System.out.println ("Total quantity ");
            System.out.println ("Total value ");
            System.out.println ("Average cost ");
    i can manage to get the following Input and corresponding Output


    Input

    Kellogs:Cornflakes 750g :5000127062092:123:10:1230
    Kellogs:Rice Krispies 600g:5000127053090:123:16:1968
    Quaker:Puffed Wheat 160g :1000108001010:78:11:858





    Output

    Transactions 3
    Total quantity
    Total value
    Average cost


    How would i get the

    Total quantity
    Total value
    Average cost
    Last edited by NOTSOSURE; Jan 20th, 2003 at 12:39 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
  •  



Click Here to Expand Forum to Full Width