Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-06-2011, 07:42 AM   PM User | #1
Episkey
New to the CF scene

 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Episkey is an unknown quantity at this point
Create 1d array from 2d array

Hey im working on a code where i need to get a certain column of a 2d array and create a 1d array with the information.

The information im using is a product list in an aray in thsi format [barcode][price][stock]

Now i need to grab the bar codes of the files that are under a certain stock.

I have so far manged to get my code to output the barcodes that are understocked but cannot work out how to put them into an array.

Heres my code so far:

Code:
public long[] understockedProductBarcodes(){
		long minStockLevel = 500;
                int maxElements = productBarcodeList.length;
		long[] understockedBarcode;
		understockedBarcode = new long[maxElements];
		int totalColumns = 3;
		int r = 0;
		int c = 0;
		for (r = 0; r < productBarcodeList.length; r++){
			for (c = 2; c < totalColumns; c++){
				if (productBarcodeList[r][c] > 0){
					if (productBarcodeList [r][c] < minStockLevel){
						System.out.println(productBarcodeList[r][0]);
					}
				}
			}
		}
		return understockedBarcode;
	}

Last edited by Episkey; 09-06-2011 at 07:47 AM..
Episkey is offline   Reply With Quote
Old 09-06-2011, 10:39 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,041
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!

Ask a mod to move this thread over to the correct forum.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 09-06-2011, 04:42 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
All you need to do is add them to your array.

How did you get this array in the first place? This seems a prime for moving into an Object (as java is an OO language afterall), and use collections:
PHP Code:
public class Item
{
    private 
long barcode;
    private 
long price// maybe a float?  Just going by the array you have.
    
private long stock;

    
// Setup your accessors and mutators

    
public boolean isUnderstocked(long toStock)
    {
        return (
this.stock toStock) <= 0;
    }
}

//...
public Vector<ItemunderstockedProduct(long toStock)
{
    
Vector<Item= new Vector<Item>();
    for (
Item i yourItemCollection)
    {
        if (
i.isUnderstocked(toStock))
        {
            
v.add(i);
        }
    }
    return 
v;

Just seems easier to treat these as objects instead of three dimensional arrays.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:38 PM.


Advertisement
Log in to turn off these ads.