edu.colorado.io
Class FormatWriter

java.lang.Object
  extended by edu.colorado.io.FormatWriter

public class FormatWriter
extends java.lang.Object

The FormatWriter class has a collection of static methods for writing formatted output to System.out.

Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/io/FormatWriter.java

See Also:
EasyReader

Constructor Summary
FormatWriter()
           
 
Method Summary
static void main(java.lang.String[] args)
          A demonstration program.
static void pause(long milliseconds)
          Make the computation pause for a specified number of milliseconds.
static void printLeft(java.lang.Object output, int minimumWidth)
          Print an Object (such as a String) to System.out, using left justification.
static void printNumber(double d, int minimumWidth, int fractionDigits)
          Print a number to System.out, using a specified format.
static void printRight(java.lang.Object output, int minimumWidth)
          Print an Object (such as a String) to System.out, using right justification.
static void printWhole(long n, int minimumWidth)
          Print a whole number to System.out, using a specified format.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatWriter

public FormatWriter()
Method Detail

pause

public static void pause(long milliseconds)
Make the computation pause for a specified number of milliseconds.

Parameters:
milliseconds - the number of milliseconds to pause
Postcondition:
The computation has paused for the specified time.

printNumber

public static void printNumber(double d,
                               int minimumWidth,
                               int fractionDigits)
Print a number to System.out, using a specified format.

Parameters:
d - the number to be printed
minimumWidth - the minimum number of characters in the entire output
fractionDigits - the number of digits to print on the right side of the decimal point
Precondition:
fractionDigits is not negative.
Postcondition:
The number d has been printed to System.out. This printed number is rounded to the specified number of digits on the right of the decimal. If fractionDigits is 0, then only the integer part of d is printed. If necessary, spaces appear at the front of the number to raise the total number of printed characters to the minimum. Additional formatting details are obtained from the current locale. For example, in the United States, a period is used for the decimal and commas are used to separate groups of integer digits.
Throws:
IllegalArgumentException - Indicates that fractionDigits is negative.
Example:
printNumber(12345.27, 8, 1);
Prints 12,345.3 in the U.S.

printLeft

public static void printLeft(java.lang.Object output,
                             int minimumWidth)
Print an Object (such as a String) to System.out, using left justification.

Parameters:
output - the Object to be printed
minimumWidth - the minimum number of characters in the entire output
Postcondition:
The Object has been printed to System.out. If necessary, spaces appear at the front of the Object to raise the total number of printed characters to the minimum.
Example:
printNumber("Foo", 8);
Prints "Foo " (with 5 spaces).

printRight

public static void printRight(java.lang.Object output,
                              int minimumWidth)
Print an Object (such as a String) to System.out, using right justification.

Parameters:
output - the Object to be printed
minimumWidth - the minimum number of characters in the entire output
Postcondition:
The Object has been printed to System.out. If necessary, spaces appear at the front of the Object to raise the total number of printed characters to the minimum.
Example:
printNumber("Foo", 8);
Prints " Foo" (with 5 spaces).

printWhole

public static void printWhole(long n,
                              int minimumWidth)
Print a whole number to System.out, using a specified format.

Parameters:
d - the number to be printed
minimumWidth - the minimum number of characters in the entire output
Postcondition:
The number n has been printed to System.out. If necessary, spaces appear at the front of the number to raise the total number of printed characters to the minimum. Additional formatting details are obtained from the current locale. For example, in the United States commas are used to separate groups of integer digits.
Example:
printNumber(12345, 8);
Prints " 12,345" in the U.S. (with 2 spaces in front)

main

public static void main(java.lang.String[] args)
A demonstration program. To run the demonstration:
java edu.colorado.io.FormatWriter