• Марта 20, 2019, 01:49:54 pm
• Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Не получили письмо с кодом активации?
Новости: 14 марта бесплатный вебинар по выбору IT профессии: http://bit.ly/2IVhqxJ

Последние сообщения

Страницы: [1] 2 3 ... 10
1
Java SE / Re: Java_OOP_Alexander_Beresteyka_13_03_2019
« Последний ответ от dm.krava.t Сегодня в 11:49:30 am »
дз №2(задание в main закоментировано)
https://github.com/dimitrykrava0912/dz2.git
2
Java SE / Re: Java OOP Online-Vadim
« Последний ответ от wodan Сегодня в 10:54:52 am »
3
Java SE / Re: Java_OOP_Alexander_Beresteyka_13_03_2019
« Последний ответ от Serhii Nahorniy Сегодня в 05:42:07 am »
В минулій відповіді забув видалити наслідування класу Deck від shapes, a також абстрактні методи класу shapes
І питання клас deck  проявляє залежність щодо класів фігур чи це щось інше?
https://www.draw.io/?lightbox=1&highlight=0000ff&edit=_blank&layers=1&nav=1&title=Untitled%20Diagram.drawio#R7Zndb5swEMD%2FGqTuYVWwQ0Iem6RdVW1StE7b%2BuiAA14JRsb56l8%2Fg803aQhpEyq1Dyk%2B353tu5%2BNbTQ4WW6%2FMRS4P6iNPQ307K0GpxoAZr8nfiPBTgr60JAChxFbivRM8EhesBIqO2dFbBwWFDmlHidBUWhR38cWL8gQY3RTVFtQr9hqgBxcETxayKtK%2FxCbu0qqD0ZZxT0mjquaNsFAVsyR9ewwuvJVexqAi%2FhPVi9R4ksNNHSRTTc5EbzV4IRRyuXTcjvBXhTaJGzS7m5Pbdpvhn3exGC6md0%2FPAWbl3vzwf4%2BtH7Df%2FxrX7lZI2%2BlAvLoogBrYOAJr%2BM5E09O9JRI3IrEJutEZNPVXARWZBXzGWZkiTm7%2BpLTFd3LqR%2FwcMMwetU6DivfJancuITjxwBZUXkjaI26y5eeKOniEYWBBGhBtthOHawx43i7N6h6mioxAzCNRrQTKsrAMBXtin6okr3JUAI9JXNzFKVCpPB1UtdZCsWDyuIxGQWVjE4Is7yTU8qQTVbhMbmcUSKiKKauCCZmbSyXiPiq90dYdxHV7gLcKwKs1xCs1xGsvxvBsELwL0aQ75zOcCjeNTfif%2BxVTMEWUIUB8mv9jvf5zVscD1fketKuy8ksEoDoLe3AqSHK%2BYJvEJbPqd18apsdnNpGZWr%2FFOMuzO0staVpm8V6Xq8yPqwyOawyrVXZM5dqFcAhBXhIoV%2Br0EX4L485GBidw3xQwbwSKezbN9HxRZTmHrWei4EStXckanTai0uiV3%2BjwrWRFJ9STVGYbvOa011S2hKeMxOlp1xNZhQVEpuQM%2FqcHoWA7Is6tul6mjJsV45VpYSJ0dIVs3CD5YAjJlg7eEypIpBLsVGT4UTGsIc4WRc7XJd11UIyExPChsWFdABL4MiBKqv8EazkCIKio3TzlTiSgag4iiFMh30Cl8NucHlWxsCHYAyWX9aDlowNRsXlEPTPzJjZDcY6v%2FbBj8HlqMTlsCWXw16JS%2BPMXI4qXE6xQK%2FBLkveiBljzZjKe7wAh%2BmJzMcb8Zuo9COdZnu3dJtF%2FAVlS5Ek6he2WpnxmoqhRalc0jWOm7qSsV0QZ0bDV42QbUsLda8n%2B6%2BBSdzyISdd2OCVryjS8uU2eAm7DRc5y0NhSKxiqKqLTXyZHEUtrrdR6KaFc66Cb7nIjZouckaXNnhm25dveYNnlgl850XOqF7nf3J5EpfgolyWVj6z7csXwpIjcGYuwQW5HOoFMq97ev8QnVFJXZ5EHy4%2BFrLwosiW9otm%2BYjbGNl%2ByVH50N0aWVHMvrpK9ezLNrz9Dw%3D%3D
4
Java SE / Re: Java_OOP_Alexander_Beresteyka_13_03_2019
« Последний ответ от Serhii Nahorniy Сегодня в 05:09:29 am »
Main
package com.gmail.sergiy3344;

public class Main {

public static void main(String[] args) {
// TODO Auto-generated method stub
Point point1 = new Point(0,0);
Point point2 = new Point(0,4);
Point point3 = new Point(3,0);
Point point4 = new Point(3,4);

      Circle corcle1 = new Circle(point1,point2);
      System.out.println(corcle1.getArea());
     
      Triangle tria1 = new Triangle(point1,point2,point3);
      System.out.println(tria1.getArea());
     
      Rectangle rec1= new Rectangle(point1,point2,point3,point4);
      System.out.println(rec1.getArea());
   
     
     
      Deck deck1 = new Deck();
      deck1.addShape(corcle1, 3);
      deck1.addShape(rec1, 1);
      deck1.addShape(tria1, 2);
     
      System.out.println(deck1.information());
      deck1.removeShape(3);
      System.out.println(deck1.information());
}

}
Shape
package com.gmail.sergiy3344;

public abstract class Shape {

abstract double getPerimetr();
abstract double getArea();
}
Point
package com.gmail.sergiy3344;

public class Point {
private double x;
private double y;
public Point(double x, double y) {
super();
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}




}
Circle
package com.gmail.sergiy3344;

public class Circle extends Shape {
private double radius = 0;
private Point center;
private Point mainCircle;

public Circle() {
}

public Circle(Point center, Point mainCircle) {
super();
this.center = center;
this.mainCircle = mainCircle;
radius = Math
.sqrt(Math.pow(center.getX() - mainCircle.getX(), 2) + Math.pow(center.getY() - mainCircle.getY(), 2));
}

double getPerimetr() {
double per = radius * Math.PI * 2;
return per;
};

double getArea() {
double area = Math.pow(radius, 2) * Math.PI;

return area;
};
}
Triangle
package com.gmail.sergiy3344;

public class Triangle extends Shape {
private double sideA = 0;
private double sideB = 0;
private double sideC = 0;
private Point ver1;
private Point ver2;
private Point ver3;

public Triangle() {
}

public Triangle(Point ver1, Point ver2,Point ver3) {
super();
this.ver1 = ver1;
this.ver2 = ver2;
this.ver3 = ver3;
sideA = Math
.sqrt(Math.pow(ver1.getX() - ver2.getX(), 2) + Math.pow(ver1.getY() - ver2.getY(), 2));
sideB = Math
.sqrt(Math.pow(ver2.getX() - ver3.getX(), 2) + Math.pow(ver2.getY() - ver3.getY(), 2));
sideC = Math
.sqrt(Math.pow(ver3.getX() - ver1.getX(), 2) + Math.pow(ver3.getY() - ver1.getY(), 2));
}


double getPerimetr() {
double per = sideA+sideB+sideC;
return per;
};

double getArea() {
double pp =(sideA+sideB+sideC)/2;
double area = Math.sqrt(pp*(pp-sideA)*(pp-sideB)*(pp-sideC));
return area;
};
}
Rectangle
package com.gmail.sergiy3344;

public class Rectangle extends Shape {
private double sideA = 0;
private double sideB = 0;
private double sideC = 0;
private double sideD = 0;
private Point ver1;
private Point ver2;
private Point ver3;
private Point ver4;

public Rectangle() {
}

public Rectangle(Point ver1, Point ver2,Point ver3,Point ver4) {
super();
if(ver4.getX()==ver3.getX()&&ver4.getY()==ver2.getY()&&ver2.getX()==ver1.getX()) {
this.ver1 = ver1;
this.ver2 = ver2;
this.ver3 = ver3;
sideA = Math
.sqrt(Math.pow(ver1.getX() - ver2.getX(), 2) + Math.pow(ver1.getY() - ver2.getY(), 2));
sideB = Math
.sqrt(Math.pow(ver2.getX() - ver4.getX(), 2) + Math.pow(ver2.getY() - ver4.getY(), 2));
sideC = Math
.sqrt(Math.pow(ver4.getX() - ver3.getX(), 2) + Math.pow(ver4.getY() - ver3.getY(), 2));
sideC = Math
.sqrt(Math.pow(ver3.getX() - ver1.getX(), 2) + Math.pow(ver3.getY() - ver1.getY(), 2));
}
else
System.out.println("it is not rectangle");
}


double getPerimetr() {
double per = 2*(sideA+sideB);
return per;
};

double getArea() {

double area = sideA*sideB;
return area;
};
}
Deck
package com.gmail.sergiy3344;

public class Deck extends Shape {
private Shape[] shapes = new Shape[4];

public Deck() {
super();
}

public void addShape(Shape shape, int figPos) {
this.shapes[figPos - 1] = shape;

}

public void removeShape(int figPos) {
this.shapes[figPos - 1] = null;

}

public double information() {
double area = 0;
for (int i = 0; i < shapes.length; i++) {

if (shapes[i] != null) {
if (shapes[i] instanceof Circle) {
area += shapes[i].getArea();
System.out.println("circle in "+ (i+1)+" position");
}

if (shapes[i] instanceof Triangle) {
area += shapes[i].getArea();
System.out.println("triangle in "+ (i+1)+" position");
}

if (shapes[i] instanceof Rectangle) {
area += shapes[i].getArea();
System.out.println("rectangle in "+ (i+1)+" position");
}

}
}
return area;
}

public double getPerimetr() {
double per = 0;

return per;
};

public double getArea() {
double area = 0;

return area;
};

}
5
Java SE / Re: Java_OOP_Alexander_Beresteyka_13_03_2019
« Последний ответ от Aldebaran Сегодня в 01:33:03 am »
package com.gmail.mikaxxx;

public abstract class Shape {
abstract public double getPerimetr();
abstract public double getArea();
abstract public String toString();
}

public class Point {
private int x;
private int y;
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
public Point() {
super();
// TODO Auto-generated constructor stub
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public String toString() {
return "Point [x=" + x + ", y=" + y + "]";
}

}

public class Triangle extends Shape {
private Point a;
private Point b;
private Point c;

public Triangle(Point a, Point b, Point c) {
super();
this.a = a;
this.b = b;
this.c = c;
}

public Triangle() {
super();
// TODO Auto-generated constructor stub
}

public Point getA() {
return a;
}

public void setA(Point a) {
this.a = a;
}

public Point getB() {
return b;
}

public void setB(Point b) {
this.b = b;
}

public Point getC() {
return c;
}

public void setC(Point c) {
this.c = c;
}

public double calculateSizeAB() {
double size = Math
.sqrt((b.getX() - a.getX()) * (b.getX() - a.getX()) + (b.getY() - a.getY()) * (b.getY() - a.getY()));
return size;
}

public double calculateSizeBC() {
double size = Math
.sqrt((c.getX() - b.getX()) * (c.getX() - b.getX()) + (c.getY() - b.getY()) * (c.getY() - b.getY()));
return size;
}

public double calculateSizeAC() {
double size = Math
.sqrt((c.getX() - a.getX()) * (c.getX() - a.getX()) + (c.getY() - a.getY()) * (c.getY() - a.getY()));
return size;
}

public double getPerimetr() {
return calculateSizeAB() + calculateSizeAC() + calculateSizeBC();
}

public double getArea() {
double area;
double p = (calculateSizeAB() + calculateSizeAC() + calculateSizeBC()) / 2;

area = Math.sqrt(p * (p - calculateSizeAB()) * (p - calculateSizeAC()) * (p - calculateSizeBC()));
return area;
}

@Override
public String toString() {
return "Triangle [a=" + a + ", b=" + b + ", c=" + c + ", calculateSizeAB()=" + calculateSizeAB()
+ ", calculateSizeBC()=" + calculateSizeBC() + ", calculateSizeAC()=" + calculateSizeAC()
+ ", getPerimetr()=" + getPerimetr() + ", getArea()=" + getArea() + "]";
}


}

public class Square extends Shape {
private Point a;
private Point b;
private Point c;
private Point d;

public Square(Point a, Point b, Point c, Point d) {
super();
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}

public Square() {
super();
// TODO Auto-generated constructor stub
}

public Point getA() {
return a;
}

public void setA(Point a) {
this.a = a;
}

public Point getB() {
return b;
}

public void setB(Point b) {
this.b = b;
}

public Point getC() {
return c;
}

public void setC(Point c) {
this.c = c;
}

public Point getD() {
return d;
}

public void setD(Point d) {
this.d = d;
}

public double calculateSizeAB() {
double size = Math
.sqrt((b.getX() - a.getX()) * (b.getX() - a.getX()) + (b.getY() - a.getY()) * (b.getY() - a.getY()));
return size;
}

public double calculateSizeBC() {
double size = Math
.sqrt((c.getX() - b.getX()) * (c.getX() - b.getX()) + (c.getY() - b.getY()) * (c.getY() - b.getY()));
return size;
}

public double calculateSizeCD() {
double size = Math.sqrt((d.getX()-c.getX())*(d.getX()-c.getX()) + (d.getY()-c.getY())*(d.getY()-c.getY()));
return size;

}

public double calculateSizeDA() {
double size = Math
.sqrt((a.getX() - d.getX()) * (a.getX() - d.getX()) + (a.getY() - d.getY()) * (a.getY() - d.getY()));
return size;
}

public double getPerimetr() {
return calculateSizeAB() + calculateSizeBC() + calculateSizeCD() + calculateSizeDA();
}
public double getArea() {
return calculateSizeAB()*calculateSizeBC();
}

@Override
public String toString() {
return "Square [a=" + a + ", b=" + b + ", c=" + c + ", d=" + d + ", calculateSizeAB()=" + calculateSizeAB()
+ ", calculateSizeBC()=" + calculateSizeBC() + ", calculateSizeCD()=" + calculateSizeCD()
+ ", calculateSizeDA()=" + calculateSizeDA() + ", getPerimetr()=" + getPerimetr() + ", getArea()="
+ getArea() + "]";
}


}

public class Circle extends Shape {
private Point center;
private Point radius;

public Circle(Point center, Point radius) {
super();
this.center = center;
this.radius = radius;
}

public Circle() {
super();
// TODO Auto-generated constructor stub
}

public Point getCenter() {
return center;
}

public void setCenter(Point center) {
this.center = center;
}

public Point getRadius() {
return radius;
}

public void setRadius(Point radius) {
this.radius = radius;
}

public double calculateRadius() {
double r = Math.sqrt((radius.getX() - center.getX()) * (radius.getX() - center.getX())
+ (radius.getY() - center.getY()) * (radius.getY() - center.getY()));
return r;
}

public double getPerimetr() {
return 2*calculateRadius()*Math.PI;
}
public double getArea() {
return Math.PI*calculateRadius()*calculateRadius();
}

@Override
public String toString() {
return "Circle [center=" + center + ", radius=" + radius + ", calculateRadius()=" + calculateRadius()
+ ", getPerimetr()=" + getPerimetr() + ", getArea()=" + getArea() + "]";
}



}

public class Desk {
private Shape[] desk = new Shape[4];
private int currentNum;

public Desk(Shape[] desk) {
super();
this.desk = desk;
this.currentNum = 0;
}

public Desk(Shape one, Shape two, Shape three, Shape four) {
super();
this.desk[0] = one;
this.desk[1] = two;
this.desk[2] = three;
this.desk[3] = four;
this.currentNum = 0;
}

public Desk() {
super();
this.currentNum = 0;
// TODO Auto-generated constructor stub
}

public void setCurrentNum(int num) {
if (num < 4 || num >= 0) {
this.currentNum = num;
} else {
this.currentNum = 0;
}

}

public int getCurrentNum() {
return currentNum;
}

public void setFigure(Shape figure) {
desk[currentNum] = figure;
if (currentNum < 3) {
currentNum++;
} else {
currentNum = 0;
}
}

public void deleteFigure() {
if (currentNum == 0) {
currentNum = 3;
} else {
currentNum--;
}
desk[currentNum] = null;
}

public double allArea() {
double area = 0;
for (int i = 0; i < 4; i++) {
if (desk[i] != null) {
area += desk[i].getArea();
}
}
return area;
}

@Override
public String toString() {
return "Part one: " + desk[0] + "\n" + "Part two: " + desk[0] + "\n" + "Part three: " + desk[2] + "\n"
+ "Part four: " + desk[3] + "\n" + "Area of figure on desk = " + allArea();
}

}

public class Main {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader = new Scanner(System.in);
Point one = new Point(4, 6);
Point two = new Point(0, 0);
Point three = new Point(0, 6);
Point four = new Point(4, 0);
Triangle a = new Triangle(one, two, three);
Circle b = new Circle(two, one);
Square c = new Square(two, three, one, four);

Desk newDesk = new Desk();
System.out.println(newDesk.getCurrentNum());

newDesk.setFigure(a);
System.out.println(newDesk.getCurrentNum());
newDesk.setFigure(b);
System.out.println(newDesk.getCurrentNum());

newDesk.setFigure(c);
System.out.println(newDesk.getCurrentNum());

System.out.println(newDesk);
//newDesk.deleteFigure();


}


}

Криво рабоает клас Доска, не могу понять почему. Можете указать где примерно искать ошибку?
6
Java SE / Re: Java_Start_Alexander_School_07_03_2019
« Последний ответ от Alexander Ts Сегодня в 12:40:58 am »
Ivan_96
Решение верное

Аlexey.a
Решение верное.
7
Java SE / Re: Java_OOP_Alexander_Pancovskogo_13_02_2019
« Последний ответ от Alexander Ts Сегодня в 12:39:02 am »
SashaUsov
Решение верное

Vlad_Mayko
Решение верное
8
Java SE / Re: Java OOP online homeworks- ILLIA ZYBIN
« Последний ответ от Alexander Ts Сегодня в 12:37:14 am »
Ilia009

Решение верное
9
Java SE / Re: Java OOP Online-Vadim
« Последний ответ от Alexander Ts Сегодня в 12:01:42 am »
Wodan

А в интерфейсе Future есть метод get - так вот этот метод вернет управлнеи только тогда когда поток завершиться.
10
Java SE / Re: Java OOP. Богдан. Группа 2019-2. Лекции 1-2 (16.03.2019)
« Последний ответ от Alexander Ts Марта 19, 2019, 11:51:58 pm »
Vova13

Решение верное
Страницы: [1] 2 3 ... 10