Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package proj20012023;
- public class Triangle {
- // attributes
- private double a, b, c;
- // ctor
- public Triangle() {
- this.a = 1;
- this.b = 1;
- this.c = 1;
- }
- public Triangle(double a, double b, double c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- public Triangle(double x) {
- this.a = x;
- this.b = x;
- this.c = x;
- }
- // getters
- public double getA() {
- return a;
- }
- public double getB() {
- return b;
- }
- public double getC() {
- return c;
- }
- public double getPerimeter() {
- return a + b + c;
- }
- // setters
- public void setA(double a) {
- if (a > 0)
- this.a = a;
- }
- public void setB(double b) {
- if (b > 0)
- this.b = b;
- }
- public void setC(double c) {
- if (c > 0)
- this.c = c;
- }
- @Override
- public String toString() {
- return "Triangle [a=" + a + ", b=" + b + ", c=" + c + ", p=" + getPerimeter() + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement