Jump to content

Trying to write "store" program

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
TAboy24

TAboy24

    Newbie

  • Members
  • PipPip
  • 13 posts
Hi friends!!!
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)


#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Well, I believe you really would need to run towards a database directly, you can't keep all the different items in memory during the run...

and yuo might need to split the lass abot into other classes. "Storage" might be a splendid class that would extend to dry, refridgerated, freezed, fresh, deli etc... and then just let your Item have a member variable that holds an object of that kind in mind...

#3
TAboy24

TAboy24

    Newbie

  • Members
  • PipPip
  • 13 posts
Thanks,
the basic need is to have those classes i mentioned...thats the demanding of the task...as the next tree i just drew..

Stock Class(having array of Item) Date Class
I I I I I... (for use in foodItem and stock
I I I I I...
(Class) Item
I
I
--------------------------
I I I
refrigiraedItem foodItem electronicItem
(subclasses class)


Thanks!

#4
whitey6993

whitey6993

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 437 posts
I have a few suggestions that may help.

Instead of using an array for inventory, you could use a linked list. These are dynamic and can grow in size unlike arrays. I don't know how to use them, but if you find a tutorial, you should be alright. The super call will call the constructor or the super class. For example, if you had a class foodItem, and you wanted to call the constructor of its super class Item, you would use this:

super(/*arguments to super class constructor*/);

You can make a variable immutable by using this statement:

public static final varName; 

The variable can either be public or private, depending on its use. Good luck with this project!

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
There's a C++ tutorial on linked lists that you should be able to adapt to Java with minimal difficulty.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog