import java.io.*; import java.util.*; class Counter { // instance variable public int count; // instance methods public void press() { count++;} public int look() {return count;} // other stuff --- not associated with class instances public static void main(String args[]) { Counter x = new Counter(); x.count = 0; System.out.println("Say hello a few times and then say goodbye."); try { Scanner s = new Scanner(System.in); while (true) { String st = s.next(); if (st.equalsIgnoreCase("Goodbye")) { System.out.println("You said hello " + x.look() + " times. "); throw new Exception(); } if (st.equalsIgnoreCase("Hello")) x.press(); } } catch (Exception e) {} } }