forked from Hnoianko/prog.kiev.ua-JavaOOP-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Homework1.2.iml | ||
.idea/ | ||
out/ |
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
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(); | ||
} | ||
} |
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
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 + | ||
'}'; | ||
} | ||
} |