Skip navigation links

Package acm.program

This package provides a set of classes that simplify the creation of programs.

See: Description

Package acm.program Description

This package provides a set of classes that simplify the creation of programs. The package includes five abstract classes, each of which uses a particular paradigm for input and output, as follows:

The principal advantages of using the Program class are:

In most environments, the only thing students need to do to create a new program is to define a Program subclass that implements a run method. For example, the following class definition creates a traditional, stream-oriented program that reads in two integers and computes their sum:


 public class Add2 extends ConsoleProgram {
    public void run() {
       println("This program adds two numbers.");
       int n1 = readInt("Enter n1: ");
       int n2 = readInt("Enter n2: ");
       int total = n1 + n2;
       println("The total is " + total + ".");
    }
 }
 
Skip navigation links