ValueClass Instance Static

ValueClass-InstanceStatic

Instance member field: int value

Static member field: static int count

public class ValueClass {
    private int value = 0; // instance field
    private static int count = 0; // static field
    static Scanner input = new Scanner(System.in); // static field

    public ValueClass() { 
	this(0); 
    }

    public ValueClass(int value) { 
        this.value = value;
        count++;
    }

    public void setValue(int value) { // instance method
        this.value = value; 
    }

    public int getValue() { // instance method
        return this.value; 
    }

    public void print() { // instance method
        System.out.println("value=" + this.value + " # of value=" + count);
    }

    public static int getCount() { // static method
        return count;
    }

    public static void printString(String str) { // static method
        System.out.print(str);
    }

    public static int getUserInputInt() { // static method
        int value = input.nextInt();
        return value;
    }

    public static void main(String[] args) {
        ValueClass v = new ValueClass();
        v.print();
        v.setValue(2000);
        int value = v.getValue();
        v.print();

        ValueClass.printString("Please enter the integer value: ");		
        int val = ValueClass.getUserInputInt();
        v.setValue(val);
        v.print();

        ValueClass v2 = new ValueClass(300);
        v2.print();

        ValueClass[] vArray = new ValueClass[3];
        for (int i=0; i<3; i++) {
            ValueClass v3 = new ValueClass();
            ValueClass.printString("Please enter the integer value: ");
            v3.setValue(ValueClass.getUserInputInt());
            vArray[i] = v3;
        }
    }
}