I am trying to make a program for my java course and it is supposed to hold basic inventory items for an office supply store. My instance variables are:
String itemNumber;
integer quantityOnHand;
integer reorderLevel;
double cost;
integer numberOnOrder;
String description;
The methods are:
A constructor that sets quantityOnHand and numberOnOrder to 0, and takes in data for the rest.
A constructor that takes and sets all the data.
Typical getters for all data.
Setters for reorderLevel and description.
A Special setter for itemNumber that guarantees the data is always stored in uppercase. Should be called from the constructors.
Method called orderItems that takes in an integer variable numOrdered and updates the number of the items that are on order.
Method called receiveOrderedItems that takes in an integer variable numberReceived and updates the number of the items on hand and the number still on order.
Method called sellItems that takes in an integer variable numberSold and updates the number of items on hand.
Method called getCurrentInventoryValue that returns the total cost of the item that is on hand.
An equals method that compares 2 instances of the InventoryItem class. It will return true if the 2 instances are the same, false otherwaise.
A toString method to display data about the instance of InventoryItem class. Format should match the following example:
Item Number: D-145-BLK
Description: Black Case-it Large Capacity 3-Inch Zipper Binder
Cost: $19.97
Quantity Available: 123
Re-order level: 50
Number on order: 0
This is what I have so far
public class InventoryItem
{
private String itemNumber;
private int quantityOnHand;
private int reorderLevel;
private double cost;
private int numberOnOrder;
private String description;
// Constructor that sets quantityOnHand and numberOnOrder to zero, and takes in data for the rest.
public InventoryItem(int quantityOnHand, int numberOnOrder)
{
this.quantityOnHand = 0;
this.numberOnOrder = 0;
}
// Constructor that takes and sets all the data
public InventoryItem(String itemNumber, String description, double cost, int quantityOnHand, int reorderLevel, int numberOnOrder)
{
this.itemNumber = itemNumber;
this.description = description;
this.cost = cost;
this.quantityOnHand = quantityOnHand;
this.reorderLevel = reorderLevel;
this.numberOnOrder = numberOnOrder;
}
// Special setter for itemNumber, data is always stored in upper-case.
public void setItemNumber(String itemNumber)
{
itemNumber = itemNumber.toUpperCase();
}
// Getter for itemNumber.
public String getItemNumber()
{
return itemNumber;
}
// Setter for reorderLevel.
public void setReorderLevel(int reorderLevel)
{
this.reorderLevel = reorderLevel;
}
// Getter for reorderLevel.
public int getReorderLevel()
{
return reorderLevel;
}
// Setter for description.
public void setDescription(String description)
{
this.description = description;
}
// Getter for description.
public String getDescription()
{
return description;
}
// Getter for quantityOnHand.
public int getQuantityOnHand()
{
return quantityOnHand;
}
// Getter for cost.
public double getCost()
{
return cost;
}
// Getter for numberOnOrder.
public int getNumberOnOrder()
{
return numberOnOrder;
}
// Method that takes in numOrdered and updates that number of items that are on order.
public void orderItems(int numOrdered)
{
numOrdered = numberOnOrder + numOrdered;
}
// Method that takes in numberReceived and updates that number of items on hand and number that is still on order.
public void receiveOrderedItems(int numberReceived)
{
quantityOnHand = quantityOnHand - numberReceived;
numberOnOrder = numberOnOrder + numberReceived;
}
// Method that takes in numberSold and updates that the number of items on hand.
public void sellItems(int numberSold)
{
quantityOnHand = quantityOnHand - numberSold;
}
// Method that returns the total cost of the item that is on hand.
public void getCurrentInventoryValue()
{
cost = cost * numberOnOrder;
}
// toString method that displays the data about the instance of InventoryItem class.
public String toString()
{
return "Item Number: " + itemNumber + "\nDescription: " + description + "\nCost: " + cost +
"\nQuantity Available: " + quantityOnHand + "\nRe-order level: " + reorderLevel +
"\nNumber on order: " + numberOnOrder;
}
}
In my application class I have
public class InventoryDriver
{
public static void main(String[] args)
{
InventoryItem item1 = new InventoryItem(0,0);
InventoryItem item2 = new InventoryItem("d-145-blk", "Black Case-it Large Capacity 3-Inch Zipper Binder", 19.97, 123, 50, 0);
System.out.println(item1);
System.out.println();
System.out.println(item2);
}
}
when ran, I get :
Item Number: null
Description: null
Cost: 0.0
Quantity Available: 0
Re-order level: 0
Number on order: 0
Item Number: d-145-blk
Description: Black Case-it Large Capacity 3-Inch Zipper Binder
Cost: 19.97
Quantity Available: 123
Re-order level: 50
Number on order: 0
How do I make an equals method? and why doesn't my order item number show up in upper-case even though I set it?
Can someone help me please?
Thanks.