Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package zad1_wp_facade;
  2.  
  3. public class mainClass {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. WektorFacade wf = new WektorFacade();
  8.  
  9. wf.a2D.wyswietl();
  10. wf.a3D.wyswietl();
  11.  
  12. wf.dodajWektor(wf.a3D);
  13. wf.a2D.wyswietl();
  14. }
  15.  
  16. }
  17.  
  18. interface Wektor {
  19. void dodaj(int x, int y);
  20. public void wyswietl();
  21. }
  22.  
  23. class Wektor3D implements Wektor {
  24.  
  25. int x, y, z;
  26.  
  27. public Wektor3D(int x, int y, int z) {
  28. this.x = x;
  29. this.y = y;
  30. this.z = z;
  31. }
  32.  
  33. @Override
  34. public void wyswietl() {
  35. System.out.println("Wektor 3D: " + this.x + " " + this.y + " " + this.z);
  36. }
  37.  
  38. @Override
  39. public void dodaj(int x, int y) {
  40. this.x = this.x + x;
  41. this.y = this.y + y;
  42. }
  43. }
  44.  
  45. class Wektor2D implements Wektor {
  46.  
  47. int x, y;
  48.  
  49. public Wektor2D(int x, int y) {
  50. this.x = x;
  51. this.y = y;
  52. }
  53.  
  54. @Override
  55. public void wyswietl() {
  56. System.out.println("Wektor 2D: " + this.x + " " + this.y + "");
  57. }
  58.  
  59. @Override
  60. public void dodaj(int x, int y) {
  61. this.x = this.x + x;
  62. this.y = this.y + y;
  63. }
  64. }
  65.  
  66. class WektorFacade {
  67. protected Wektor3D a3D;
  68. protected Wektor2D a2D;
  69.  
  70. public WektorFacade() {
  71. a3D = new Wektor3D(1, 2, 3);
  72. a2D = new Wektor2D(4, 5);
  73. }
  74.  
  75. public void dodajWektor(Wektor3D a){
  76. a2D.dodaj(a.x, a.y);
  77. }
  78.  
  79. public void dodajWektor(Wektor2D a){
  80. a2D.dodaj(a.x, a.y);
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement