Program help...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zaidalin79
    New Member
    • Nov 2006
    • 59

    #1

    Program help...

    Here is my Inventory program for my Java class....

    Code:
    //Inventory.java
    //Class created to store item information for Inventory purposes
    //Created November 15, 2006
    //Modified November 29, 2006
    //Audrey A. Paige
    //IT315
    
    class Product
    {
       private String name; 	// class variable that stores the item name
       private double number;	  // class variable that stores the item number
       private long stockQuantity;   // class variable that stores the quantity in stock
       private double price;	  // class variable that stores the item price
       public Product() // Constructor for the Supplies class
       {
    	  name = "";
    	  number = 0.0;
    	  stockQuantity = 0L;
    	  price = 0.0;
       }
       public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
    	  {
    		 this.name = name;
    		 this.number = number;
    		 this.stockQuantity = stockQuantity;
    		 this.price = price;
       }
       public void setItemName(String name)  // Method to set the item name
       {
    	  this.name = name;
       }
       public String getItemName()  // Method to get the item name
       {
    	  return name;
       }
       public void setItemNumber(double number)  // Method to set the item number
       {
    	  this.number = number;
       }
       public double getItemNumber()  // Method to get the item number
       {
    	  return number;
       }
       public void setStockQuantity(long quantity)  // Method to set the quantity in stock
       {
    	  stockQuantity = quantity;
       }
       public long getStockQuantity()  // Method to get the quantity in stock
       {
    	  return stockQuantity;
       }
       public void setItemPrice(double price)  // Method to set the item price
       {
    	  this.price = price;
       }
       public double getItemPrice()  // Method to get the item price
       {
    	  return price;
       }
       public double calculateInventoryValue()  // Method to calculate the value of the inventory
       {
    	  return price * stockQuantity;
       }
    }//end class Product
    
    public class Inventory
    {
       // main methods begins execution of java application
       public static void main( String args[])
       {
        Product p = new Product("Pencil", 5460, 125, 1.5);
    	System.out.printf("\n\nItem Name:%s\n",p.getItemName()); //display item name
    	System.out.printf("Item Number:%s\n",p.getItemNumber()); //display item number
    	System.out.printf("Quantity in Stock:%s\n",p.getStockQuantity()); //display quantity in stock
    	System.out.printf("Item Price:$%.2f\n",p.getItemPrice()); //display item price
    	System.out.printf("Value of Inventory:$%.2f\n",p.calculateInventoryValue()); //display total value of inventory for this item
    
    
       } // end main method
    }//end class Inventory
    I need to add these changes...

    1. CheckPoint: Inventory Program Part 2
    • Resource: Java: How to Program
    • Due Date: Day 4 [Individual] forum
    • 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.
    • Create a method to calculate the value of the entire inventory.
    • Create another method to sort the array items by the name of the product.

    If anyone can help it would be greatly appreciated... I am getting desperate-my class ends next week, and I still have to figure out three more modifications of this program...

    Thanks!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by zaidalin79
    Here is my Inventory program for my Java class....

    Code:
    //Inventory.java
    //Class created to store item information for Inventory purposes
    //Created November 15, 2006
    //Modified November 29, 2006
    //Audrey A. Paige
    //IT315
     
    class Product
    {
    private String name; 	// class variable that stores the item name
    private double number;	 // class variable that stores the item number
    private long stockQuantity; // class variable that stores the quantity in stock
    private double price;	 // class variable that stores the item price
    public Product() // Constructor for the Supplies class
    {
    	 name = "";
    	 number = 0.0;
    	 stockQuantity = 0L;
    	 price = 0.0;
    }
    public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
    	 {
    		 this.name = name;
    		 this.number = number;
    		 this.stockQuantity = stockQuantity;
    		 this.price = price;
    }
    public void setItemName(String name) // Method to set the item name
    {
    	 this.name = name;
    }
    public String getItemName() // Method to get the item name
    {
    	 return name;
    }
    public void setItemNumber(double number) // Method to set the item number
    {
    	 this.number = number;
    }
    public double getItemNumber() // Method to get the item number
    {
    	 return number;
    }
    public void setStockQuantity(long quantity) // Method to set the quantity in stock
    {
    	 stockQuantity = quantity;
    }
    public long getStockQuantity() // Method to get the quantity in stock
    {
    	 return stockQuantity;
    }
    public void setItemPrice(double price) // Method to set the item price
    {
    	 this.price = price;
    }
    public double getItemPrice() // Method to get the item price
    {
    	 return price;
    }
    public double calculateInventoryValue() // Method to calculate the value of the inventory
    {
    	 return price * stockQuantity;
    }
    }//end class Product
     
    public class Inventory
    {
    // main methods begins execution of java application
    public static void main( String args[])
    {
    Product p = new Product("Pencil", 5460, 125, 1.5);
    	System.out.printf("\n\nItem Name:%s\n",p.getItemName()); //display item name
    	System.out.printf("Item Number:%s\n",p.getItemNumber()); //display item number
    	System.out.printf("Quantity in Stock:%s\n",p.getStockQuantity()); //display quantity in stock
    	System.out.printf("Item Price:$%.2f\n",p.getItemPrice()); //display item price
    	System.out.printf("Value of Inventory:$%.2f\n",p.calculateInventoryValue()); //display total value of inventory for this item
     
     
    } // end main method
    }//end class Inventory
    I need to add these changes...

    1. CheckPoint: Inventory Program Part 2
    • Resource: Java: How to Program
    • Due Date: Day 4 [Individual] forum
    • 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.
    • Create a method to calculate the value of the entire inventory.
    • Create another method to sort the array items by the name of the product.

    If anyone can help it would be greatly appreciated... I am getting desperate-my class ends next week, and I still have to figure out three more modifications of this program...

    Thanks!
    Keep one question in one thread please. What happened to the last stage we reached in this thread

    Comment

    • zaidalin79
      New Member
      • Nov 2006
      • 59

      #3
      Sorry, I am new to the forum. My teacher liked the first one, but the second one she said the for loops were wrong, the addProduct part was unnecessary, and that I should create the array and add the items in the main method. She also said she doesn't care how I do the sort-I can use bubble or the utility.

      I am just basically at the end of my rope with her. She said I will not get any credit for the first three checkpoints, so I basically have to find a way to get from one to five in the next week,

      I really appreciate you help and am hoping you can help me more. My teacher is proving to be very little help at all...

      Comment

      Working...