/*******************************************************************************
* Companion code for the book "Introduction to Software Design with Java",
* 2nd edition by Martin P. Robillard.
*
* Copyright (C) 2022 by Martin P. Robillard
*
* This code is licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* See http://creativecommons.org/licenses/by-nc-nd/4.0/
*
*******************************************************************************/
package e2.chapter8;
/**
* Sample observer of ObservableCardStack. Counts the number of
* cards pushed on a stack.
*/
public class Counter implements CardStackObserver {
private int aCount = 0;
@Override
public void pushed(Card pCard) {
aCount++;
System.out.println("PUSH Counter=" + aCount);
}
@Override
public void popped(Card pCard) {
aCount--;
System.out.println("POP Counter=" + aCount);
if (aCount == 0) {
System.out.println("Last card popped!");
}
}
@Override
public void cleared() {
aCount = 0;
System.out.println("CLEAR Counter=" + aCount);
}
}
print(String)
and then
println()
.print(String)
and then
println()
.x
- The String
to be printed.Console.charset()
if the Console
exists,
stdout.encoding otherwise.
Console.charset()
if the Console
exists,
stdout.encoding otherwise.
For simple stand-alone Java applications, a typical way to write a line of output data is:
System.out.println(data)
See the println
methods in class PrintStream
.
System
class contains several useful class fields
and methods. It cannot be instantiated.
Among the facilities provided by the System
class
are standard input, standard output, and error output streams;
access to externally defined properties and environment
variables; a means of loading files and libraries; and a utility
method for quickly copying a portion of an array.System
class contains several useful class fields
and methods. It cannot be instantiated.
Among the facilities provided by the System
class
are standard input, standard output, and error output streams;
access to externally defined properties and environment
variables; a means of loading files and libraries; and a utility
method for quickly copying a portion of an array.