Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am trying to create an ArrayList of product, i have three types of product:

ProductLine(mainClass), PerishableProductLine(extends ProductLine), ItemisedProductLine(extends ProductLine).

ProductLine Class

Fields: Product Code, recRetPrice, Sale Price, Quantity.

PerishableProductLine Class Fields: Days to Expiry

ItemisedProductLine Class

Fields: String[] Serial Numbers

I am trying to hard code the product in the Inventory Class but i don't know how to insert an array into an ArrayList as one of the parameter, String [] Serial Numbers;

public Inventory()
{
    products = new ArrayList<ProductLine>();
    products.add(new ProductLine("A0001", 10.90, 9.90, 100, "N/A"));
    products.add(new ProductLine("B0010", 12.00, 7.50, 125, "5"));
    products.add(new ProductLine("C0100", 3.00, 2.30, 1000, "16"));
    products.add(new ItemisedProductLine("D1000", 2600, 2490, 2, Arrays.asList("a b d", "e f g h", "i j k l"))));
    products.add(new ProductLine("E0001", 699, 509, 3, Arrays.asList(new serialNumbers("CCCC333333"),new serialNumbers("DDDD444444"), new serialNumber("AAAA222222"))));
}

As you can see in line 7 and 8 i tried to hard code the array as suggested in other similar questions on Stack Overflow but it does not compile.

The errors are generic(stuff like "missing ';' or expecting ')'...")don't know if this can help, I hope i described well the scenario.

ProductLine class

public class ProductLine
{
private String productCode;      // Format X9999
private double recRetPrice;
private double salePrice;
private int    quantity;
private String description;

public ProductLine(String productCode, double recRetPrice, double salePrice, int quantity, String description)
{
    this.productCode = productCode;
    this.recRetPrice = recRetPrice;
    this.salePrice   = salePrice;
    this.quantity    = quantity;
    this.description = description;
}

public  void sold(int no){

}

public String getProductCode(){
    return productCode;
}

public double getPrice(){
    return salePrice;
}

/*public String getSerialNumber(){
    return ItemisedProductLine.serialNumbers;
}*/ //Does not compile

}

ItemisedProductLine

public class ItemisedProductLine extends ProductLine
{
public static String[] serialNumbers;

public ItemisedProductLine(String productCode, double recRetPrice, double salePrice, int quantity, String[] SerialNumber){
    super( productCode,  recRetPrice,  salePrice,  quantity,  description);
    this.serialNumbers = serialNumbers;
}    
public void sold(int no){}

}
share|improve this question
 
Post the declaration of the ItemisedProductLine and ProductLine constructors. in itself your code is fine. –  Marko Topolnik May 10 '12 at 8:48
 
apart from the too many closing Parentheses on the ItemisedProductLine line –  Woody May 10 '12 at 8:50
1  
OP, please convince us that you are not abusing us to balance your parens for you. –  Marko Topolnik May 10 '12 at 8:57
add comment

1 Answer

Isn't there an extra ")" at the end of line 7?

share|improve this answer
 
+1 in fact there is, but only on line 7. –  Péter Török May 10 '12 at 8:53
 
Let's hope he's not alerting SO about ONE EXTRA PAREN! –  Marko Topolnik May 10 '12 at 8:54
 
Hmm, checked. You're right :) I hate those (((( and )))), always confusing me! xD –  shuuchan May 10 '12 at 8:55
 
embarrassing!!! i really need a break. You guys actually right, now it complains about something in my ItemisedProductLine class. –  fra pet May 10 '12 at 9:18
 
Thanks everyone for the help, i spent quite a bit of time on that(better i don't say how much...):-) –  fra pet May 10 '12 at 9:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.