Skip to main content

Java Program-Credits Company,costumers.

No replies
dewiktor
Offline
Joined: 2013-09-08
Points: 0

Hello i want to ask about many things.
I have to do program.
We have company.
This company have contracts with many distributors, this distributors have contracts
with shops.Shops giving credits for Costumers for some stuff.
Client have name,surname,ID.
Distributors have and shop have name.

1.Adding Distributors
2.Adding shops and adding this shops to Distributor.
3.Return Information that specified shop gave credit (return person name,ID and what did costumer took from the shop.
4.Return sum of all credits from specified shop.
5.Return sum of all credits from specified distributor.
6.Each Distributor and Shop have name.
7.Clients have name,ID,surname.
8.Use Abstract Class or Interfaces or Both.

I made many mistake here in this program and there is some stuffs that i can't do.
I was trying to find information here,and java2s.com but i can't find more.
Any help will be great ;]

class Company

public class Indesto {
private String name;
protected Distributor[] table=new Distributor[100];
protected Shop[] table2=new Shop[100];
protected int licznik=0;
protected int licznik2=0;
public Indesto(String n)
{

this.name=n;
}
public String getName()
{
return name;
}
public void add(Distributor distributor)
{
table[licznik] = distributor;
licznik++;
}
}
>

class Distributor  extends Indesto
{	
	public Distributor(String n) {super(n);}
	 public void add(Shop shop)
	  {
	    table2[licznik2] = shop;
	    licznik2++;
	  }
	public void save()
	{
		
	}
	
}


public class Products {
public String pname;
public int qty;

public Products(String pname, int qty) {
this.pname = pname;
this.qty = qty;

}

public String toString() {
return "pid = " + getPname() + ", Desc = " + getQty();
}

public void setPname(String pname) {
this.pname = pname;
}

public void setQty(int qty) {
this.qty = qty;
}

public String getPname() {
return (this.pname);
}

public int getQty() {
return (this.qty);
}

}


public class Costumer {

private String Surname;
private String Name;
private int ID;

public Costumer(String n, String s, int p) {

this.Name = n;
this.Surname = s;
this.ID = p;
}

public String getName() {
return Name;
}

public String getSurname() {
return Surname;
}

public int getID() {
return ID;
}
}


public class ItemList {

private Products[] itemArray;
private int index = 0;

ItemList(int initSize) {
itemArray = new Products[initSize];
}

void add(Products product) {

if (index >= itemArray.length) {
Products[] temp = new Products[itemArray.length * 2];
for (int i = 0; i < itemArray.length; i++)
temp[i] = itemArray[i];
itemArray = temp;
}
itemArray[index++] = product;
}

Products get(int i) {
return itemArray[i];
}

int size() {
return index;
}
}


public class Shop extends Indesto {
private ItemList itemList;
private int index = 0;

public Shop(String n) {
super(n);
itemList = new ItemList(2);
}

void add(Products product) {
itemList.add(product);
}

boolean hasMoreElements() {
return index < itemList.size();
}

Products nextElement() {
return itemList.get(index++);
}

public void save() {

}

}

public class Test {

private Costumer[] table = new Costumer[100];

private int l = 0;

/**
* @param args
*/
public void addPerson(Costumer p) {
table[l] = p;
l++;
}

public void info() {
for (int i = 0; i < l; i++)
System.out.println("name " + table[i].getName() + " \nsurname "
+ table[i].getSurname() + " \npID " + table[i].getID());

}

public static void main(String[] args) {
// TODO Auto-generated method stub\
Test t = new Test();
Costumer c = new Costumer("Adam", "Maloney", 920601);
t.addPerson(c);
t.info();

Shop shop = new Shop("WalMart");

shop.add(new Products("Fridge", 1));
shop.add(new Products("Socks", 3));
shop.add(new Products("car", 3));
while (shop.hasMoreElements())
System.out.println("Products in the shop " + shop.nextElement());

}

}

## Heading ##