1

I just started taking the Stanford CS106a course on iTunes, but I'm running in to problems with Eclipse. Here's my code:

/*
 * File: Add2Integers.java
 * -----------------------
 * A simple ConsoleProgram to add two integers
 * and display their total.
 */

import acm.program.*;

public class Add2Integers extends ConsoleProgram {

public void run() {
    /* So all y'all in the back can see! */
    setFont("DejaVuSerif-BOLD-24");

    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 + ".");
}

}

When I try to run it, I get the message that the section does not contain an applet. I think it has to do with import acm.program.

I downloaded the acm toolkit and tried adding the program.java file to my root folder, building the path, doing the same for the entire acm folder, nothing works.

I just need help getting this simple program up and running so that I can start learning.

I'm running OSX 10.8.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Kris
  • 11
  • 1

4 Answers4

1

To run a Java application, you need a main method:

public static void main(String[] args) {
    Add2Integers add2Integers = new Add2Integers();
    add2Integers.run();
}
Alban Dericbourg
  • 1,616
  • 2
  • 16
  • 39
  • Nothing changes when I add this. I watched the professor run this same program without needing this extra code in Eclipse. Is it possible if you can give me step by step instructions of everything I need to do to get this running? – Kris Mar 15 '13 at 17:32
0

You need to start your ConsoleProgram from a main method:

public static void main(String[] args) {
   new Add2Integers().start(args);
}

See: Introduction to the JTF Packages

Reimeus
  • 158,255
  • 15
  • 216
  • 276
0

When I try to run, I get the message that the section does not contain an applet.

That's because it isn't an applet. It's an ordinary Java application.

The examples which do graphics, are applets. But this is text-only - it extends ConsoleProgram - so it is not an applet.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
0

I know its too late, but you dont need the main(String[] args), all you need is press the right click in your project, go to propieties, then java build path, libraries, add external Jars, and search the acm.jar file in your pc.