Results 1 to 8 of 8
  1. #1
    JR2010 is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default Need Help please don't know where to start.

    :confused:I need help with my program for my intro to Java class. I have the first part of the assignment running perfectly, now I have to Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.

    I have read my book, but it makes no sence to me. Can someone please help me figure this out?

    My code is below.

    Java Code:
    package product;
    
    
    import java.util.Scanner;// program uses class Scanner
    
    
    
    public class product {
    
              // main method begins execution of Java application
    
    
      public static void main(String[] args) {
           // Multiplication program to calculate payroll
    
          // create Scanner to obtain input from command window
    
          Scanner input = new Scanner(System.in);
    
    
           boolean enterMoreData = true;
           String proName;
      while(enterMoreData){
    
    
         //get product name or stop program
    
                
          System.out.print("Enter product name or stop to quit: " );
          proName = input.nextLine();
                   
                    
       if (proName.equalsIgnoreCase("stop")) {
           System.out.println(" Good bye! Thank You for using inventory organizer.");
           System.exit(0);}
                        
    
    
       // get product number
       int proNumber;
    
       do
           {
                         
           System.out.println(" Please enter the product identification number for inventory: ");
           proNumber = input.nextInt();
       if (proNumber < 0) {
             System.out.println("number must be positive, please try again. ");
             }
             }
       while (proNumber < 0);
    
       int proQuant;
       // get product quantity in inventory
       do
          {
          System.out.println(" Please enter the quantity of product in inventory: ");
          proQuant = input.nextInt();
       if (proQuant < 0) {
              System.out.println("number must be positive, please try again. ");
              }
    
              }
                        
       while ( proQuant < 0);
    
       double proPrice;
       // get product
       do
            {
            System.out.println("Please enter product price: ");
            proPrice = input.nextDouble();
       if   (proPrice < 0) {
            System.out.println("number must be positive, please try again.");
            }
    
            }
    
       while ( proPrice < 0);
                     
           Item item = new Item (proName, proNumber, proQuant, proPrice);
    
           System.out.printf("Product name is: %s\n Product number is : %.2f\n "
           + "Product quantity in stock is: %.2f\n Product price is: %.2f\n Total of products"
           + " in inventory is: $ %.2f\n ",
           item.proName, item.proNumber, item.proQuantity, item.proPrice, item.getproTotal());
                  
           proName = input.nextLine();
    
    
               }// end while
            } //end method main
    
    } //end class product
    
    class Item //creat new class Product
    {
        //input variables
    
        String proName;
        double proNumber;
        double proQuantity;
        double proPrice;
        double proTotal;
    
        // Get input
    
       public Item(String name, double number, double quant, double price)
        {
            this.proName = name;
            this.proNumber = number;
            this.proQuantity = quant;
            this.proPrice = price;
            computeproTotal();
        }
        // method to compute proTotal
        private void computeproTotal()
        {
            proTotal = proQuantity * proPrice;
        }
        // method to get Total
        public double getproTotal()
        {
            return proTotal;
    
        }
        
      
            
    }// end class Product

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Are you asking how to use Arrays?

  4. #4
    JR2010 is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default

    Dark, Yes I am asking how to use arrays and implement them into my program.

    Kevin Workman, thank you for the links I will check them out right now.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Doesn't Inventory season fall in September?

  6. #6
    JR2010 is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default

    For some reason, the String variables are not being recognized. Could someone give me a hint as to why? My code is below that I have so far.

    Java Code:
    package inventory;
    // This program displays inventory
    /**
     *
     * @author Julie
     */
    public class inventory {
    
      
        public static void main(String[] args) {
            // TODO code application logic here
        
     
         {
       String[] ProductName = new String[5];
       ProductName[0] = CD;
       ProductName[1] = Shirt;
       ProductName[2] = Pants;        
       ProductName[3] = Hat;
       ProductName[4] = Shoes;
         }
       
      { int[] ProductNumber  = new int [5];
       ProductNumber[0] = 2525;
       ProductNumber[1] = 2526;
       ProductNumber[2] = 2527;
       ProductNumber[3] = 2528;
       ProductNumber[4] = 2529;}
    
      { int ProductQuantity [] = new int [5];
       ProductQuantity[0] = 4;
       ProductQuantity[1] = 6;
       ProductQuantity[2] = 15;      
       ProductQuantity[3] = 4;       
       ProductQuantity[4] = 3;      
        }
               
        {
       double ProductPrice[] = new double[5];
       ProductPrice[0] = 14.99;
       ProductPrice[1] = 12.58;
       ProductPrice[2] = 22.58;
       ProductPrice[3] = 10.72;
       ProductPrice[4] = 52.58;
        }
        
        }// end main
    }//end class inventory

  7. #7
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default

    Strings should be in quotations.

    String s = "Welcome to Java!";

  8. #8
    JR2010 is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Where to start - GUI
    By matejm1994 in forum New To Java
    Replies: 2
    Last Post: 01-30-2011, 05:02 PM
  2. Replies: 1
    Last Post: 01-18-2011, 06:27 PM
  3. Replies: 5
    Last Post: 03-20-2009, 10:04 PM
  4. Where to start?
    By McChill in forum New To Java
    Replies: 5
    Last Post: 02-19-2009, 02:26 PM
  5. Web Start
    By DannyZB in forum NetBeans
    Replies: 0
    Last Post: 11-14-2008, 12:58 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
  •