Program Java-Clienci

0

Witam robie program ,ktory umozliwia udzielanie kredytow na zakupy w sklepach.

1.Dodanie Dystrybutora
2.Dodanie sklepu i dodanie do Dystrybutora
3.Wypisanie sum kredytow udzielonych przez sklep.
4.Wypisanie sum kredytow udzielonych przez danego dystrybutora.
5.Wypisanie sum kredytow wzietych przez klienta(tutaj problem)
Potrzebna jest pomoc wlasnie z tym podpunktem 5,probowalem juz duzo rzeczy,ale ciagle jakies bledy.
Klasa Sklep

 
public class Shop  implements Adding
{
	private String name;
	private String pname;
	private int price;
	private int sum;
public Shop(String n)
{
	this.name=n;
	
}
public String metoda(String pname,int price,Costumer c)
{
	this.pname=pname;
	this.price=price;
	sum +=price;
	return "Kredyt udzielony w sklepie na okaziciela "+c.getName()+"nr pesel"+c.getID()+ "nazwisko "+c.getSurname()+" na cene "+price;
}
public int getCreditSum()
{
	return sum;
}
public String getName()
{
	
return name;
}
public String toString()
{
	return "Suma kredytow udzielonych przez sklep "+getName()+" na cene "+ sum;
	
}
public String getPname()
{
	return pname;
}
public int getPrice()
{
	return price;
}

}

Klasa Dystrybutor

public class Distributor  implements Adding
{
	private String name;
	private List <Shop>shops;
public Distributor(String n)
{
	this.name=n;
	shops=new ArrayList<Shop>();
}
public Distributor()
{
	
}
public void Add(Shop shop)
{
	shops.add(shop);
}
public String getName()
{
	return name;
}

public void sumCreditD(Shop shop)
{
	int suma=0;
	for(int i=0;i<shops.size();i++)
	{
		suma+=shops.get(i).getCreditSum();
				
	}
	System.out.println(" Dystrybutor "+getName()+" udzielil kredytow na sume "+suma);
}
public int getSize()
{
	return shops.size();
	

}


}

 

Klasa Costumer

public class Costumer  implements Adding
{
	private String name;
	private String surname;
	private int ID;
	
public Costumer(String name,String surname,int ID)
{
	this.name=name;
	this.surname=surname;
	this.ID=ID;
	
}
public String getName()
{
	return name;
}
public String getSurname()
{
	return surname;
}
public int getID()
{
	return ID;
}

}
 

Klasa Test

 
public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
  Costumer c=new Costumer(" Wik","Dę",92060);
  Costumer c1=new Costumer(" AQ","Kar",9206);
  Costumer c2=new Costumer(" Wik","Dę",92060);
  Shop s=new Shop("salon samochodowy");
  Shop s1=new Shop("salon samochodowy-Ford");
  Distributor d=new Distributor("Volvo");
  Distributor e=new Distributor("Ford");
  d.Add(s);
 d.Add(s1);
  s1.metoda("s", 3000, c2);
  s1.metoda("s2", 3000, c2);
  s.metoda("ford", 4000, c1);
  s.metoda("ford", 4000, c);
  System.out.println(s.metoda("ford", 4000, c2));
  System.out.println(s.toString());
  System.out.println(s1.toString());
  d.sumCreditD(s);
  
  
	}

}

Klasa Indesto

 
import java.util.ArrayList;
import java.util.List;


public class Indesto 
{
private List <Distributor>distributors;
public Indesto()
{
	distributors=new ArrayList<Distributor>();
}
public void Add(Distributor dis)
{
	distributors.add(dis);
}

}

Chodzi o stworzenie metody ktora by zwracala sume(liczbe) na jaka klient jest zadluzony.
Interface pominac(jest tam tylko metoda getName())

0

Dodaj do klasy Customer (a nie Costumer) pole o nazwie credit. Każde wywołanie typu

s1.metoda("s", 3000, c2)

powinno zwiększyć wartość tego pola dla Customera c.
Nazwę funkcji metoda sam wymyśliłeś? Gratuluję inwencji.

1 użytkowników online, w tym zalogowanych: 0, gości: 1