diff --git a/hw5.staticvariable b/hw5.staticvariable new file mode 100644 index 0000000..56745d2 --- /dev/null +++ b/hw5.staticvariable @@ -0,0 +1,57 @@ +package StaticVarMethod; + +import java.util.List; +import java.util.ArrayList; + +public class Rectangle { + public static void main(String[] args) { + } + public int mLength; + public int mWidth; + public static List instances = new ArrayList(); + + public Rectangle(int length, int width) { + mLength = length; + mWidth = width; + instances.add(this); + } + public int getmLength() { + return mLength; + } + public int getmWidth() { + return mWidth; + } + public boolean isSquare() { + return mLength == mWidth; + } + public int area() { + return mLength * mWidth; + } + public static List all() { + return instances; + } + static class Square { //nested class + int length = 15; + int width = 15; + int getTotalSize() { + return length * width; + } + public static void main(String[] args) { + Rectangle rc = new Rectangle(15, 15); + System.out.println("Rectangle : " + rc.isSquare()); + } + static class Loop { //loop + public static void main(String[] args) { + for (int length = 1; length <= 10; ++length) { + System.out.println("Line " + length); + for (int width =1; width<=10; ++width); + } + class WhileLoop { + public void main(String[] args) { + int length = 1; + while (length <= 10) { + System.out.println("Line " + length); + ++length; + } + }}}}}} +