Skip to content

Commit

Permalink
Homework1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hnoianko committed Nov 19, 2017
1 parent c5d6ab4 commit 0df2b36
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Homework1.2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Homework1.2.iml
.idea/
out/
15 changes: 15 additions & 0 deletions Homework1.2/src/com/gmail/gnoianko/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gmail.gnoianko;

public class Main {
public static void main(String[] args) {
Triangle trOne = new Triangle(3.5, 5.4, 6.0);
System.out.println(trOne);
trOne.square();

System.out.println();

Triangle trTwo = new Triangle(10, 5.4, 1.0);
System.out.println(trOne);
trTwo.square();
}
}
55 changes: 55 additions & 0 deletions Homework1.2/src/com/gmail/gnoianko/Triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.gmail.gnoianko;

public class Triangle {
private double sideOne;
private double sideTwo;
private double sideThree;

public Triangle(double sideOne, double sideTwo, double sideThree) {
this.sideOne = sideOne;
this.sideTwo = sideTwo;
this.sideThree = sideThree;
}

public double getSideOne() {
return sideOne;
}

public void setSideOne(double sideOne) {
this.sideOne = sideOne;
}

public double getSideTwo() {
return sideTwo;
}

public void setSideTwo(double sideTwo) {
this.sideTwo = sideTwo;
}

public double getSideThree() {
return sideThree;
}

public void setSideThree(double sideThree) {
this.sideThree = sideThree;
}

public void square() {
double p = (sideOne + sideTwo + sideThree) / 2;
if (sideOne > sideTwo + sideThree || sideTwo > sideThree + sideOne || sideThree > sideTwo + sideOne) {
System.out.println("Incorrect input");
} else {
System.out.println("Square = " + Math.sqrt(p * (p - sideOne) * (p - sideTwo) * (p - sideThree)));
}
}

@Override
public String toString() {
return "Triangle{" +
"sideOne=" + sideOne +
", sideTwo=" + sideTwo +
", sideThree=" + sideThree +
'}';
}
}

0 comments on commit 0df2b36

Please sign in to comment.