Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions hw5.staticvariable
Original file line number Diff line number Diff line change
@@ -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<Rectangle> instances = new ArrayList<Rectangle>();

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<Rectangle> 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;
}
}}}}}}