Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zad1_wp_facade;
- public class mainClass {
- public static void main(String[] args) {
- WektorFacade wf = new WektorFacade();
- wf.a2D.wyswietl();
- wf.a3D.wyswietl();
- wf.dodajWektor(wf.a3D);
- wf.a2D.wyswietl();
- }
- }
- interface Wektor {
- void dodaj(int x, int y);
- public void wyswietl();
- }
- class Wektor3D implements Wektor {
- int x, y, z;
- public Wektor3D(int x, int y, int z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- @Override
- public void wyswietl() {
- System.out.println("Wektor 3D: " + this.x + " " + this.y + " " + this.z);
- }
- @Override
- public void dodaj(int x, int y) {
- this.x = this.x + x;
- this.y = this.y + y;
- }
- }
- class Wektor2D implements Wektor {
- int x, y;
- public Wektor2D(int x, int y) {
- this.x = x;
- this.y = y;
- }
- @Override
- public void wyswietl() {
- System.out.println("Wektor 2D: " + this.x + " " + this.y + "");
- }
- @Override
- public void dodaj(int x, int y) {
- this.x = this.x + x;
- this.y = this.y + y;
- }
- }
- class WektorFacade {
- protected Wektor3D a3D;
- protected Wektor2D a2D;
- public WektorFacade() {
- a3D = new Wektor3D(1, 2, 3);
- a2D = new Wektor2D(4, 5);
- }
- public void dodajWektor(Wektor3D a){
- a2D.dodaj(a.x, a.y);
- }
- public void dodajWektor(Wektor2D a){
- a2D.dodaj(a.x, a.y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement