By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

Program help...

P: 59
Here is my Inventory program for my Java class....

Expand|Select|Wrap|Line Numbers
  1. //Inventory.java
  2. //Class created to store item information for Inventory purposes
  3. //Created November 15, 2006
  4. //Modified November 29, 2006
  5. //Audrey A. Paige
  6. //IT315
  7.  
  8. class Product
  9. {
  10.    private String name;     // class variable that stores the item name
  11.    private double number;      // class variable that stores the item number
  12.    private long stockQuantity;   // class variable that stores the quantity in stock
  13.    private double price;      // class variable that stores the item price
  14.    public Product() // Constructor for the Supplies class
  15.    {
  16.       name = "";
  17.       number = 0.0;
  18.       stockQuantity = 0L;
  19.       price = 0.0;
  20.    }
  21.    public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
  22.       {
  23.          this.name = name;
  24.          this.number = number;
  25.          this.stockQuantity = stockQuantity;
  26.          this.price = price;
  27.    }
  28.    public void setItemName(String name)  // Method to set the item name
  29.    {
  30.       this.name = name;
  31.    }
  32.    public String getItemName()  // Method to get the item name
  33.    {
  34.       return name;
  35.    }
  36.    public void setItemNumber(double number)  // Method to set the item number
  37.    {
  38.       this.number = number;
  39.    }
  40.    public double getItemNumber()  // Method to get the item number
  41.    {
  42.       return number;
  43.    }
  44.    public void setStockQuantity(long quantity)  // Method to set the quantity in stock
  45.    {
  46.       stockQuantity = quantity;
  47.    }
  48.    public long getStockQuantity()  // Method to get the quantity in stock
  49.    {
  50.       return stockQuantity;
  51.    }
  52.    public void setItemPrice(double price)  // Method to set the item price
  53.    {
  54.       this.price = price;
  55.    }
  56.    public double getItemPrice()  // Method to get the item price
  57.    {
  58.       return price;
  59.    }
  60.    public double calculateInventoryValue()  // Method to calculate the value of the inventory
  61.    {
  62.       return price * stockQuantity;
  63.    }
  64. }//end class Product
  65.  
  66. public class Inventory
  67. {
  68.    // main methods begins execution of java application
  69.    public static void main( String args[])
  70.    {
  71.     Product p = new Product("Pencil", 5460, 125, 1.5);
  72.     System.out.printf("\n\nItem Name:%s\n",p.getItemName()); //display item name
  73.     System.out.printf("Item Number:%s\n",p.getItemNumber()); //display item number
  74.     System.out.printf("Quantity in Stock:%s\n",p.getStockQuantity()); //display quantity in stock
  75.     System.out.printf("Item Price:$%.2f\n",p.getItemPrice()); //display item price
  76.     System.out.printf("Value of Inventory:$%.2f\n",p.calculateInventoryValue()); //display total value of inventory for this item
  77.  
  78.  
  79.    } // end main method
  80. }//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!
Nov 29 '06 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
Here is my Inventory program for my Java class....

Expand|Select|Wrap|Line Numbers
  1. //Inventory.java
  2. //Class created to store item information for Inventory purposes
  3. //Created November 15, 2006
  4. //Modified November 29, 2006
  5. //Audrey A. Paige
  6. //IT315
  7.  
  8. class Product
  9. {
  10. private String name;     // class variable that stores the item name
  11. private double number;     // class variable that stores the item number
  12. private long stockQuantity; // class variable that stores the quantity in stock
  13. private double price;     // class variable that stores the item price
  14. public Product() // Constructor for the Supplies class
  15. {
  16.      name = "";
  17.      number = 0.0;
  18.      stockQuantity = 0L;
  19.      price = 0.0;
  20. }
  21. public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
  22.      {
  23.          this.name = name;
  24.          this.number = number;
  25.          this.stockQuantity = stockQuantity;
  26.          this.price = price;
  27. }
  28. public void setItemName(String name) // Method to set the item name
  29. {
  30.      this.name = name;
  31. }
  32. public String getItemName() // Method to get the item name
  33. {
  34.      return name;
  35. }
  36. public void setItemNumber(double number) // Method to set the item number
  37. {
  38.      this.number = number;
  39. }
  40. public double getItemNumber() // Method to get the item number
  41. {
  42.      return number;
  43. }
  44. public void setStockQuantity(long quantity) // Method to set the quantity in stock
  45. {
  46.      stockQuantity = quantity;
  47. }
  48. public long getStockQuantity() // Method to get the quantity in stock
  49. {
  50.      return stockQuantity;
  51. }
  52. public void setItemPrice(double price) // Method to set the item price
  53. {
  54.      this.price = price;
  55. }
  56. public double getItemPrice() // Method to get the item price
  57. {
  58.      return price;
  59. }
  60. public double calculateInventoryValue() // Method to calculate the value of the inventory
  61. {
  62.      return price * stockQuantity;
  63. }
  64. }//end class Product
  65.  
  66. public class Inventory
  67. {
  68. // main methods begins execution of java application
  69. public static void main( String args[])
  70. {
  71. Product p = new Product("Pencil", 5460, 125, 1.5);
  72.     System.out.printf("\n\nItem Name:%s\n",p.getItemName()); //display item name
  73.     System.out.printf("Item Number:%s\n",p.getItemNumber()); //display item number
  74.     System.out.printf("Quantity in Stock:%s\n",p.getStockQuantity()); //display quantity in stock
  75.     System.out.printf("Item Price:$%.2f\n",p.getItemPrice()); //display item price
  76.     System.out.printf("Value of Inventory:$%.2f\n",p.calculateInventoryValue()); //display total value of inventory for this item
  77.  
  78.  
  79. } // end main method
  80. }//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

http://www.thescripts.com/forum/thread570714.html
Nov 30 '06 #2

P: 59
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...
Nov 30 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.