Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public class Magazin
  2. {
  3. String nume;
  4. Produs p1 = new Produs("p1",10.0,3);
  5. Produs p2 = new Produs("p2",20.0,4);
  6. Produs p3 = new Produs("p3",30.0,2);
  7.  
  8.  
  9. public String toString()
  10. {
  11. return this.p1.toString() + "\n" + this.p2.toString() + "\n" + this.p3.toString();
  12. }
  13.  
  14. public double getTotalMagazin(Magazin m)
  15. {
  16. double sum;
  17. sum = m.p1.getTotalProdus(p1) + m.p2.getTotalProdus(p2) + m.p3.getTotalProdus(p3);
  18. return sum;
  19. }
  20.  
  21. public static void main(String args[])
  22. {
  23. Magazin m = new Magazin();
  24. Magazin m1 = new Magazin();
  25. Produs p = new Produs("p1",10.0,32);
  26. //p.toString(p);
  27. //System.out.println(p.getTotalProdus(p));
  28. //m.toString(m1);
  29. System.out.println(m.getTotalMagazin(m1));
  30. System.out.println(m.toString());
  31. }
  32. }
  33.  
  34. class Produs
  35. {
  36. String nume;
  37. double pret;
  38. int cantitate;
  39. Produs(String n, double p, int c)
  40. {
  41. nume = n;
  42. pret = p;
  43. cantitate = c;
  44. }
  45. public String toString()
  46. {
  47. return "Produsul " + this.nume + " are pretul " + this.pret + ", regasindu-se in numar de " + this.cantitate + " de bucati.";
  48. }
  49.  
  50. double getTotalProdus(Produs p)
  51. {
  52. double total;
  53. total = p.pret * p.cantitate;
  54. return total;
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement