I need to write an inventory system program using java...

The inventory control system should have
1. Login in to the system.
2. Adding new items.
3. Modifying data of selective item.
4. Deleting existing items.
5. Check the stock availability.
6. Real time stock management (ie. When purchase happen you have to increase the stock availability and if sales occurs you have to reduce the stock availability.)

hey guys.. i could really use some help.. im writing this in java.. i hv absolutely no clue what i should be doing.. cuz out lecturer is rubish..
but..
i did some reading and i tried something out i dunno if you guys could help...
i made two classes Inventory and Item

i will past the code i have written...

what i really want to know how 2 do tho is number 6. which is

" real time management" ( no clue what this is or where to start)
this is as far as reading ( as a complete newbie) got me..
please help me out guys...
most important is number 6 the real time management ( which i have not written cuz i dpont know how)\
thank u
here is the code

Inventory src code :

public class inventory {


private static Item[] inventory;
private static Scanner sc;
private static int noOfItems;

/**
* @param args
*/
public static void main(String[] args) {
noOfItems=0;
sc=new Scanner(System.in);
// TODO Auto-generated method stub
inventory=new item[10];
run();
}

public static int displayMenu()
{
System.out.println("1.Add Item");
System.out.println("2.Find Item");
System.out.println("3.Delete Item");
System.out.println("4.Count Item");
System.out.println("5.Exit");
System.out.println("Please enter your choice:");
int i=sc.nextInt();
return i;
}

public static void run()
{
while(true)
{
int i=displayMenu();
switch(i)
{
case 1:addItem();
break;
case 2:findItem();
break;
case 4:countItem();
break;
case 5:return;
defaultystem.out.println("Invalid choice");
}
}
}

public static void addItem()
{
System.out.print("Enter Item namme:");
String item_name=sc.next();
System.out.print("Enter barcode:");
String barcode=sc.next();
System.out.print("Enter price:");
double price=sc.nextDouble();
Item b=new Item(item_name,barcode,price);
if(noOfItems==inventory.length)
System.out.println("Array is full");
else
{
inventory[noOfItems++]=b;
System.out.println("Item added successfully");
}
}

public static void findItem()
{
System.out.print("Enter item name:");
String item_name=sc.next();
for(int i=0; i<noOfItems; i++)
{
if(item_name.equalsIgnoreCase(inventory[i].getItem_name()))
{
System.out.println("Item found:");
System.out.print(Inventory[i]);
return;
}
}

}

public static void countItems()
{
System.out.println("Num of items:"+noOfItems);
for(int i=0; i< noOfItems; i++)
System.out.println(inventory[i]);
}

}

ITEM src codehere

public class item {

private String item_name;
private String barcode;
private double price;

//To initialise the state of the object
public void Item(String item_name,String barcode,double price)
{
this.item_name=item_name;
this.barcode=barcode;
this.price=price;
}

//Reader methods i.e behavior methods
public String getItem_name()
{
return item_name;
}

public String getBarcode()
{
return barcode;
}

public double getPrice()
{
return price;
}

//Writer methods or setter methods
public void setTitle(String item_name)
{
this.item_name=item_name;
}

public void setPrice(double price)
{
if(price < 0)
System.out.println("Price cannot be negative");
else
this.price=price;
}

public void setBarcode(String barcode)
{
this.barcode=barcode;
}
public String toString()
{
return "Item name:"+item_name+",Barcode:"+barcode+",Price:"+price;
}

}

Recommended Answers

All 6 Replies

Where is the sale and purchase of Inventory happening ?

what do you mean?
your talking about the real time? well im guessing that the lecturer just wants the program to be able to handle such event if it occurs... all he wants to see is that the program is up and running really..
im sorry but like i said im really clueless...
i just did alot of scannin through books and internet and this is what i could come up with..
it's really the best i can do :S

where's the urgency? I don't need something like that.

3. Modifying data of selective item.

For modifying I suggest that once you call the findItem method, to ask the user for new data from the keyboard and change the item found:

System.out.println("Item found:");
System.out.print(Inventory[i]);
// ask for new data
inventory[i].set...();

return;

4. Deleting existing items.

After you search for the item you want to delete you can set that item to null:

inventory[i] = null;
noOfItems--;

That will change all you implementation of course. Your array will have gaps between the elements with null values.

So when you add instead of simply increasing noOfItems and using it as index, you can loop the array and whenever you find a null value, insert the new item to that spot and increase the noOfItems. Remember that when you initialize the array all its elements are null.

At the findItem method you can have your search to be like this:

if ( (inventory[i]!=null) && (item_name.equalsIgnoreCase(inventory[i].getItem_name()))
)

For counting items and printing them you can print only those that are not null:

System.out.println("Num of items:"+noOfItems);
for(int i=0; i< noOfItems; i++) {
  if (inventory[i]!=null) System.out.println(inventory[i]);
}

For 5 and 6, you need to redesign your class and change your whole implementation:

public class item {

private String item_name;
private String barcode;
private double price;
private int quantity = 0;

public void sellItem() {
  quantity--;
}

public void buyItem() {
   quantity++;
}

public boolean isAvailable() {
  return quantity>0;
}
}

That would mean that whenever you add an item, you will have to check if the item already exists in the array. If yes just increase the quantity. Else just add a new Item to en empty slot.

For deleting it's up to you whether to just decrease or remove completely.
I would remove completely, and have another option for selling that item. Checks whether it is available using the quantity variable need to be made.

commented: brilliant post! great help! lots of info too +0

wow... thanks a million bro!
for 5 and 6 , the code you wrote there.. do i still need to add the if function to it? ( sorry if it sounds like a dumb question its my very first attempt at any java programming.)
thank you so much for all this help!

do i still need to add the if function to it?

I don't understand. Post your new code. Also, are you allowed to use the Vector or the ArrayList class?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.