From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- Java/Square/Square.java | 43 +++++++++++++++++++++++++++++++++++++++++++ Java/Square/SquareDemo.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Java/Square/Square.java create mode 100644 Java/Square/SquareDemo.java (limited to 'Java/Square') diff --git a/Java/Square/Square.java b/Java/Square/Square.java new file mode 100644 index 0000000..4ea72e9 --- /dev/null +++ b/Java/Square/Square.java @@ -0,0 +1,43 @@ +public class Square { + + // data member + private double length; + + + + // Constructors + //accepts r as length + public Square (double l) { + length = l; + } +//no r? assume length is 1 + public Square() { + length = 1; + } +//copy's length from another circle + public Square (Square s) { + length = s.length; + } + + // setter & getter + // sets length + public void setLength(double l) { + length = l; + } +//return length + public double getLength() { + return length; + } + + // other methods + public double area() { + return Math.pow(length,2); + } + + public double perimeter() { + return length*4; + } + +} + + diff --git a/Java/Square/SquareDemo.java b/Java/Square/SquareDemo.java new file mode 100644 index 0000000..ab6f0dc --- /dev/null +++ b/Java/Square/SquareDemo.java @@ -0,0 +1,28 @@ +public class SquareDemo { + + public static void main (String args []) { + + double leng = 2.5; + double value; + + // create a circle object called mySquare with a lengius of 2.5 + Square mySquare = new Square(leng); + + // create a circle object called myOtherSquare with a lengius of 10.0 + Square myOtherSquare = new Square(10); + + // create a circle object called unitSquare with a default lengius of 1.0; + Square unitSquare = new Square(); + + // create a circle object called myLastSquare that is a copy of the Square mySquare + Square myLastSquare = new Square(mySquare); + + // get the area of mySquare + value = mySquare.area(); + + // print the area of mySquare + System.out.println("The area is " + value); + + } +} + -- cgit v1.2.3