I just started to write a program that alows me to control a big Grocery store..(inheritance Polyphormism subject exercise mostly)..
It supposed to allow input basic information about the items,storing it,enabling to use the info later,allowing adding new items ,finding the expired items..etc..
first,I wrote the Class "Item"-enabling to have name,quantity and producing by itself a serial number..enabling basic functions getting the info and printing it..
second i wrote a sub classes of "Item"(extending Item)-foodItem,refregoratedItem and electronicItem...they have also some additional stuff everyone of them...for example foodItem contains the expiry and production dates as well(the Date supposed to be represented as a class)...
i must to admit in all the subclasses i had no idea how to use&write the "super" call..and not sure how keep some vars immutable(as Minimal&Maximal temerature in "RefregiratedItem" extended class)..
all the items of the store must be managed by "Stock" class ,being kept in an array of maximum 100(no idea how to keep it flexible/dynamic for the proper input size)..enabling by funcions adding new item,remove item,print all items as string,remove only the expired items..
I really need help.. despite reading all the leterature on it ..it messes me up even more..I try but still need help please..
thank you all,happy new year!(sorry its still so messy and far from being finished:(...hope being able to write something more worthy in the future..
thanx!
here are the classes:(also i added zip file of java)
public class Item {
public static void main () {
protected String _name;
protected int _quantity=0;
private long _catalogueNumber=1000001;
int _counter=1;
public Item(String name,int quantity) {
_name = name;
_quantity = _quantity+quantity;
_catalogueNumber +=1;
}
public String getName() {
return _name;
}
public int getQuantity() {
return _quantity;}
public long getCatalogueNumber() {
return _catalogueNumber;
}
public void printItem() {
System.out.println("Item: "+_name);
System.out.println("quantity: "+_quantity);
System.out.println("zCatalogue Number: "+_catalogueNumber);
}
}
}}
------------------------------------
public class RefrigiratedItem extends Item {
private int _minTemperature=10;
private int _maxTemperature=20;
public RefrigiratedItem ( int minTemperature, int maxTemperature){
super () ;
_ minTemperature= minTemperature;
_maxTemperature= maxTemperature;
}
}
------------------------------
public class FoodItem extends Item {
protected Date _ProductionDate;
protected Date _ExpiryDate;
public FoodItem ( Date ProductionDate,Date ExpiryDate){ //???
super ()
_ProductionDate= ProductionDate;
_ExpiryDate=ExpiryDate;
}
}
------------------------
public class Stock {
public static void main () {
final int MAX_SIZE=100;
private Item[] itemList=new Item[MAX_SIZE];
String itemName;
int itemQuantity
int i=0;
public Stock() {
SimpleInput sinp=new SimpleInput(System.in);
while (i<MAX_SIZE){
System.out.println("add a new item name and quantity or type empty or 0 value to quit");
itemName=sinp.ReadStr();
itemQuantity=sinp.ReadInt();
if (itemName.length==0) II (itemQuantity==0)II(i+itemQuantity>MAX_SIZE)) {
system.out.println("Illegal Input!-input must be a valid string and more than 0 quantity and not exceed the maximal limitation");
break;}
for (int k=0;k<itemQuantity;k++) {
itemList[i]=Item(itemName,itemQuantity);
i++}}
}}
// Add item to stock
public void addItem (Item newItem){
i++;
if newItem.getName==NULL && i>MAX_SIZE)) {
system.out.print("Illegal Input!");
break;
}
itemList[i]=Item(itemName,1);}
}
public void removeItem (Item item) {
for (int k;k<MAX_SIZE;k++) {
if item==itemList[k]
itemList[i]=Item(NULL,0);}
}
public String toString () {
for (int k;k<MAX_SIZE;k++) {
system.out.println(itemList[k].getName+"/n"+"/n");
}
public void removeAfterDate (Date d){
for (int k;k<MAX_SIZE;k++) {
if d
}
public int howMany (int temp){
}
}
Attached Files
Edited by WingedPanther, 04 January 2009 - 05:16 AM.
add code tags (the # button)


Sign In
Create Account



Back to top









