added java
This commit is contained in:
parent
45fd3d0f65
commit
14a1b7186c
11
Java/zad1_1/Przedmiot.java
Normal file
11
Java/zad1_1/Przedmiot.java
Normal file
@ -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";
|
||||
}
|
||||
}
|
16
Java/zad1_1/zad1_1.java
Normal file
16
Java/zad1_1/zad1_1.java
Normal file
@ -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<Przedmiot> subjects = new ArrayList<Przedmiot>();
|
||||
subjects.add(new Przedmiot("Ball"));
|
||||
subjects.add(new Przedmiot("Chair"));
|
||||
subjects.add(new Przedmiot("Table"));
|
||||
for(Przedmiot p : subjects){
|
||||
System.out.println(p);
|
||||
}
|
||||
}
|
||||
}
|
27
Java/zad1_2/Vector2D.java
Normal file
27
Java/zad1_2/Vector2D.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
14
Java/zad1_2/zad1_2.java
Normal file
14
Java/zad1_2/zad1_2.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
73
zad6_1.cpp
Normal file
73
zad6_1.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <opencv2/opencv.hpp>
|
||||
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<Shape*> 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;
|
||||
}
|
40
zad6_2.py
Normal file
40
zad6_2.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user