Jump to content

No Main Class Error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Blue Indian

Blue Indian

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
The following code is a simple beginning program that I am trying to run, but I am do not have a main. Also, according to my teacher's solutions, there should be no main. How do I get this program to run?
import acm.program.*;

public class Fibinacci extends ConsoleProgram{

    private static final int MAX_TERM_VALUE = 10000;

    public void run(){

       println("This program lists the Fibinacci sequence.");
       int term = 0;
       int i = 0;
       while (term < MAX_TERM_VALUE){
           println(+term);
           term = fib(i + 1);
           i++;
       }
    }

       private int fib(int i){
           int result;
           if (i == 0){
              result = 0;
           } else if (i == 1){
              result = 1;
           } else {
               result = fib(i -1) + fib(i - 2);
           }
           return result;
       }

}

Edited by WingedPanther, 26 March 2010 - 04:33 PM.
add code tags (the # button)


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You MUST have a static public method named main!

Also, please use code tags
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
maybe your teacher wants you to submit your class withought a main because he has his own main with his own tests, but as WingedPanther said, you must have a main method in order to test your class at home.

#4
Deadlock

Deadlock

    Learning Programmer

  • Members
  • PipPipPip
  • 81 posts
You can never run a class without the main method. Alternatively you may use that class from another class which has the main method. Your code lacks the running engine.

#5
Blue Indian

Blue Indian

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
Actually, I got this program to run as is. I was just trying to run the wrong file. Once I clicked on this file and hit run it performed exactly like I wanted it to.