From 44f59b68cbeefe2d661539a001078c24986c09c3 Mon Sep 17 00:00:00 2001 From: Mantazul Chowdhury <42322886+Mantazul@users.noreply.github.com> Date: Wed, 5 Sep 2018 09:13:27 +0600 Subject: [PATCH] hw5.staticvariable Added draft practice static variable following hw5. --- hw5.staticvariable | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 hw5.staticvariable 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; + } + }}}}}} +