Skip to content

Commit d7fe187

Browse files
committed
lab 5-6
1 parent 84e10f1 commit d7fe187

14 files changed

+388
-41
lines changed

src/ru/shureck/java2020/Kvort/Main.java

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ru.shureck.java2020.Lab5;
2+
3+
public class Circle extends Shape{
4+
5+
private double radius;
6+
7+
public Circle() {
8+
}
9+
10+
public Circle(double radius) {
11+
this.radius = radius;
12+
}
13+
14+
public Circle(String color, boolean filled, double radius) {
15+
super(color, filled);
16+
this.radius = radius;
17+
}
18+
19+
public double getRadius() {
20+
return radius;
21+
}
22+
23+
public void setRadius(double radius) {
24+
this.radius = radius;
25+
}
26+
27+
@Override
28+
public double getArea() {
29+
return Math.PI*radius*radius;
30+
}
31+
32+
@Override
33+
public double getPerimetr() {
34+
return 2*Math.PI*radius;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "Circle{" +
40+
"radius=" + radius +
41+
'}';
42+
}
43+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package ru.shureck.java2020.Lab5;
2+
3+
public class Lab5 {
4+
5+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ru.shureck.java2020.Lab5;
2+
3+
public class Rectangle extends Shape{
4+
private double width;
5+
private double height;
6+
7+
public Rectangle() {
8+
}
9+
10+
public Rectangle(String color, boolean filled, double width, double height) {
11+
super(color, filled);
12+
this.width = width;
13+
this.height = height;
14+
}
15+
16+
public Rectangle(double width, double height) {
17+
this.width = width;
18+
this.height = height;
19+
}
20+
21+
public double getWidth() {
22+
return width;
23+
}
24+
25+
public void setWidth(double width) {
26+
this.width = width;
27+
}
28+
29+
public double getHeight() {
30+
return height;
31+
}
32+
33+
public void setHeight(double height) {
34+
this.height = height;
35+
}
36+
37+
@Override
38+
public double getArea() {
39+
return height*width;
40+
}
41+
42+
@Override
43+
public double getPerimetr() {
44+
return 2*(height+width);
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return "Rectangle{" +
50+
"color" + getColor() +
51+
"width=" + width +
52+
", height=" + height +
53+
'}';
54+
}
55+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.shureck.java2020.Lab5;
2+
3+
public abstract class Shape {
4+
private String color;
5+
private boolean filled;
6+
7+
public Shape(){
8+
9+
}
10+
11+
public Shape(String color, boolean filled) {
12+
this.color = color;
13+
this.filled = filled;
14+
}
15+
16+
public String getColor() {
17+
return color;
18+
}
19+
20+
public void setColor(String color) {
21+
this.color = color;
22+
}
23+
24+
public boolean isFilled() {
25+
return filled;
26+
}
27+
28+
public void setFilled(boolean filled) {
29+
this.filled = filled;
30+
}
31+
32+
public abstract double getArea();
33+
public abstract double getPerimetr();
34+
35+
@Override
36+
public String toString() {
37+
return "Shape{" +
38+
"color='" + color + '\'' +
39+
", filled=" + filled +
40+
'}';
41+
}
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ru.shureck.java2020.Lab5;
2+
3+
public class Square extends Rectangle{
4+
5+
public Square() {
6+
}
7+
8+
public Square(String color, boolean filled, double side) {
9+
super(color, filled, side, side);
10+
}
11+
12+
public Square(double side) {
13+
super(side, side);
14+
}
15+
16+
public double getSide(){
17+
return getHeight();
18+
}
19+
20+
@Override
21+
public void setHeight(double height) {
22+
super.setWidth(height);
23+
super.setHeight(height);
24+
}
25+
26+
@Override
27+
public void setWidth(double height) {
28+
super.setWidth(height);
29+
super.setHeight(height);
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return "Square{"+ super.toString() +"}";
35+
}
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.shureck.java2020.Lab5;
2+
3+
public class SquareTrue extends Shape{
4+
private double side;
5+
6+
public SquareTrue() {
7+
}
8+
9+
public SquareTrue(String color, boolean filled, double side) {
10+
super(color, filled);
11+
this.side = side;
12+
}
13+
14+
public SquareTrue(double width, double side) {
15+
this.side = side;
16+
}
17+
18+
public double getSide() {
19+
return side;
20+
}
21+
22+
public void setSide(double side) {
23+
this.side = side;
24+
}
25+
26+
@Override
27+
public double getArea() {
28+
return side*side;
29+
}
30+
31+
@Override
32+
public double getPerimetr() {
33+
return 4*side;
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return "Square_true{" +
39+
"side=" + side +
40+
'}';
41+
}
42+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.shureck.java2020.Lab6;
2+
3+
public class Lab6 {
4+
public static void main(String[] args) {
5+
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package ru.shureck.java2020.Lab6;
2+
3+
public interface Movable {
4+
void moveCenter(double right, double down);
5+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.shureck.java2020.Lab6;
2+
3+
public class MovableCircle implements Movable{
4+
private double radius;
5+
private double x,y;
6+
7+
public MovableCircle(double radius, double x, double y) {
8+
this.radius = radius;
9+
this.x = x;
10+
this.y = y;
11+
}
12+
13+
public double getRadius() {
14+
return radius;
15+
}
16+
17+
public void setRadius(double radius) {
18+
this.radius = radius;
19+
}
20+
21+
public double getX() {
22+
return x;
23+
}
24+
25+
public void setX(double x) {
26+
this.x = x;
27+
}
28+
29+
public double getY() {
30+
return y;
31+
}
32+
33+
public void setY(double y) {
34+
this.y = y;
35+
}
36+
37+
@Override
38+
public void moveCenter(double right, double down) {
39+
this.x += right;
40+
this.y += down;
41+
}
42+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.shureck.java2020.Lab6;
2+
3+
public class MovablePoint extends MovableCircle{
4+
public MovablePoint(double x, double y) {
5+
super(0, x, y);
6+
}
7+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ru.shureck.java2020.Lab6;
2+
3+
import ru.shureck.java2020.Lab5.Rectangle;
4+
import ru.shureck.java2020.Lab5.Shape;
5+
6+
public class MovableRectangle extends Rectangle implements Movable{
7+
8+
private double x;
9+
private double y;
10+
11+
public MovableRectangle(String color, boolean filled, double width, double height, double x, double y) {
12+
super(color, filled, width, height);
13+
this.x = x;
14+
this.y = y;
15+
}
16+
17+
public MovableRectangle(String color, boolean filled, double width, double height) {
18+
super(color, filled, width, height);
19+
this.x = width/2;
20+
this.y = height/2;
21+
}
22+
23+
public MovableRectangle(double width, double height) {
24+
super(width, height);
25+
this.x = width/2;
26+
this.y = height/2;
27+
}
28+
29+
@Override
30+
public void moveCenter(double right, double down) {
31+
this.x += right;
32+
this.y += down;
33+
}
34+
}

0 commit comments

Comments
 (0)