Okay. I'm fairly new in this Java thing, but i'm desperately trying to learn. I've come upon somewhat of a deadend. I'm making an inventory program as part of school and i have a superclass Items with 4 instance variables. No problem there. I have 4 subclasses, two of which is mandatory Food class, which have a futher 2 variables and Nonfood class, which have one more variable. My problems is this.
Right now i'm working with an ArrayList (this is what i know so far) but i'm seriously considering working with a map or a linkedMap.
I have based my ArrayList on my superClass Items, but i'm having trouble getting my subclass variables into my ArrayList. Any idea how that's done. Using relative simple solutions (remember i'm new at this)
I have not yet got my id working. I've, in the spirit of the shop terminology, called it barCode. It's part of my Superclass, and i can't seem to initialize it in my main class.
//constructer from superclass
public Items (int barCode, String itemName, String itemSupplier, double itemPrice, int stock)
{
this.itemName = itemName;
barCode = GenerateBarCode();
this.itemSupplier = itemSupplier;
this.itemPrice = itemPrice;
this.stock = stock;
// getter method for barCode
protected int getBarCode()
{
return barCode;
}
// method for generating barcode
private int GenerateBarCode()
{
Random barCode = new Random();
int barCode1 = barCode.nextInt(100000);
return barCode1;
}
If any more code i needed, let me know. I'm working on getting it a bit prettyer.
this.barCode = GenerateBarCode();?barcodeis generated internally, and thus should not be provided as a parameter to constructor.