in jGRASP
INVENTORY CLASS
You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object).
Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object).
The data fields in the Inventory class include the inventory product number (int), inventory product description (String), inventory product price (float), inventory quantity on hand (int), inventory quantity on order (int), and inventory quantity sold (int).
The Inventory class (.java file) should also contain all of the static data fields, as well as static methods to handle the logic in counting all of the objects processed (counter), as well as totals (accumulators) for the total product inventory and the total product inventory dollar value.
Your Inventory class .java should also contain all of the methods in order to calculate the current product inventory and the dollar value of the inventory product, as well as handling inventory product levels.
In order to calculate the current product inventory, the formula is inventory quantity on hand plus inventory quantity on order minus inventory quantity sold. In order to calculate the dollar value of the inventory product, the formula is inventory product price * (inventory quantity on hand + inventory quantity on order – inventory quantity sold).
A message should be generated and displayed to the user when the inventory product should be ordered if the current product inventory is less than 50 products. For data type float, show the output precision to two decimal places.
The Inventory class should not contain any computer programming code related to inputting of the data or outputting or displaying of the information for this should be handled by the GUI (Graphical User Interface). No GUI programming code should be contained in the Inventory class (.java) file.
General Format of a User-Defined Class
private data fields
final static constants (rates for example)
static programmer-defined variables for counters/accumulators
one or more constructors (overloaded constructors also)
mutator and accessor methods for the private data fields
overloaded mutators to handle data coming into the class in a different data type
methods to calculate and any other methods necessary
methods to add/return for counter(s)
methods to add/return for accumulator(s)
may also want to add the toString method to the Inventory class to show the objects contents.
The Inventory class (.java file) must be a separate .java file from the GUI .java file(s).
public class Inventory {
private int productNumber;
private String productDescription;
private double productPrice;
private int quantityOnHand;
private int quantityOnOrder;
private int quantitySold;
private static int counter;
/**
* @param productNumber
* @param productDescription
* @param productPrice
* @param quantityOnHand
* @param quantityOnOrder
* @param quantitySold
*/
public Inventory(int productNumber, String
productDescription,
double productPrice, int quantityOnHand, int quantityOnOrder,
int quantitySold) {
this.productNumber = productNumber;
this.productDescription = productDescription;
this.productPrice = productPrice;
this.quantityOnHand = quantityOnHand;
this.quantityOnOrder = quantityOnOrder;
this.quantitySold = quantitySold;
counter++;
}
public class Test {
public static void main(String[] args) {
Inventory i1=new
Inventory(1111,"Laptops",1200,340,100,200);
Inventory i2=new Inventory(1213,"Mobile",350,100,50,30);
System.out.println("No of "+i1.getProductDescription()+" in
Inventory :"+i1.currentProductInventory());
System.out.println("Total Cost of "+i1.getProductDescription()+" in
Inventory :"+i1.currentProductInventoryValue());
System.out.println("No of "+i2.getProductDescription()+" in
Inventory :"+i2.currentProductInventory());
System.out.println("Total Cost of "+i2.getProductDescription()+" in
Inventory :"+i2.currentProductInventoryValue());
System.out.println("No of Product Types in Inventory
:"+Inventory.totNoofProductsInInventory());
}
}
/**
* @return the productNumber
*/
public int getProductNumber() {
return productNumber;
}
/**
* @param productNumber
* the productNumber to set
*/
public void setProductNumber(int productNumber) {
this.productNumber = productNumber;
}
/**
* @return the productDescription
*/
public String getProductDescription() {
return productDescription;
}
/**
* @param productDescription
* the productDescription to set
*/
public void setProductDescription(String productDescription)
{
this.productDescription = productDescription;
}
/**
* @return the productPrice
*/
public double getProductPrice() {
return productPrice;
}
/**
* @param productPrice
* the productPrice to set
*/
public void setProductPrice(double productPrice) {
this.productPrice = productPrice;
}
/**
* @return the quantityOnHand
*/
public int getQuantityOnHand() {
return quantityOnHand;
}
/**
* @param quantityOnHand
* the quantityOnHand to set
*/
public void setQuantityOnHand(int quantityOnHand) {
this.quantityOnHand = quantityOnHand;
}
/**
* @return the quantityOnOrder
*/
public int getQuantityOnOrder() {
return quantityOnOrder;
}
/**
* @param quantityOnOrder
* the quantityOnOrder to set
*/
public void setQuantityOnOrder(int quantityOnOrder) {
this.quantityOnOrder = quantityOnOrder;
}
/**
* @return the quantitySold
*/
public int getQuantitySold() {
return quantitySold;
}
/**
* @param quantitySold
* the quantitySold to set
*/
public void setQuantitySold(int quantitySold) {
this.quantitySold = quantitySold;
}
public int currentProductInventory() {
return (quantityOnHand + quantityOnOrder) - quantitySold;
}
public static int totNoofProductsInInventory()
{
return counter;
}
public double currentProductInventoryValue() {
return ((quantityOnHand + quantityOnOrder) - quantitySold)
* productPrice;
}
public void CheckToOrderInventory()
{
if(currentProductInventory()<50)
{
System.out.println("You have to Order Inventory");
}
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Inventory [productNumber=" + productNumber
+ ", productDescription=" + productDescription
+ ", productPrice=" + productPrice + ", quantityOnHand="
+ quantityOnHand + ", quantityOnOrder=" + quantityOnOrder
+ ", quantitySold=" + quantitySold + "]";
}
}
public class Test {
public static void main(String[] args) {
Inventory i1=new Inventory(1111,"Laptops",1200,340,100,200);
Inventory i2=new Inventory(1213,"Mobile",350,100,50,30);
System.out.println("No of "+i1.getProductDescription()+" in Inventory :"+i1.currentProductInventory());
System.out.println("Total Cost of "+i1.getProductDescription()+" in Inventory :"+i1.currentProductInventoryValue());
System.out.println("No of "+i2.getProductDescription()+" in Inventory :"+i2.currentProductInventory());
System.out.println("Total Cost of "+i2.getProductDescription()+" in Inventory :"+i2.currentProductInventoryValue());
System.out.println("No of Product Types in Inventory :"+Inventory.totNoofProductsInInventory());
}
}
Get Answers For Free
Most questions answered within 1 hours.