From 14a1b7186cf9baf0fc0f85b989adf68fd19d6dc2 Mon Sep 17 00:00:00 2001 From: marcin Date: Sun, 14 Apr 2019 12:05:09 +0200 Subject: [PATCH] added java --- Java/zad1_1/Przedmiot.java | 11 ++++++ Java/zad1_1/zad1_1.java | 16 +++++++++ Java/zad1_2/Vector2D.java | 27 ++++++++++++++ Java/zad1_2/zad1_2.java | 14 ++++++++ zad6_1.cpp | 73 ++++++++++++++++++++++++++++++++++++++ zad6_2.py | 40 +++++++++++++++++++++ 6 files changed, 181 insertions(+) create mode 100644 Java/zad1_1/Przedmiot.java create mode 100644 Java/zad1_1/zad1_1.java create mode 100644 Java/zad1_2/Vector2D.java create mode 100644 Java/zad1_2/zad1_2.java create mode 100644 zad6_1.cpp create mode 100644 zad6_2.py diff --git a/Java/zad1_1/Przedmiot.java b/Java/zad1_1/Przedmiot.java new file mode 100644 index 0000000..27919cc --- /dev/null +++ b/Java/zad1_1/Przedmiot.java @@ -0,0 +1,11 @@ +package POB_2019.Java.zad1_1; + +public class Przedmiot { + private String subjectName; + public Przedmiot(String name){ + this.subjectName=name; + } + public String toString(){ + return this.subjectName + "JEchane"; + } +} \ No newline at end of file diff --git a/Java/zad1_1/zad1_1.java b/Java/zad1_1/zad1_1.java new file mode 100644 index 0000000..42ba44d --- /dev/null +++ b/Java/zad1_1/zad1_1.java @@ -0,0 +1,16 @@ +package POB_2019.Java.zad1_1; + +import java.util.ArrayList; +import java.util.List; + +public class zad1_1 { + public static void main(String[] args) { + List subjects = new ArrayList(); + subjects.add(new Przedmiot("Ball")); + subjects.add(new Przedmiot("Chair")); + subjects.add(new Przedmiot("Table")); + for(Przedmiot p : subjects){ + System.out.println(p); + } + } +} diff --git a/Java/zad1_2/Vector2D.java b/Java/zad1_2/Vector2D.java new file mode 100644 index 0000000..977be72 --- /dev/null +++ b/Java/zad1_2/Vector2D.java @@ -0,0 +1,27 @@ +package POB_2019.Java.zad1_2; + +public class Vector2D { + private int x, y; + public Vector2D(int _x, int _y){ + this.x=_x; + this.y=_y; + } + public Vector2D add(Vector2D vec2){ + int newX, newY; + newX=this.x + vec2.x; + newY=this.y + vec2.y; + return new Vector2D(newX, newY); + } + public Vector2D substract(Vector2D vec2){ + int newX, newY; + newX=this.x - vec2.x; + newY=this.y - vec2.y; + return new Vector2D(newX, newY); + } + public double multiply(Vector2D vec2){ + return (this.x*vec2.x + this.y*vec2.y); + } + public String toString(){ + return String.format("[%s, %s]", this.x, this.y); + } +} \ No newline at end of file diff --git a/Java/zad1_2/zad1_2.java b/Java/zad1_2/zad1_2.java new file mode 100644 index 0000000..ce13f3e --- /dev/null +++ b/Java/zad1_2/zad1_2.java @@ -0,0 +1,14 @@ +package POB_2019.Java.zad1_2; + +public class zad1_2 { + public static void main(String[] args){ + Vector2D vec1 = new Vector2D(5, 11); + Vector2D vec2 = new Vector2D(-2, 4); + Vector2D vec3 = vec1.add(vec2); + Vector2D vec4 = vec2.substract(vec1); + double multiplicationResult = vec2.multiply(vec1); + System.out.println(vec3); + System.out.println(vec4); + System.out.println(multiplicationResult); + } +} \ No newline at end of file diff --git a/zad6_1.cpp b/zad6_1.cpp new file mode 100644 index 0000000..9ca73d3 --- /dev/null +++ b/zad6_1.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +using namespace std; +using namespace cv; + +class Shape +{ +public: + virtual void draw(Mat &img) = 0; +}; + +class Circle : public Shape +{ +public: + Circle(int x, int y, int r) + : _x(x), _y(y), _r(r) {} + + virtual void draw(Mat &img) { + circle(img, Point(_x, _y), _r, Scalar(0,0,0)); + } + +private: + int _x, _y, _r; +}; + +class Rectangle : public Shape +{ +public: + Rectangle(int x, int y, int w, int h) + : _x(x), _y(y), _w(w), _h(h) {} + + virtual void draw(Mat &img) { + rectangle(img, Point(_x, _y), + Point(_x+_w, _y+_h), Scalar(0,0,0)); + } + +private: + int _x, _y, _w, _h; +}; + +int main() +{ + const char wnd[] = "test"; + namedWindow(wnd, WINDOW_AUTOSIZE); + int width = 1000, height = 800; + + vector shapes { + new Circle(300, 200, 100), + new Rectangle(500, 200, 300, 100), + new Circle(500, 600, 100), + new Rectangle(100, 400, 100, 150) + }; + + Mat img = Mat::zeros(height, width, CV_8UC3); + + while (true) + { + img = Scalar(255,255,255); + for (Shape* shape : shapes) { + shape->draw(img); + } + imshow(wnd, img); + int key = waitKey(40); + if ((key & 255) == 27) break; + } + + for (Shape* shape : shapes) delete shape; + shapes.clear(); + + + return 0; +} \ No newline at end of file diff --git a/zad6_2.py b/zad6_2.py new file mode 100644 index 0000000..a328162 --- /dev/null +++ b/zad6_2.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +from turtle import * + +class Shape(): + def __init__(self): + pass + def draw(self): + pass + +class Circle(Shape): + def __init__(self, _posX, _posY, _size): + self.posX=_posX + self.posY=_posY + self.size=_size + def draw(self): + goto(self.posX, self.posY) + pendown() + circle(self.size) + penup() + +class Rect(Shape): + def __init__(self, _posX, _posY, _sizeX, _sizeY): + self.posX=_posX + self.posY=_posY + self.sizeX=_sizeX + self.sizeY=_sizeY + def draw(self): + goto(self.posX, self.posY) + pendown() + for i in range(2): + forward(self.sizeX) + right(90) + forward(self.sizeY) + right(90) + penup() +penup() +shapes=[Circle(-200,100,100), + Rect(100,100,200,100)] +for shape in shapes: + shape.draw() \ No newline at end of file