Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Magazin
- {
- String nume;
- Produs p1 = new Produs("p1",10.0,3);
- Produs p2 = new Produs("p2",20.0,4);
- Produs p3 = new Produs("p3",30.0,2);
- public String toString()
- {
- return this.p1.toString() + "\n" + this.p2.toString() + "\n" + this.p3.toString();
- }
- public double getTotalMagazin(Magazin m)
- {
- double sum;
- sum = m.p1.getTotalProdus(p1) + m.p2.getTotalProdus(p2) + m.p3.getTotalProdus(p3);
- return sum;
- }
- public static void main(String args[])
- {
- Magazin m = new Magazin();
- Magazin m1 = new Magazin();
- Produs p = new Produs("p1",10.0,32);
- //p.toString(p);
- //System.out.println(p.getTotalProdus(p));
- //m.toString(m1);
- System.out.println(m.getTotalMagazin(m1));
- System.out.println(m.toString());
- }
- }
- class Produs
- {
- String nume;
- double pret;
- int cantitate;
- Produs(String n, double p, int c)
- {
- nume = n;
- pret = p;
- cantitate = c;
- }
- public String toString()
- {
- return "Produsul " + this.nume + " are pretul " + this.pret + ", regasindu-se in numar de " + this.cantitate + " de bucati.";
- }
- double getTotalProdus(Produs p)
- {
- double total;
- total = p.pret * p.cantitate;
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement