Results 1 to 2 of 2
  1. #1
    chkm8 is offline Member
    Join Date
    Dec 2008
    Location
    Canjulao, Jagna, Bohol Philippines
    Posts
    10
    Rep Power
    0

    Default help array set null or delete

    hai.., I have problem of setting the array found to null. I want to set the found array(result of the search of the item to be stock out) to null if the number of stock to out is equal to the number of the stocks in of the product.

    sapmle:

    Chocolate 001 $5.50 12(stocks in)

    Enter Number of stock out: 12

    Number of stock out: 12
    total cost=(12*5.50)

    //so the Chocolate now will be out of stock and I want to delete it so that the user can input another product

    heres my code.

    Java Code:
    public ProductInfo computeStockOut() //computing the total amount of stock
    	{
    		int num;
    		double totalAmount;
    		int newStck;
    		System.out.print("Enter Number Of Stock to Out: ");
    		num=i.getInt();
    			if(num<=found.getNumStock())
    			{
    				newStck=found.getNumStock()-num;
    				found.setNumStock(newStck);
    				totalAmount=found.getPrice()*num;
    				System.out.println("Total Amount is: "+totalAmount);
    				System.out.println("");
    				if(newStck==0)
    				{
    					found=null;
    				}
    			}
    			else{
    				System.out.println("You Enter Number greater than your stock products");
    			}
    		return found;	
    	}

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    stockIn = stockIn - stockPurchased.

    Maybe I'm not following your question properly but I think you can just do that. I think your issue is with newStck. Why not just this.setNumStock(getNumStock - num) or something along those lines.

    What is happening when you run it? Does numstock remain at 12 or is it throwing an error?
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. Delete Button
    By Zoroxeus in forum JavaServer Faces (JSF)
    Replies: 3
    Last Post: 10-26-2008, 02:45 PM
  2. Delete
    By Sarinam in forum New To Java
    Replies: 6
    Last Post: 07-23-2008, 11:09 AM
  3. Delete From .txt file
    By Sarinam in forum New To Java
    Replies: 86
    Last Post: 06-28-2008, 10:17 AM
  4. Listbox Add/Delete
    By Rageagainst20 in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 04:49 PM
  5. Null array when passed to MouseListener
    By stevemcc in forum New To Java
    Replies: 2
    Last Post: 04-02-2008, 10:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •