-
-
Save GlebGomenyuk/156768ca5cf864cba02e1f48503e4802 to your computer and use it in GitHub Desktop.
HW1_2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com; | |
public class Main { | |
public static void main(String[] args) { | |
Triangle first = new Triangle(); | |
first.setSizeA(12); | |
first.setSizeB(14); | |
first.setSizeC(8); | |
first.triangleTrueOrFalse(); | |
Triangle second = new Triangle(); | |
second.setSizeA(1200); | |
second.setSizeB(14); | |
second.setSizeC(8); | |
second.triangleTrueOrFalse(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com; | |
public class Triangle { | |
private int sizeA; | |
private int sizeB; | |
private int sizeC; | |
public int getSizeA() { | |
return sizeA; | |
} | |
public void setSizeA(int sizeA) { | |
this.sizeA = sizeA; | |
} | |
public int getSizeB() { | |
return sizeB; | |
} | |
public void setSizeB(int sizeB) { | |
this.sizeB = sizeB; | |
} | |
public int getSizeC() { | |
return sizeC; | |
} | |
public void setSizeC(int sizeC) { | |
this.sizeC = sizeC; | |
} | |
public void triangleTrueOrFalse() { | |
if((sizeA+sizeB>sizeC)&&(sizeA+sizeC>sizeB)&&(sizeB+sizeC>sizeA)) { | |
System.out.printf("Треугольник с сторонами %1$s, %2$s, %3$s \n", sizeA,sizeB,sizeC); | |
square(); | |
} | |
else { | |
System.out.printf("Треугольник с сторонами %1$s, %2$s, %3$s не существует \n", sizeA,sizeB,sizeC ); | |
} | |
} | |
public void square() { | |
int halfPerimeter = (sizeA + sizeB + sizeC) / 2; | |
double squareTriangle = Math.sqrt(halfPerimeter * (halfPerimeter - sizeA) * (halfPerimeter - sizeB) * (halfPerimeter - sizeC)); | |
System.out.printf("Площадь треугольника %.4f \n", squareTriangle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment